diff --git a/help.go b/help.go index 9a7687f947300fe9f9455477c8dab896324e2493..060c8a76ca974f6032383021b3911c8de407f0c3 100644 --- a/help.go +++ b/help.go @@ -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 { diff --git a/help_test.go b/help_test.go index 8508a5cce81ba8e83c3554ee8b35331fb6f76f36..483f90567674d816e5501aa105949cb459cbc718 100644 --- a/help_test.go +++ b/help_test.go @@ -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) })