Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update example test & readme #45

Merged
merged 1 commit into from Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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