Skip to content

Commit

Permalink
Merge pull request WindomZ#20 from WindomZ/dev
Browse files Browse the repository at this point in the history
v1.0.1 fix WindomZ#19
  • Loading branch information
WindomZ authored Apr 18, 2017
2 parents 7410c4c + 5bec42e commit a53a5e5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ The solution for building command shell programs,
drive by <[docopt](https://github.com/docopt/docopt.go)>,
inspired by <[commander.js](https://github.com/tj/commander.js)>

![v0.17.2](https://img.shields.io/badge/version-v0.17.2-yellow.svg)
![status](https://img.shields.io/badge/status-beta-yellow.svg)
![v1.0.1](https://img.shields.io/badge/version-v1.0.1-blue.svg)
![status](https://img.shields.io/badge/status-stable-green.svg)

## Features

Expand All @@ -28,10 +28,10 @@ To install commander according to your `$GOPATH`:
go get github.com/WindomZ/go-commander
```

To use commander in your Go code:
or use stable v1 version:

```go
import "github.com/WindomZ/go-commander"
```bash
go get gopkg.in/WindomZ/go-commander.v1
```

## Examples
Expand Down
32 changes: 16 additions & 16 deletions command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func TestCommand_HelpMessage(t *testing.T) {

assert.Equal(t, c.UsagesString(),
[]string{
"cmd <x> [[-c|--config] | [-d|--drop]]",
"cmd cmd2 [[-a|--about] | [-t|--test]]",
"cmd cmd3 [y] [[-b=<kn>|--bold=<kn>] | [-c|--count]]",
"cmd <x> [-c|--config] [-d|--drop]",
"cmd cmd2 [-a|--about] [-t|--test]",
"cmd cmd3 [y] [-b=<kn>|--bold=<kn>] [-c|--count]",
})
assert.Equal(t, c.OptionsString(),
[]string{
Expand All @@ -64,9 +64,9 @@ func TestCommand_HelpMessage(t *testing.T) {
` this is description
Usage:
cmd <x> [[-c|--config] | [-d|--drop]]
cmd cmd2 [[-a|--about] | [-t|--test]]
cmd cmd3 [y] [[-b=<kn>|--bold=<kn>] | [-c|--count]]
cmd <x> [-c|--config] [-d|--drop]
cmd cmd2 [-a|--about] [-t|--test]
cmd cmd3 [y] [-b=<kn>|--bold=<kn>] [-c|--count]
Options:
-c --config config description
Expand All @@ -87,9 +87,9 @@ func TestCommand_HelpMessage(t *testing.T) {
` this is description
Usage:
cmd <x> [[-c|--config] | [-d|--drop]]
cmd cmd2 [[-a|--about] | [-t|--test]]
cmd cmd3 [y] [[-b=<kn>|--bold=<kn>] | [-c|--count]]
cmd <x> [-c|--config] [-d|--drop]
cmd cmd2 [-a|--about] [-t|--test]
cmd cmd3 [y] [-b=<kn>|--bold=<kn>] [-c|--count]
Options:
-c --config config description
Expand All @@ -107,15 +107,15 @@ func TestCommand_HelpMessage(t *testing.T) {
`)

c.Doc(` Usage:
cmd <x> [[-c|--config] | [-d|--drop]]
cmd cmd2 [[-a|--about] | [-t|--test]]
cmd cmd3 [y] [[-b=<kn>|--bold=<kn>] | [-c|--count]]
cmd <x> [-c|--config] [-d|--drop]
cmd cmd2 [-a|--about] [-t|--test]
cmd cmd3 [y] [-b=<kn>|--bold=<kn>] [-c|--count]
`)

assert.Equal(t, c.HelpMessage(), ` Usage:
cmd <x> [[-c|--config] | [-d|--drop]]
cmd cmd2 [[-a|--about] | [-t|--test]]
cmd cmd3 [y] [[-b=<kn>|--bold=<kn>] | [-c|--count]]
cmd <x> [-c|--config] [-d|--drop]
cmd cmd2 [-a|--about] [-t|--test]
cmd cmd3 [y] [-b=<kn>|--bold=<kn>] [-c|--count]
`)
}

Expand All @@ -126,7 +126,7 @@ func TestCommand_Aliases(t *testing.T) {
Option("-a, --about", "cmd about description").
Option("-t, --test", "cmd test description")
assert.Equal(t, c.HelpMessage(), ` Usage:
(cmd|c0|cmd0) [[-a|--about] | [-t|--test]]
(cmd|c0|cmd0) [-a|--about] [-t|--test]
Options:
-a --about cmd about description
Expand Down
6 changes: 5 additions & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ func (o _Options) UsagesString(ones ...bool) (r []string) {
}
}
if len(rs) != 0 {
r = append(r, fmt.Sprintf("[%s]", strings.Join(rs, " | ")))
if len(rs) == 1 {
r = append(r, fmt.Sprintf("[%s]", strings.Join(rs, " ")))
} else {
r = append(r, fmt.Sprintf("%s", strings.Join(rs, " ")))
}
}
return
}
Expand Down
2 changes: 1 addition & 1 deletion options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestOptions_UsagesString(t *testing.T) {
newOption("-d, --drop", "drop description"),
}
assert.Equal(t, o.UsagesString(),
[]string{"[[-a|--about] | [-b=<kn>|--bold=<kn>] | [-c|--config] | [-d|--drop]]"})
[]string{"[-a|--about] [-b=<kn>|--bold=<kn>] [-c|--config] [-d|--drop]"})
}

func TestOptions_OptionsString(t *testing.T) {
Expand Down

0 comments on commit a53a5e5

Please sign in to comment.