mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
feat(comp): Completion for the docs --type flag
Add completion for the --type flag of the docs command. Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
This commit is contained in:
parent
bb875c3e2b
commit
3c4ccade13
4 changed files with 32 additions and 0 deletions
|
|
@ -68,6 +68,17 @@ func newDocsCmd(out io.Writer) *cobra.Command {
|
|||
f.StringVar(&o.docTypeString, "type", "markdown", "the type of documentation to generate (markdown, man, bash)")
|
||||
f.BoolVar(&o.generateHeaders, "generate-headers", false, "generate standard headers for markdown files")
|
||||
|
||||
cmd.RegisterFlagCompletionFunc("type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||
types := []string{"bash", "man", "markdown"}
|
||||
var comps []string
|
||||
for _, t := range types {
|
||||
if strings.HasPrefix(t, toComplete) {
|
||||
comps = append(comps, t)
|
||||
}
|
||||
}
|
||||
return comps, cobra.ShellCompDirectiveNoFileComp
|
||||
})
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,19 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestDocsTypeFlagCompletion(t *testing.T) {
|
||||
tests := []cmdTestCase{{
|
||||
name: "completion for docs --type",
|
||||
cmd: "__complete docs --type ''",
|
||||
golden: "output/docs-type-comp.txt",
|
||||
}, {
|
||||
name: "completion for docs --type",
|
||||
cmd: "__complete docs --type mar",
|
||||
golden: "output/docs-type-filtered-comp.txt",
|
||||
}}
|
||||
runTestCmd(t, tests)
|
||||
}
|
||||
|
||||
func TestDocsFileCompletion(t *testing.T) {
|
||||
checkFileCompletion(t, "docs", false)
|
||||
}
|
||||
|
|
|
|||
5
cmd/helm/testdata/output/docs-type-comp.txt
vendored
Normal file
5
cmd/helm/testdata/output/docs-type-comp.txt
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
bash
|
||||
man
|
||||
markdown
|
||||
:4
|
||||
Completion ended with directive: ShellCompDirectiveNoFileComp
|
||||
3
cmd/helm/testdata/output/docs-type-filtered-comp.txt
vendored
Normal file
3
cmd/helm/testdata/output/docs-type-filtered-comp.txt
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
markdown
|
||||
:4
|
||||
Completion ended with directive: ShellCompDirectiveNoFileComp
|
||||
Loading…
Reference in a new issue