Skip to content

Commit

Permalink
Respect SUMMARY: or USAGE: (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
zph authored Aug 8, 2024
1 parent 14fc1b8 commit a44fe7d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
)

var UsageKey = "USAGE: "
var LegacyUsageKey = "SUMMARY: "

// helpCmd represents the help command
var helpCmd = &cobra.Command{
Expand Down
6 changes: 3 additions & 3 deletions cmd/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func (s *Script) parse() error {
return err
}

if strings.Contains(string(b), UsageKey) {
if strings.Contains(string(b), UsageKey) || strings.Contains(string(b), LegacyUsageKey) {
lines := strings.Split(string(b), "\n")
var linesStart int
for idx, line := range lines {
if strings.Contains(line, UsageKey) {
if strings.Contains(line, UsageKey) || strings.Contains(line, LegacyUsageKey) {
linesStart = idx
break
}
Expand All @@ -74,7 +74,7 @@ func (s *Script) parse() error {
helpTextLines := lines[linesStart:helpEnds]
helpText := strings.Join(helpTextLines, "\n")

s.usage = strings.TrimSpace(strings.Split(lines[linesStart], UsageKey)[1])
s.usage = strings.TrimSpace(strings.SplitN(lines[linesStart], ":", 2)[1])
s.help = helpText
}
return nil
Expand Down

0 comments on commit a44fe7d

Please sign in to comment.