Skip to content

Commit 34dd638

Browse files
committed
Keep helpFlags explicit, to avoid possible interference with other args, ex file names "h"
1 parent 3d2675a commit 34dd638

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

cmd/src/cmd.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"log"
77
"os"
88
"slices"
9-
"strings"
109

1110
"github.com/sourcegraph/src-cli/internal/cmderrors"
1211
)
@@ -50,11 +49,18 @@ func (c commander) run(flagSet *flag.FlagSet, cmdName, usageText string, args []
5049
// remove it from the list of args at this point to avoid interrupting recursive function calls,
5150
// and append it to the deepest command / subcommand
5251
filteredArgs := make([]string, 0, len(args))
53-
helpFlags := []string{"help", "h"}
5452
helpRequested := false
53+
54+
helpFlags := []string{
55+
"--h",
56+
"--help",
57+
"-h",
58+
"-help",
59+
"help",
60+
}
61+
5562
for _, arg := range args {
56-
trimmedArg := strings.TrimLeft(arg, "-")
57-
if slices.Contains(helpFlags, trimmedArg) {
63+
if slices.Contains(helpFlags, arg) {
5864
helpRequested = true
5965
} else {
6066
filteredArgs = append(filteredArgs, arg)

0 commit comments

Comments
 (0)