Skip to content
Open
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
2 changes: 1 addition & 1 deletion cmd/src/run_migration_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func migratedRootCommand() *cli.Command {
commands = append(commands, migratedCommands[name])
}

return clicompat.WrapRoot(&cli.Command{
return clicompat.Wrap(&cli.Command{
Name: "src",
HideVersion: true,
Commands: commands,
Expand Down
13 changes: 7 additions & 6 deletions cmd/src/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ import (
"github.com/urfave/cli/v3"
)

const versionExamples = `Examples:
const versionExamples = `
Display and compare the src-cli version against the recommended version for your instance

Get the src-cli version and the Sourcegraph instance's recommended version:
Examples:

$ src version
Get the src-cli version and the Sourcegraph instance's recommended version:

$ src version
`

var versionCommand = clicompat.Wrap(&cli.Command{
Name: "version",
Usage: "display and compare the src-cli version against the recommended version for your instance",
UsageText: "src version [options]",
OnUsageError: clicompat.OnUsageError,
Description: `
` + versionExamples,
Description: versionExamples,
Flags: clicompat.WithAPIFlags(
&cli.BoolFlag{
Name: "client-only",
Expand Down
43 changes: 0 additions & 43 deletions internal/clicompat/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,12 @@ package clicompat

import "github.com/urfave/cli/v3"

// LegacyCommandHelpTemplate formats leaf command help in a style closer to the
// existing flag.FlagSet-based help output.
const LegacyCommandHelpTemplate = `Usage of '{{.FullName}}':
{{range .VisibleFlags}} {{printf " -%s\n\t\t\t\t%s\n" .Name .Usage}}{{end}}{{if .Description}}
{{trim .Description}}
{{end}}
`

// LegacyRootCommandHelpTemplate formats root command help while preserving a
// command's UsageText when it is provided.
const LegacyRootCommandHelpTemplate = `{{if .UsageText}}{{trim .UsageText}}
{{else}}Usage of '{{.FullName}}':
{{end}}{{if .VisibleFlags}}{{range .VisibleFlags}}{{println .}}{{end}}{{end}}{{if .VisibleCommands}}
{{range .VisibleCommands}}{{printf "\t%s\t%s\n" .Name .Usage}}{{end}}{{end}}{{if .Description}}
{{trim .Description}}
{{end}}
`

// Wrap sets common options on a sub commands to ensure consistency for help and error handling
func Wrap(cmd *cli.Command) *cli.Command {
if cmd == nil {
return nil
}

cmd.CustomHelpTemplate = LegacyCommandHelpTemplate
cmd.OnUsageError = OnUsageError
return cmd
}

// WrapRoot sets common options on a root command to ensure consistency for help and error handling
func WrapRoot(cmd *cli.Command) *cli.Command {
if cmd == nil {
return nil
}

cmd.CustomRootCommandHelpTemplate = LegacyRootCommandHelpTemplate
cmd.OnUsageError = OnUsageError
return cmd
}

// WithLegacyHelp applies both root and leaf legacy help templates.
func WithLegacyHelp(cmd *cli.Command) *cli.Command {
if cmd == nil {
return nil
}

cmd.CustomHelpTemplate = LegacyCommandHelpTemplate
cmd.CustomRootCommandHelpTemplate = LegacyRootCommandHelpTemplate
cmd.OnUsageError = OnUsageError

return cmd
}
Loading