func build(ctx *cli.Context) error { argv := ctx.Argv().(*buildT) ctx.String("%s: %v", ctx.Path(), jsonIndent(argv)) ctx.String("Arch: %s", ctx.Args()[0]) return nil }
func execute(ctx *cli.Context, cmd, line string, argv *argT) error { urlStr := fmt.Sprintf("%s://%s:%d%sdb/execute?pretty&timings", argv.Protocol, argv.Host, argv.Port, argv.Prefix) ret := &executeResponse{} if err := sendRequest(ctx, urlStr, line, argv, ret); err != nil { return err } if ret.Error != "" { return fmt.Errorf(ret.Error) } if len(ret.Results) != 1 { // What's happen? ret.Results.length MUST be 1 return fmt.Errorf("unexpected results length: %d", len(ret.Results)) } result := ret.Results[0] if result.Error != "" { ctx.String("Error: %s\n", result.Error) return nil } rowString := "row" if result.RowsAffected > 1 { rowString = "rows" } ctx.String("%d %s affected (%f sec)\n", result.RowsAffected, rowString, result.Time) return nil }
// Validate implements cli.Validator interface func (argv *argT) Validate(ctx *cli.Context) error { if argv.Age < 0 || argv.Age > 300 { return fmt.Errorf("age %d out of range", argv.Age) } if argv.Gender != "male" && argv.Gender != "female" { return fmt.Errorf("invalid gender %s", ctx.Color().Yellow(argv.Gender)) } return nil }
func publish(ctx *cli.Context) error { argv := ctx.Argv().(*publishT) if argv.List { ctx.String(ctx.Command().ChildrenDescriptions("", " ")) return nil } ctx.String("%s: %v", ctx.Path(), jsonIndent(argv)) return nil }
func redo(ctx *cli.Context) error { ctx.JSON(ctx.RootArgv()) ctx.JSON(ctx.Argv()) fmt.Println() return nil }
func publish(ctx *cli.Context) error { rootArgv := ctx.RootArgv().(*rootT) argv := ctx.Argv().(*publishT) jR, _ := json.Marshal(*rootArgv) jC, _ := json.Marshal(*argv) ctx.String("[publish]:\n %v\n %v\n %v\n", string(jR), string(jC), ctx.Args()) return nil }
func install(ctx *cli.Context) error { rootArgv := ctx.RootArgv().(*rootT) argv := ctx.Argv().(*installT) jR, _ := json.Marshal(*rootArgv) jC, _ := json.Marshal(*argv) ctx.String("[install]:\n %v\n %v\n %v\n", string(jR), string(jC), ctx.Args()) return nil }
func doc(ctx *cli.Context) error { argv := ctx.Argv().(*docT) ctx.String("%s: %v", ctx.Path(), jsonIndent(argv)) return nil }
func publishUs(ctx *cli.Context) error { argv := ctx.Argv().(*publishUsT) ctx.String("%s: %v", ctx.Path(), jsonIndent(argv)) return nil }
func gogo(ctx *cli.Context) error { argv := ctx.Argv().(*gogoT) if argv.Version { ctx.String(version + "\n") return nil } if argv.List { ctx.String(ctx.Command().ChildrenDescriptions(" ", " => ")) return nil } ctx.String("try `%s --help for more information'\n", ctx.Path()) return nil }
func fi(ctx *cli.Context) error { ctx.JSON(ctx.RootArgv()) ctx.JSON(ctx.Argv()) fmt.Println() argv := ctx.Argv().(*rootT) data, err := ioutil.ReadAll(argv.Fi) argv.Fi.Close() if err != nil { return err } ctx.String("read from file(or stdin): %s\n", string(data)) ctx.String("filename: %s, isStdin=%v\n", argv.Fi.Name(), argv.Fi.IsStdin()) return nil }
func install(ctx *cli.Context) error { argv := ctx.Argv().(*installT) ctx.String("%s: %v", ctx.Path(), jsonIndent(argv)) ctx.String("Installing: %v\n", ctx.Args()) return nil }
func build(ctx *cli.Context) error { rootArgv := ctx.RootArgv().(*rootT) argv := ctx.Argv().(*buildT) jR, _ := json.Marshal(*rootArgv) jC, _ := json.Marshal(*argv) ctx.String("[build]:\n %v\n %v\n %v\n", string(jR), string(jC), ctx.Args()) cli.ReadJSONFromFile("redo2.json", rootArgv) ctx.String("[%s]:\n %+v\n", ctx.Path(), *rootArgv) return nil }