Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Aug 1, 2020
1 parent 21f0283 commit 7dc76bc
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 11 deletions.
95 changes: 89 additions & 6 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,6 @@ OK, auto-complete file generate successful

## 编写命令

### 关于参数定义

- 必须的参数不能定义在可选参数之后
- 只允许有一个数组参数(多个值的)
- 数组参数只能定义在最后

### 简单使用

```go
Expand Down Expand Up @@ -309,9 +303,98 @@ go build ./_examples/cliapp.go && ./cliapp example -h

### 添加选项

添加选项可用的方法:

```go
BoolOpt(p *bool, name, shorts string, defValue bool, desc string)
BoolVar(p *bool, meta FlagMeta)
Float64Opt(p *float64, name, shorts string, defValue float64, desc string)
Float64Var(p *float64, meta FlagMeta)
Int64Opt(p *int64, name, shorts string, defValue int64, desc string)
Int64Var(p *int64, meta FlagMeta)
IntOpt(p *int, name, shorts string, defValue int, desc string)
IntVar(p *int, meta FlagMeta)
StrOpt(p *string, name, shorts, defValue, desc string)
StrVar(p *string, meta FlagMeta)
Uint64Opt(p *uint64, name, shorts string, defValue uint64, desc string)
Uint64Var(p *uint64, meta FlagMeta)
UintOpt(p *uint, name, shorts string, defValue uint, desc string)
UintVar(p *uint, meta FlagMeta)
Var(p flag.Value, meta FlagMeta)
VarOpt(p flag.Value, name, shorts, desc string)
```

Usage examples:

```go
var id int
var b bool
var opt, dir string
var f1 float64
var names gcli.Strings

// bind options
cmd.IntOpt(&id, "id", "", 2, "the id option")
cmd.BoolOpt(&b, "bl", "b", false, "the bool option")
// notice `DIRECTORY` will replace to option value type
cmd.StrOpt(&dir, "dir", "d", "", "the `DIRECTORY` option")
// setting option name and short-option name
cmd.StrOpt(&opt, "opt", "o", "", "the option message")
// setting a special option var, it must implement the flag.Value interface
cmd.VarOpt(&names, "names", "n", "the option message")
```

### 绑定参数

关于参数定义:

- `必须的` 参数不能定义在 `可选参数` 之后
- 只允许有一个数组参数(多个值的)
- 数组参数只能定义在最后

绑定参数可用的方法:

```go
Add(arg Argument) *Argument
AddArg(name, desc string, requiredAndIsArray ...bool) *Argument
AddArgument(arg *Argument) *Argument
BindArg(arg Argument) *Argument
```

用法示例:

```go
cmd.AddArg("arg0", "the first argument, is required", true)
cmd.AddArg("arg1", "the second argument, is required", true)
cmd.AddArg("arg2", "the optional argument, is optional")
cmd.AddArg("arrArg", "the array argument, is array", false, true)
```

也可以使用 `Arg()/BindArg()`:

```go
cmd.Arg("arg0", gcli.Argument{
Name: "ag0",
Desc: "the first argument, is required",
Require: true,
})
cmd.BindArg("arg0", gcli.Argument{
Name: "ag0",
Desc: "the second argument, is required",
Require: true,
})
cmd.Arg("arg2", gcli.Argument{
Name: "ag0",
Desc: "the third argument, is is optional",
})

cmd.BindArg("arrArg", gcli.Argument{
Name: "arrArg",
Desc: "the third argument, is is array",
IsArray: true,
})
```

## 进度显示

- `progress.Bar` 通用的进度条
Expand Down
5 changes: 0 additions & 5 deletions gcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,6 @@ func StdApp() *App {
return stdApp
}

// Exit program
func Exit(code int) {
os.Exit(code)
}

// Verbose returns verbose level
func Verbose() uint {
return gOpts.verbose
Expand Down

0 comments on commit 7dc76bc

Please sign in to comment.