コード例 #1
0
ファイル: main.go プロジェクト: LA3QMA/wl2k-go
func init() {
	listeners = make(map[string]net.Listener)

	if appDir, err := mailbox.DefaultAppDir(); err != nil {
		log.Fatal(err)
	} else {
		fOptions.ConfigPath = path.Join(appDir, "config.json")
		fOptions.LogPath = path.Join(appDir, "wl2k.log")
		fOptions.EventLogPath = path.Join(appDir, "eventlog.json")
	}

	pflag.Usage = func() {
		fmt.Fprintf(os.Stderr, "%s is a client for the Winlink 2000 Network.\n\n", os.Args[0])
		fmt.Fprintf(os.Stderr, "Usage:\n  %s [options] command [arguments]\n", os.Args[0])

		fmt.Fprintln(os.Stderr, "\nCommands:")
		for _, cmd := range commands {
			fmt.Fprintf(os.Stderr, "  %-15s %s\n", cmd.Str, cmd.Desc)
		}

		fmt.Fprintln(os.Stderr, "\nOptions:")
		optionsSet().PrintDefaults()
		fmt.Fprint(os.Stderr, "\n")
	}
}
コード例 #2
0
ファイル: rmslist.go プロジェクト: LA3QMA/wl2k-go
func rmsListHandle(args []string) {
	set := pflag.NewFlagSet("rmslist", pflag.ExitOnError)
	mode := set.StringP("mode", "m", "", "")
	forceDownload := set.BoolP("force-download", "d", false, "")
	set.Parse(args)

	appDir, err := mailbox.DefaultAppDir()
	if err != nil {
		log.Fatal(err)
	}
	filePath := path.Join(appDir, "rmslist.json") // Should be moved to a tmp-folder, along with logfile.

	var query string
	if len(set.Args()) > 0 {
		query = strings.ToUpper(set.Args()[0])
	}

	file, err := GetGatewayStatusCached(filePath, *forceDownload)
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	var status GatewayStatus

	err = json.NewDecoder(file).Decode(&status)
	if err != nil {
		log.Fatal(err)
	}

	*mode = strings.ToLower(*mode)

	fmtStr := "%-9.9s [%-6.6s] %-15.15s %14.14s %14.14s\n"

	// Print header
	fmt.Printf(fmtStr, "callsign", "gridsq", "mode(s)", "dial freq", "center freq") //TODO: "center frequency" of packet is wrong...

	// Print gateways (separated by blank line)
	for _, gw := range status.Gateways {
		switch {
		case query != "" && !strings.HasPrefix(gw.Callsign, query):
			continue
		default:
		}

		var printed bool
		for _, channel := range gw.Channels {
			if mode != nil && !strings.Contains(strings.ToLower(channel.SupportedModes), *mode) {
				continue
			}
			printed = true

			freq := Frequency(channel.Frequency)
			dial := freq.Dial(channel.SupportedModes)
			fmt.Printf(fmtStr, gw.Callsign, channel.Gridsquare, channel.SupportedModes, dial, freq)
		}
		if printed {
			fmt.Println("")
		}
	}
}