File: completion.go

package info (click to toggle)
golang-github-containers-buildah 1.19.6%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,020 kB
  • sloc: sh: 1,957; makefile: 199; perl: 173; awk: 12; ansic: 1
file content (23 lines) | stat: -rw-r--r-- 771 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package completion

import (
	"strings"

	"github.com/spf13/cobra"
)

/* Autocomplete Functions for cobra ValidArgsFunction */

// AutocompleteNamespaceFlag - Autocomplete the userns flag.
// -> host, private, container, ns:[path], [path]
func AutocompleteNamespaceFlag(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
	var completions []string
	// If we don't filter on "toComplete", zsh and fish will not do file completion
	// even if the prefix typed by the user does not match the returned completions
	for _, comp := range []string{"host", "private", "container", "ns:"} {
		if strings.HasPrefix(comp, toComplete) {
			completions = append(completions, comp)
		}
	}
	return completions, cobra.ShellCompDirectiveDefault
}