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: Implement global options
|
||||
var zshTpl = template.Must(template.New("zsh").Funcs(tplFuncs).Parse(`
|
||||
{{- $rootCmd := .RootCmd -}}
|
||||
{{- $progName := $rootCmd.Name -}}
|
||||
|
@ -39,8 +38,12 @@ var zshTpl = template.Must(template.New("zsh").Funcs(tplFuncs).Parse(`
|
|||
_arguments
|
||||
{{- end -}}
|
||||
{{- range .Cmd.Opts -}}
|
||||
{{ " " }}\
|
||||
{{- if ne .Name ""}} \
|
||||
'--{{ .Name }}[{{ .Description }}]'
|
||||
{{- end }}
|
||||
{{- if ne .ShortName ""}} \
|
||||
'-{{ .ShortName }}[{{ .Description }}]'
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- if gt (len .Cmd.Subcommands) 0 -}}
|
||||
{{ " " }}\
|
||||
|
@ -64,6 +67,18 @@ var zshTpl = template.Must(template.New("zsh").Funcs(tplFuncs).Parse(`
|
|||
|
||||
function _{{ $varName }} {
|
||||
{{ 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 }}
|
||||
|
|
Loading…
Reference in New Issue