func Info(flag *flag.FlagSet) Command { query := crank.InfoQuery{} return func(client *rpc.Client) (err error) { var reply crank.InfoReply if err = client.Call("crank.Info", &query, &reply); err != nil { return } fmt.Printf("crankctl\n-------\n%s\n\n", crank.GetInfo(build)) fmt.Printf("crank\n-----\n%s\n", reply.Info) return } }
func main() { var err error if err = flags.Parse(os.Args[1:]); err != nil { usageError("%s", err) } if version { fmt.Println(crank.GetInfo(build)) return } command := flags.Arg(0) if command == "" { usageError("command missing") } cmdSetup, ok := commands[command] if !ok { usageError("unknown command %s", command) } flagSet := flag.NewFlagSet(os.Args[0]+" "+command, flag.ExitOnError) defaultFlags(flagSet) cmd := cmdSetup(flagSet) if err = flagSet.Parse(flags.Args()[1:]); err != nil { usageError("%s", err) } ctl = crank.DefaultCtl(ctl, prefix, name) conn, err := netutil.DialURI(ctl) if err != nil { fail("couldn't connect: %s", err) } client := rpc.NewClient(conn) if err = cmd(client); err != nil { fail("command failed: %v", err) } }