Implement global options in zsh implementation
This commit is contained in:
parent
ba90879ff0
commit
26bee58adc
|
@ -15,7 +15,6 @@ func WriteZshCompletions(out io.Writer, rootCmd *Command) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Fix indentation and other spacing
|
// TODO: Fix indentation and other spacing
|
||||||
// TODO: Implement global options
|
|
||||||
var zshTpl = template.Must(template.New("zsh").Funcs(tplFuncs).Parse(`
|
var zshTpl = template.Must(template.New("zsh").Funcs(tplFuncs).Parse(`
|
||||||
{{- $rootCmd := .RootCmd -}}
|
{{- $rootCmd := .RootCmd -}}
|
||||||
{{- $progName := $rootCmd.Name -}}
|
{{- $progName := $rootCmd.Name -}}
|
||||||
|
@ -39,8 +38,12 @@ var zshTpl = template.Must(template.New("zsh").Funcs(tplFuncs).Parse(`
|
||||||
_arguments
|
_arguments
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- range .Cmd.Opts -}}
|
{{- range .Cmd.Opts -}}
|
||||||
{{ " " }}\
|
{{- if ne .Name ""}} \
|
||||||
|
'--{{ .Name }}[{{ .Description }}]'
|
||||||
|
{{- end }}
|
||||||
|
{{- if ne .ShortName ""}} \
|
||||||
'-{{ .ShortName }}[{{ .Description }}]'
|
'-{{ .ShortName }}[{{ .Description }}]'
|
||||||
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if gt (len .Cmd.Subcommands) 0 -}}
|
{{- if gt (len .Cmd.Subcommands) 0 -}}
|
||||||
{{ " " }}\
|
{{ " " }}\
|
||||||
|
@ -64,6 +67,18 @@ var zshTpl = template.Must(template.New("zsh").Funcs(tplFuncs).Parse(`
|
||||||
|
|
||||||
function _{{ $varName }} {
|
function _{{ $varName }} {
|
||||||
{{ template "cmd" (map "Cmd" .RootCmd) -}}
|
{{ template "cmd" (map "Cmd" .RootCmd) -}}
|
||||||
|
|
||||||
|
{{- if gt (len .GlobalOpts) 0 }}
|
||||||
|
_arguments
|
||||||
|
{{- range .GlobalOpts -}}
|
||||||
|
{{- if ne .Name ""}} \
|
||||||
|
'--{{ .Name }}[{{ .Description }}]'
|
||||||
|
{{- end }}
|
||||||
|
{{- if ne .ShortName ""}} \
|
||||||
|
'-{{ .ShortName }}[{{ .Description }}]'
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
}
|
}
|
||||||
|
|
||||||
compdef _{{ $varName }} {{ $progName }}
|
compdef _{{ $varName }} {{ $progName }}
|
||||||
|
|
Loading…
Reference in New Issue