(ctx context.Context)
| 115 | } |
| 116 | |
| 117 | func (cmd *command) run(ctx context.Context) error { |
| 118 | normalize := func(_ *pflag.FlagSet, name string) pflag.NormalizedName { |
| 119 | return pflag.NormalizedName(internal.NormalizeToKebabCase(name)) |
| 120 | } |
| 121 | // While we prefer kebab-case for flags, we do support other well-formed, |
| 122 | // cases through normalization (but only kebab-case shows up in --help). |
| 123 | cmd.delegate.SetGlobalNormalizationFunc(normalize) |
| 124 | if v := version(); v != "" { |
| 125 | // Add the version subcommand only when the root command already has |
| 126 | // subcommands (similar to how Cobra does it for help / completion). |
| 127 | if cmd.delegate.HasSubCommands() { |
| 128 | cmd.delegate.AddCommand(versionCommand(cmd.delegate.Name(), v)) |
| 129 | } |
| 130 | cmd.delegate.Version = v |
| 131 | } |
| 132 | // Align the flag usages as a table (pflag's FlagUsages already does this to |
| 133 | // some extent but doesn't align types and default values). |
| 134 | cobra.AddTemplateFunc("flagUsages", flagUsages) |
| 135 | t := cmd.delegate.UsageTemplate() |
| 136 | t = strings.ReplaceAll(t, ".FlagUsages", " | flagUsages") |
| 137 | cmd.delegate.SetUsageTemplate(t) |
| 138 | return cmd.delegate.ExecuteContext(ctx) |
| 139 | } |
| 140 | |
| 141 | type funcCommandBuilder struct { |
| 142 | name string |
no test coverage detected