Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions cmd/src/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"log"
"os"
"slices"

"github.com/sourcegraph/src-cli/internal/cmderrors"
)
Expand Down Expand Up @@ -86,16 +85,6 @@ func (c commander) run(flagSet *flag.FlagSet, cmdName, usageText string, args []
log.Fatal("reading config: ", err)
}

// Print help to stdout if requested
if slices.IndexFunc(args, func(s string) bool {
return s == "--help"
}) >= 0 {
cmd.flagSet.SetOutput(os.Stdout)
flag.CommandLine.SetOutput(os.Stdout)
cmd.flagSet.Usage()
os.Exit(0)
}

// Parse subcommand flags.
args := flagSet.Args()[1:]
if err := cmd.flagSet.Parse(args); err != nil {
Expand Down
17 changes: 16 additions & 1 deletion cmd/src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net/url"
"os"
"path/filepath"
"slices"
"strings"

"github.com/sourcegraph/sourcegraph/lib/errors"
Expand Down Expand Up @@ -89,7 +90,21 @@ func main() {
log.SetFlags(0)
log.SetPrefix("")

commands.run(flag.CommandLine, "src", usageText, os.Args[1:])
commands.run(flag.CommandLine, "src", usageText, normalizeDashHelp(os.Args[1:]))
}

// normalizeDashHelp converts --help to -help since Go's flag parser only supports single dash.
func normalizeDashHelp(args []string) []string {
args = slices.Clone(args)
for i, arg := range args {
if arg == "--" {
break
}
if arg == "--help" {
args[i] = "-help"
}
}
return args
}

var cfg *config
Expand Down
Loading