diff --git a/cmd/src/run_migration_compat.go b/cmd/src/run_migration_compat.go index c50f2cd34a..399cab11f6 100644 --- a/cmd/src/run_migration_compat.go +++ b/cmd/src/run_migration_compat.go @@ -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, diff --git a/cmd/src/version.go b/cmd/src/version.go index 6186159368..646ac6b6e1 100644 --- a/cmd/src/version.go +++ b/cmd/src/version.go @@ -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", diff --git a/internal/clicompat/help.go b/internal/clicompat/help.go index f458ad6fbb..02cf15b66b 100644 --- a/internal/clicompat/help.go +++ b/internal/clicompat/help.go @@ -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 -}