mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
normalize flag names so that underscores are interchangeable with hyphens
This commit is contained in:
@@ -30,7 +30,7 @@ class Option:
|
|||||||
short = flags[0][1:]
|
short = flags[0][1:]
|
||||||
long = flags[-1][2:]
|
long = flags[-1][2:]
|
||||||
if not long:
|
if not long:
|
||||||
raise SystemExit(f'No long flag for {x} with flags {flags}')
|
raise TypeError(f'No long flag for {x} with flags {flags}')
|
||||||
self.short, self.long = short, long
|
self.short, self.long = short, long
|
||||||
self.usage = serialize_as_go_string(x['help'].strip())
|
self.usage = serialize_as_go_string(x['help'].strip())
|
||||||
self.type = x['type']
|
self.type = x['type']
|
||||||
@@ -70,7 +70,7 @@ class Option:
|
|||||||
return f'cli.ChoicesP({base}, "{self.long}", "{self.short}", "{self.usage}", {cx})'
|
return f'cli.ChoicesP({base}, "{self.long}", "{self.short}", "{self.usage}", {cx})'
|
||||||
return f'cli.Choices({base}, "{self.long}", "{self.usage}", {cx})'
|
return f'cli.Choices({base}, "{self.long}", "{self.usage}", {cx})'
|
||||||
else:
|
else:
|
||||||
raise KeyError(f'Unknown type of CLI option: {self.type}')
|
raise TypeError(f'Unknown type of CLI option: {self.type} for {self.long}')
|
||||||
|
|
||||||
|
|
||||||
def build_go_code(name: str, cmd: RemoteCommand, seq: OptionSpecSeq, template: str) -> str:
|
def build_go_code(name: str, cmd: RemoteCommand, seq: OptionSpecSeq, template: str) -> str:
|
||||||
|
|||||||
@@ -402,6 +402,9 @@ func Init(root *cobra.Command) {
|
|||||||
root.SetHelpFunc(show_help)
|
root.SetHelpFunc(show_help)
|
||||||
root.SetHelpCommand(&cobra.Command{Hidden: true})
|
root.SetHelpCommand(&cobra.Command{Hidden: true})
|
||||||
root.CompletionOptions.DisableDefaultCmd = true
|
root.CompletionOptions.DisableDefaultCmd = true
|
||||||
|
root.SetGlobalNormalizationFunc(func(fs *pflag.FlagSet, name string) pflag.NormalizedName {
|
||||||
|
return pflag.NormalizedName(strings.ReplaceAll(name, "_", "-"))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func Execute(root *cobra.Command) error {
|
func Execute(root *cobra.Command) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user