From b88381055b6cc856c4b7dbdd444eb8e2720d41c1 Mon Sep 17 00:00:00 2001 From: Inhere Date: Thu, 7 Jul 2022 11:39:17 +0800 Subject: [PATCH] up: update some examples demo and some sub pkg readme --- _examples/README.md | 36 +++++++++++++++++++++++++++------ _examples/cmd/git_pull_multi.go | 16 ++++++++------- _examples/serveman/commands.go | 2 +- _examples/simpleone/main.go | 19 +++++++++++++---- interact/README.md | 2 +- resource/gcli-cmd-code.tpl | 5 +++++ show/README.md | 2 +- 7 files changed, 62 insertions(+), 20 deletions(-) diff --git a/_examples/README.md b/_examples/README.md index bd3f567..2e55e9a 100644 --- a/_examples/README.md +++ b/_examples/README.md @@ -2,20 +2,44 @@ ## run example -**run with application:** +### cli application + +show help: + +```bash +go run ./cliapp -h +``` + +run application: ```bash -go run ./_examples/cliapp +go run ./cliapp demo ``` -**only one command:** +### Only one command + +show help: + +```bash +go run ./simpleone -h +``` + +run command: + +```bash +go run ./simpleone +``` + +### Multi level commands + +show help: ```bash -go run ./_examples/simpleone +go run ./multilevel -h ``` -**multi level commands:** +run command: ```bash -go run ./_examples/multilevel +go run ./multilevel ``` diff --git a/_examples/cmd/git_pull_multi.go b/_examples/cmd/git_pull_multi.go index 7d6738e..dc5b9a3 100644 --- a/_examples/cmd/git_pull_multi.go +++ b/_examples/cmd/git_pull_multi.go @@ -24,12 +24,14 @@ var GitPullMulti = &gcli.Command{ "basePath", "the base operate dir path. default is current dir", true, - ).WithValidator(func(v interface{}) (i interface{}, e error) { - if !fsutil.IsDir(v.(string)) { - return nil, fmt.Errorf("the base path must be an exist dir") - } - return v, nil - }) + ). + WithValue("./"). + WithValidator(func(v interface{}) (i interface{}, e error) { + if !fsutil.IsDir(v.(string)) { + return nil, fmt.Errorf("the base path must be an exist dir") + } + return v, nil + }) c.AddArg( "dirNames", @@ -42,7 +44,7 @@ var GitPullMulti = &gcli.Command{ `, Func: func(c *gcli.Command, _ []string) (err error) { var ret string - basePath := c.Arg("basePath").String("./") + basePath := c.Arg("basePath").String() dirNames := c.Arg("dirNames").Strings() if len(dirNames) == 0 { diff --git a/_examples/serveman/commands.go b/_examples/serveman/commands.go index f56c757..ac48c99 100644 --- a/_examples/serveman/commands.go +++ b/_examples/serveman/commands.go @@ -28,7 +28,7 @@ var ( confFile string ) -// eg: cliapp serve:start +// ServerStart eg: cliapp serve:start func ServerStart() *gcli.Command { c := &gcli.Command{ Name: "start", diff --git a/_examples/simpleone/main.go b/_examples/simpleone/main.go index 09a5ee7..4014390 100644 --- a/_examples/simpleone/main.go +++ b/_examples/simpleone/main.go @@ -10,10 +10,13 @@ var opts = struct { visualMode bool list bool sample bool + number int }{} -// test run: go build ./_examples/simpleone && ./simpleone -h -// test run: go run ./_examples/simpleone +// test run: +// go build ./_examples/simpleone && ./simpleone -h +// test run: +// go run ./_examples/simpleone func main() { cmd := gcli.Command{ Name: "test", @@ -22,9 +25,17 @@ func main() { } cmd.BoolOpt(&opts.visualMode, "visual", "v", false, "Prints the font name.") - cmd.StrOpt(&opts.fontName, "font", "", "", "Choose a font name. Default is a random font.") + cmd.StrOpt(&opts.fontName, "font", "fn", "", "Choose a font name. Default is a random font.") cmd.BoolOpt(&opts.list, "list", "", false, "Lists all available fonts.") - cmd.BoolOpt(&opts.sample, "sample", "", false, "Prints a sample with that font.") + cmd.BoolOpt(&opts.sample, "sample", "", false, "Prints a sample with that font.\nmessage at new line") + cmd.IntOpt(&opts.number, "number", "n,num", 0, "a integer option") + + cmd.AddArg("arg1", "this is a argument") + cmd.AddArg("arg2", "this is a argument2") + + cmd.WithConfigFn(func(opt *gcli.FlagsConfig) { + opt.DescNewline = true + }) cmd.Func = func(c *gcli.Command, args []string) error { c.Infoln("hello, in the alone command:", c.Name) diff --git a/interact/README.md b/interact/README.md index f5d2d57..65e392e 100644 --- a/interact/README.md +++ b/interact/README.md @@ -1,4 +1,4 @@ -# Interactive Util +# Interactive command-line interactive util methods diff --git a/resource/gcli-cmd-code.tpl b/resource/gcli-cmd-code.tpl index e69de29..cdacc0c 100644 --- a/resource/gcli-cmd-code.tpl +++ b/resource/gcli-cmd-code.tpl @@ -0,0 +1,5 @@ + +var {{.Name}}Cmd = &gcli.Command { + Name: "{{ .Name }}", + Name: "{{ .Desc }}", +} diff --git a/show/README.md b/show/README.md index 76806a0..92b9158 100644 --- a/show/README.md +++ b/show/README.md @@ -1,4 +1,4 @@ -# Format message +# Show data contains `section, panel, padding, helpPanel, table, tree, title, list, multiList`