Skip to content

Commit a44fe7d

Browse files
authored
Respect SUMMARY: or USAGE: (#5)
1 parent 14fc1b8 commit a44fe7d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

cmd/help.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
var UsageKey = "USAGE: "
16+
var LegacyUsageKey = "SUMMARY: "
1617

1718
// helpCmd represents the help command
1819
var helpCmd = &cobra.Command{

cmd/struct.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ func (s *Script) parse() error {
5454
return err
5555
}
5656

57-
if strings.Contains(string(b), UsageKey) {
57+
if strings.Contains(string(b), UsageKey) || strings.Contains(string(b), LegacyUsageKey) {
5858
lines := strings.Split(string(b), "\n")
5959
var linesStart int
6060
for idx, line := range lines {
61-
if strings.Contains(line, UsageKey) {
61+
if strings.Contains(line, UsageKey) || strings.Contains(line, LegacyUsageKey) {
6262
linesStart = idx
6363
break
6464
}
@@ -74,7 +74,7 @@ func (s *Script) parse() error {
7474
helpTextLines := lines[linesStart:helpEnds]
7575
helpText := strings.Join(helpTextLines, "\n")
7676

77-
s.usage = strings.TrimSpace(strings.Split(lines[linesStart], UsageKey)[1])
77+
s.usage = strings.TrimSpace(strings.SplitN(lines[linesStart], ":", 2)[1])
7878
s.help = helpText
7979
}
8080
return nil

0 commit comments

Comments
 (0)