Skip to content

Commit

Permalink
up: update some examples demo and some sub pkg readme
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jul 7, 2022
1 parent 0e1636c commit b883810
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 20 deletions.
36 changes: 30 additions & 6 deletions _examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
16 changes: 9 additions & 7 deletions _examples/cmd/git_pull_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion _examples/serveman/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 15 additions & 4 deletions _examples/simpleone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion interact/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Interactive Util
# Interactive

command-line interactive util methods

Expand Down
5 changes: 5 additions & 0 deletions resource/gcli-cmd-code.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

var {{.Name}}Cmd = &gcli.Command {
Name: "{{ .Name }}",
Name: "{{ .Desc }}",
}
2 changes: 1 addition & 1 deletion show/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Format message
# Show data

contains `section, panel, padding, helpPanel, table, tree, title, list, multiList`

Expand Down

0 comments on commit b883810

Please sign in to comment.