Skip to content

Commit 80417af

Browse files
authored
chore: remove clicompat help templates and use urfave/cli defaults (#1296)
- fixup version command to have better help formatting with urfave defaults
1 parent f71cf56 commit 80417af

3 files changed

Lines changed: 8 additions & 50 deletions

File tree

cmd/src/run_migration_compat.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func migratedRootCommand() *cli.Command {
5050
commands = append(commands, migratedCommands[name])
5151
}
5252

53-
return clicompat.WrapRoot(&cli.Command{
53+
return clicompat.Wrap(&cli.Command{
5454
Name: "src",
5555
HideVersion: true,
5656
Commands: commands,

cmd/src/version.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ import (
1717
"github.com/urfave/cli/v3"
1818
)
1919

20-
const versionExamples = `Examples:
20+
const versionExamples = `
21+
Display and compare the src-cli version against the recommended version for your instance
2122
22-
Get the src-cli version and the Sourcegraph instance's recommended version:
23+
Examples:
2324
24-
$ src version
25+
Get the src-cli version and the Sourcegraph instance's recommended version:
26+
27+
$ src version
2528
`
2629

2730
var versionCommand = clicompat.Wrap(&cli.Command{
2831
Name: "version",
29-
Usage: "display and compare the src-cli version against the recommended version for your instance",
3032
UsageText: "src version [options]",
3133
OnUsageError: clicompat.OnUsageError,
32-
Description: `
33-
` + versionExamples,
34+
Description: versionExamples,
3435
Flags: clicompat.WithAPIFlags(
3536
&cli.BoolFlag{
3637
Name: "client-only",

internal/clicompat/help.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,12 @@ package clicompat
22

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

5-
// LegacyCommandHelpTemplate formats leaf command help in a style closer to the
6-
// existing flag.FlagSet-based help output.
7-
const LegacyCommandHelpTemplate = `Usage of '{{.FullName}}':
8-
{{range .VisibleFlags}} {{printf " -%s\n\t\t\t\t%s\n" .Name .Usage}}{{end}}{{if .Description}}
9-
{{trim .Description}}
10-
{{end}}
11-
`
12-
13-
// LegacyRootCommandHelpTemplate formats root command help while preserving a
14-
// command's UsageText when it is provided.
15-
const LegacyRootCommandHelpTemplate = `{{if .UsageText}}{{trim .UsageText}}
16-
{{else}}Usage of '{{.FullName}}':
17-
{{end}}{{if .VisibleFlags}}{{range .VisibleFlags}}{{println .}}{{end}}{{end}}{{if .VisibleCommands}}
18-
{{range .VisibleCommands}}{{printf "\t%s\t%s\n" .Name .Usage}}{{end}}{{end}}{{if .Description}}
19-
{{trim .Description}}
20-
{{end}}
21-
`
22-
235
// Wrap sets common options on a sub commands to ensure consistency for help and error handling
246
func Wrap(cmd *cli.Command) *cli.Command {
257
if cmd == nil {
268
return nil
279
}
2810

29-
cmd.CustomHelpTemplate = LegacyCommandHelpTemplate
30-
cmd.OnUsageError = OnUsageError
31-
return cmd
32-
}
33-
34-
// WrapRoot sets common options on a root command to ensure consistency for help and error handling
35-
func WrapRoot(cmd *cli.Command) *cli.Command {
36-
if cmd == nil {
37-
return nil
38-
}
39-
40-
cmd.CustomRootCommandHelpTemplate = LegacyRootCommandHelpTemplate
4111
cmd.OnUsageError = OnUsageError
4212
return cmd
4313
}
44-
45-
// WithLegacyHelp applies both root and leaf legacy help templates.
46-
func WithLegacyHelp(cmd *cli.Command) *cli.Command {
47-
if cmd == nil {
48-
return nil
49-
}
50-
51-
cmd.CustomHelpTemplate = LegacyCommandHelpTemplate
52-
cmd.CustomRootCommandHelpTemplate = LegacyRootCommandHelpTemplate
53-
cmd.OnUsageError = OnUsageError
54-
55-
return cmd
56-
}

0 commit comments

Comments
 (0)