Skip to content
Snippets Groups Projects
Verified Commit 1f5c2ecf authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix: use context help instead help

parent 389c7c2a
No related branches found
No related tags found
No related merge requests found
......@@ -34,9 +34,12 @@ func (s *Settings[C]) Help() string {
func (s *Settings[C]) createHelp(cmd *cmd[C], path []string) string {
h := strings.Join(path, " ")
if h != "" {
h = " " + h + " "
}
var help string
help = "Usage: " + h + " "
help = "Usage:" + h
g := getFlagTable(cmd.settings.command.flagSet)
if len(g) > 0 {
......
......@@ -32,16 +32,16 @@ func TestGetHelp(t *testing.T) {
args []string
substring string
}{
{"test1", []string{"sub1", "--help"}, "Usage: [global options] [command] [arguments]\n\nGlobal Options:\n -a\tMessage A\n -x int\n \tMessage X\n\nCommand: sub1\n\nOptions:\n -b\tMessage B\n"},
{"test1", []string{"xsd", "help"}, "Usage: [global options] [command] [arguments]\n\nGlobal Options:\n -a\tMessage A\n -x int\n \tMessage X\n\nCommand: sub1\n\nOptions:\n -b\tMessage B\n"},
{"test2", []string{"sub1", "sub2"}, "Usage: [global options] [command] [arguments]\n\nGlobal Options:\n -a\tMessage A\n -x int\n \tMessage X\n\nCommand: sub1\n\nOptions:\n -b\tMessage B\n"},
{"test1", []string{"sub1", "--help"}, "Usage: test1 sub1 [global options] [command] [arguments]\n\nGlobal Options:\n -a\tMessage A\n -x int\n \tMessage X\n\nCommand: sub2\n\nOptions:\n -c\tMessage C\n"},
{"test1", []string{"xsd", "help"}, "Usage: test1 [global options] [command] [arguments]\n\nGlobal Options:\n -a\tMessage A\n -x int\n \tMessage X\n\nCommand: sub1\n\nOptions:\n -b\tMessage B\n"},
{"test2", []string{"sub1", "sub2"}, "Usage: test2 sub1 sub2 [global options] [command] [arguments]\n\nGlobal Options:\n -a\tMessage A\n -x int\n \tMessage X\n\nCommand: sub3\n\nOptions:\n -d\tMessage D\n\nCommand: sub4\n\nOptions:\n -e\tMessage E\n"},
}
for _, table := range tables {
t.Run(table.name, func(t *testing.T) {
s := New(table.name, CmdTestHelp1{})
s.Parse(table.args)
help := s.Help()
help := s.ContextHelp()
assert.NotEmpty(t, help)
assert.Contains(t, help, table.substring)
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment