github.com/thajeztah/cli@v0.0.0-20240223162942-dc6bfac81a8b/cmd/docker/completions.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/docker/cli/cli/context/store"
     5  	"github.com/spf13/cobra"
     6  )
     7  
     8  func registerCompletionFuncForGlobalFlags(contextStore store.Store, cmd *cobra.Command) error {
     9  	err := cmd.RegisterFlagCompletionFunc(
    10  		"context",
    11  		func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
    12  			names, err := store.Names(contextStore)
    13  			if err != nil {
    14  				return nil, cobra.ShellCompDirectiveError
    15  			}
    16  			return names, cobra.ShellCompDirectiveNoFileComp
    17  		},
    18  	)
    19  	if err != nil {
    20  		return err
    21  	}
    22  	err = cmd.RegisterFlagCompletionFunc(
    23  		"log-level",
    24  		func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
    25  			values := []string{"debug", "info", "warn", "error", "fatal"}
    26  			return values, cobra.ShellCompDirectiveNoFileComp
    27  		},
    28  	)
    29  	if err != nil {
    30  		return err
    31  	}
    32  
    33  	return nil
    34  }