func main() { cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) ctx.String("username=%s, password=%s\n", argv.Username, argv.Password) return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) ctx.String("%d, %s, %d, %s\n", argv.Basic, argv.Env, argv.Expr, argv.DevDir) return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) ctx.JSONIndentln(argv.JSON, "", " ") return nil }) }
func main() { cli.Run(new(helloT), func(ctx *cli.Context) error { argv := ctx.Argv().(*helloT) ctx.String("Hello, %s! Your age is %d?\n", argv.Name, argv.Age) return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { ctx.String("native args: %v\n", ctx.NativeArgs()) ctx.String("args: %v\n", ctx.Args()) return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) ctx.String("msg: %s", argv.Msg) return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) ctx.String("port=%d, x=%v, y=%v\n", argv.Port, argv.X, argv.Y) return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) ctx.String(argv.Content.String()) return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) ctx.String("v=%d\n", argv.V.Value()) return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) ctx.String("time=%v, duration=%v\n", argv.Time, argv.Duration) return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) ctx.JSONln(argv.Example.list) return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) if argv.Version { ctx.String("v0.0.1\n") } return nil }) }
func main() { // register parser factory function cli.RegisterFlagParser("myparser", newMyParser) cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) ctx.String("%v\n", argv.Cfg) return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) if err := argv.PidFile.New(); err != nil { return err } defer argv.PidFile.Remove() return nil }) }
func main() { cli.GetEditor = func() (string, error) { if editor := os.Getenv("EDITOR"); editor != "" { return editor, nil } return cli.DefaultEditor, nil } cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) ctx.String("msg: %s", argv.Msg) return nil }) }
func main() { cli.SetUsageStyle(cli.ManualStyle) cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) if argv.Help { ctx.WriteUsage() return nil } prefix := fmt.Sprintf("%s:%d> ", argv.Host, argv.Port) FOR_READ: for { line, err := prompt.Basic(prefix, false) if err != nil { return err } line = strings.TrimSpace(line) if line == "" { continue } var ( index = strings.Index(line, " ") cmd = line ) if index >= 0 { cmd = line[:index] } cmd = strings.ToUpper(cmd) switch cmd { case "QUIT", "EXIT": break FOR_READ case "SELECT": err = query(ctx, cmd, line, argv) default: err = execute(ctx, cmd, line, argv) } if err != nil { ctx.String("%s %v\n", ctx.Color().Red("ERR!"), err) } } ctx.String("bye~\n") return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) data, err := ioutil.ReadAll(argv.Reader) argv.Reader.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.Reader.Name(), argv.Reader.IsStdin()) // Replace the reader argv.Reader.SetReader(strings.NewReader("string reader")) data, err = ioutil.ReadAll(argv.Reader) if err != nil { return err } ctx.String("reade from reader: %s\n", string(data)) ctx.String("filename: %s, isStdin=%v\n", argv.Reader.Name(), argv.Reader.IsStdin()) return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { argv := ctx.Argv().(*argT) argv.Writer.Close() n, err := argv.Writer.Write([]byte("hello,writer\n")) argv.Writer.Close() if err != nil { return err } ctx.String("writes %d byte(s) to file or stdout\n", n) ctx.String("filename: %s, isStdout: %v\n", argv.Writer.Name(), argv.Writer.IsStdout()) // Replace the writer w := bytes.NewBufferString("") argv.Writer.SetWriter(w) n, err = argv.Writer.Write([]byte("hello,bytes.Writer")) if err != nil { return err } ctx.String("writes %d bytes to bytes.Writer: %s\n", n, w.String()) ctx.String("filename: %s, isStdout: %v\n", argv.Writer.Name(), argv.Writer.IsStdout()) return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { ctx.JSONln(ctx.Argv()) return nil }) }
func main() { cli.Run(new(argT), func(ctx *cli.Context) error { return nil }) }