import "github.com/keybase/client/go/libcmdline" func main() { flags := libcmdline.Flags{ "name": &libcmdline.StringFlag{}, "age": &libcmdline.IntFlag{}, "help": &libcmdline.BoolFlag{}, } args, err := flags.Parse(os.Args[1:]) if err != nil || flags.GetBool("help") { fmt.Println(flags.HelpDoc()) os.Exit(1) } name := flags.GetString("name") age := flags.GetInt("age") // ... }
import "github.com/keybase/client/go/libcmdline" func main() { argspec := []libcmdline.ArgSpec{ {&libcmdline.StringArg{}, "file", ""}, {&libcmdline.StringArg{}, "pattern", ""}, } args, err := libcmdline.ParseArgs(os.Args[1:], argspec) if err != nil { fmt.Println(err) os.Exit(1) } file := args[0].GetString() pattern := args[1].GetString() // ... }This code defines two positional arguments, `file` and `pattern`, and parses them from the command-line arguments. It assigns their values to the `file` and `pattern` variables. Overall, the go github.com.keybase.client.go.libcmdline CommandLine package provides a simple and flexible way to define and parse command-line flags and arguments in Go programs.