reorg code and add Readme
This commit is contained in:
parent
e20ed14191
commit
74e7586c36
44
README.md
44
README.md
|
@ -1,3 +1,47 @@
|
||||||
# command
|
# command
|
||||||
|
|
||||||
utils for command line app
|
utils for command line app
|
||||||
|
|
||||||
|
Provide two style for command line args parse:
|
||||||
|
|
||||||
|
- use struct field tag
|
||||||
|
- use command
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
use struct field tag
|
||||||
|
|
||||||
|
```go
|
||||||
|
type targs struct {
|
||||||
|
Test string `flag_default:"test" flag_usage:"this is test"`
|
||||||
|
TestBool bool `flag_short:"b"`
|
||||||
|
TestInt int
|
||||||
|
}
|
||||||
|
sargs := &targs{}
|
||||||
|
v, _ := NewFVSet(sargs)
|
||||||
|
v.Usage()
|
||||||
|
err := Parse([]string{"--test", "test", "--test-bool", "--test-int", "1"}, v)
|
||||||
|
```
|
||||||
|
|
||||||
|
use command style
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"git.pyer.club/kingecg/command"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
var cmd = command.NewCommand("test", "test command")
|
||||||
|
cmd.AddArg("arg1", "a", "arg1 description", "default value")
|
||||||
|
cmd.AddArg("arg2", "b", "arg2 description", "default value")
|
||||||
|
cmd.AddSubCommand("sub1", "sub1 description")
|
||||||
|
cmd.Parse(os.Args[1:])
|
||||||
|
fmt.Println(cmd.GetGlobalOptions())
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
Loading…
Reference in New Issue