Skip to content

Commit

Permalink
Update example test & readme (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Nov 29, 2022
1 parent 46744d4 commit a1e96d9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 41 deletions.
6 changes: 2 additions & 4 deletions README.md
Expand Up @@ -21,8 +21,6 @@ Popular CLI libraries (or better frameworks) have too large and unclear API, in
* Auto suggesting command.
* Builtin `help` and `version` commands.

See [GUIDE.md](https://github.com/cristalhq/acmd/blob/main/GUIDE.md) for more details

## Install

Go version 1.17+
Expand Down Expand Up @@ -68,11 +66,11 @@ if err := r.Run(); err != nil {
}
```

Also see examples: [examples_test.go](https://github.com/cristalhq/acmd/blob/main/example_test.go).
See examples: [examples_test.go](example_test.go).

## Documentation

See [these docs][pkg-url].
See [these docs][pkg-url] or [GUIDE.md](GUIDE.md) for more details.

## License

Expand Down
32 changes: 0 additions & 32 deletions acmd_test.go
Expand Up @@ -391,38 +391,6 @@ func TestExit(t *testing.T) {
mustEqual(t, buf.String(), wantOutput)
}

func TestCommand_Help_SubCommands(t *testing.T) {
buf := &bytes.Buffer{}
cmds := []Command{
{Name: "cmd", Subcommands: []Command{
{Name: "sub1", ExecFunc: nopFunc, Description: "show sub1"},
{Name: "sub2", ExecFunc: nopFunc, Description: "show sub2"},
}},
}
r := RunnerOf(cmds, Config{
Args: []string{"./myapp", "help"},
AppName: "myapp",
Output: buf,
})
failIfErr(t, r.Run())

if !strings.Contains(buf.String(), "cmd sub1") {
t.Fatal("should show subcommand help")
}

if !strings.Contains(buf.String(), "cmd sub2") {
t.Fatal("should show subcommand help")
}

if !strings.Contains(buf.String(), "show sub1") {
t.Fatal("should show subcommand help")
}

if !strings.Contains(buf.String(), "show sub2") {
t.Fatal("should show subcommand help")
}
}

func failIfOk(t testing.TB, err error) {
t.Helper()
if err == nil {
Expand Down
18 changes: 13 additions & 5 deletions example_test.go
Expand Up @@ -100,6 +100,12 @@ func ExampleHelp() {
ExecFunc: nopFunc,
FlagSet: &generalFlags{},
},
{
Name: "time", Subcommands: []acmd.Command{
{Name: "next", ExecFunc: nopFunc, Description: "next time subcommand"},
{Name: "curr", ExecFunc: nopFunc, Description: "curr time subcommand"},
},
},
}

r := acmd.RunnerOf(cmds, acmd.Config{
Expand All @@ -124,11 +130,13 @@ func ExampleHelp() {
//
// The commands are:
//
// boom <no description>
// help shows help message
// now prints current time
// status prints status of the system
// version shows version of the application
// boom <no description>
// help shows help message
// now prints current time
// status prints status of the system
// time curr curr time subcommand
// time next next time subcommand
// version shows version of the application
//
// Best place to add examples.
//
Expand Down

0 comments on commit a1e96d9

Please sign in to comment.