diff --git a/README.md b/README.md index 6473bcaac1913f6bb3e6b3382f83572b86444224..a65731f03b6fbe5c4e5d76d61d96797c267f427b 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,9 @@ the command `serve`. Furthermore, the command has the tag `call` with the value `DoServe`. The function `DoServe` is called when the command `serve` is used. +Important: The function must be exported, that means it +must start with a capital letter. + The function is called with the receiver `*Definition` An example for the function `DoServe`: diff --git a/api.go b/api.go index 04f187db642f2739d09d49e2c7e82d5d1b8537e5..37ea8756585e9fcff8fa104837510f7c9170d4ac 100644 --- a/api.go +++ b/api.go @@ -34,8 +34,8 @@ func New[C any](name string, definitions C) *Settings[C] { return s } -// FlagOutput returns the writer where the flag package writes its output. -func (s *Settings[C]) FlagOutput() string { +// Output returns the writer where the flag package writes its output. +func (s *Settings[C]) Output() string { return s.flagOutput.(*bytes.Buffer).String() } diff --git a/api_test.go b/api_test.go index d402296d0c6c1c04a197c09124420b8aaeb057fb..93a01690d96b80ad0173b1ebcc8f73b55267892e 100644 --- a/api_test.go +++ b/api_test.go @@ -8,6 +8,23 @@ import ( "testing" ) +func TestUsage(t *testing.T) { + + commands := New("root", CmdTest1{}) + args := []string{"-h"} + + commands.Parse(args) + + assert.False(t, commands.HasErrors()) + if commands.HasErrors() { + t.Log(commands.Errors()) + } + + usage := commands.Usage() + assert.NotEmpty(t, usage) + +} + func TestNewIntWithError(t *testing.T) { // two is not a struct