From a1e96d9f557d6a664d537dcda86a2e7f7a1737e9 Mon Sep 17 00:00:00 2001 From: Oleg Kovalov Date: Tue, 29 Nov 2022 21:41:09 +0100 Subject: [PATCH] Update example test & readme (#45) --- README.md | 6 ++---- acmd_test.go | 32 -------------------------------- example_test.go | 18 +++++++++++++----- 3 files changed, 15 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 929aaf6..7a1420a 100644 --- a/README.md +++ b/README.md @@ -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+ @@ -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 diff --git a/acmd_test.go b/acmd_test.go index 3c41227..a55fd3b 100644 --- a/acmd_test.go +++ b/acmd_test.go @@ -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 { diff --git a/example_test.go b/example_test.go index 2d98532..23806c5 100644 --- a/example_test.go +++ b/example_test.go @@ -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{ @@ -124,11 +130,13 @@ func ExampleHelp() { // // The commands are: // - // boom - // help shows help message - // now prints current time - // status prints status of the system - // version shows version of the application + // boom + // 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. //