From 1f5c2ecff21cdd97248bedd5a1f2e1203909d035 Mon Sep 17 00:00:00 2001
From: Volker Schukai <volker.schukai@schukai.com>
Date: Fri, 23 Dec 2022 11:10:45 +0100
Subject: [PATCH] fix: use context help instead help

---
 help.go      | 5 ++++-
 help_test.go | 8 ++++----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/help.go b/help.go
index 9a7687f..060c8a7 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 8508a5c..483f905 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)
 		})
-- 
GitLab