diff --git a/GUIDE.md b/GUIDE.md new file mode 100644 index 0000000..4f53b51 --- /dev/null +++ b/GUIDE.md @@ -0,0 +1,38 @@ +# acmd guides + +## Flag +Example with command like that `./dummy server ./openapi.yml -port=8080` from [dummy](https://github.com/go-dummy/dummy/blob/main/cmd/dummy/main.go) +```go +func run() error { + cmds := []acmd.Command{ + { + // Command + Name: "server", + Description: "run mock server", + Do: func(ctx context.Context, args []string) error { + cfg := config.NewConfig() + + // Argument ./openapi + cfg.Server.Path = args[0] + + // Flags after argument + fs := flag.NewFlagSet("dummy", flag.ContinueOnError) + fs.StringVar(&cfg.Server.Port, "port", "8080", "") + fs.StringVar(&cfg.Logger.Level, "logger-level", "INFO", "") + if err := fs.Parse(args[1:]); err != nil { + return err + } + + ... + }, + }, + } + + r := acmd.RunnerOf(cmds, acmd.Config{ + AppName: "Dummy", + Version: version, + }) + + return r.Run() +} +``` diff --git a/README.md b/README.md index 0000dee..7fccf47 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,8 @@ Popular CLI libraries (or better frameworks) have too large and unclear API, in * Auto suggesting command. * Builtin `help` and `version` commands. +See [GUIDE.md](https://github.com/cristalhq/acmd/blob/main/GUIDE.md) for more details + ## Install Go version 1.17+