@@ -2,55 +2,12 @@ package clicompat
22
33import "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
246func 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