zotregistry.dev/zot@v1.4.4-0.20240314164342-eec277e14d20/pkg/cli/client/image_cmd.go (about)

     1  //go:build search
     2  // +build search
     3  
     4  package client
     5  
     6  import (
     7  	"strconv"
     8  	"time"
     9  
    10  	"github.com/spf13/cobra"
    11  )
    12  
    13  const (
    14  	spinnerDuration = 150 * time.Millisecond
    15  	usageFooter     = `
    16  Run 'zli config -h' for details on [config-name] argument
    17  `
    18  )
    19  
    20  func NewImageCommand(searchService SearchService) *cobra.Command {
    21  	imageCmd := &cobra.Command{
    22  		Use:   "image [command]",
    23  		Short: "List images hosted on the zot registry",
    24  		Long:  `List images hosted on the zot registry`,
    25  		RunE:  ShowSuggestionsIfUnknownCommand,
    26  	}
    27  
    28  	imageCmd.SetUsageTemplate(imageCmd.UsageTemplate() + usageFooter)
    29  
    30  	imageCmd.PersistentFlags().String(URLFlag, "",
    31  		"Specify zot server URL if config-name is not mentioned")
    32  	imageCmd.PersistentFlags().String(ConfigFlag, "",
    33  		"Specify the registry configuration to use for connection")
    34  	imageCmd.PersistentFlags().StringP(UserFlag, "u", "",
    35  		`User Credentials of zot server in "username:password" format`)
    36  	imageCmd.PersistentFlags().StringP(OutputFormatFlag, "f", "", "Specify output format [text/json/yaml]")
    37  	imageCmd.PersistentFlags().Bool(VerboseFlag, false, "Show verbose output")
    38  	imageCmd.PersistentFlags().Bool(DebugFlag, false, "Show debug output")
    39  
    40  	imageCmd.AddCommand(NewImageListCommand(searchService))
    41  	imageCmd.AddCommand(NewImageCVEListCommand(searchService))
    42  	imageCmd.AddCommand(NewImageBaseCommand(searchService))
    43  	imageCmd.AddCommand(NewImageDerivedCommand(searchService))
    44  	imageCmd.AddCommand(NewImageDigestCommand(searchService))
    45  	imageCmd.AddCommand(NewImageNameCommand(searchService))
    46  
    47  	return imageCmd
    48  }
    49  
    50  func parseBooleanConfig(configPath, configName, configParam string) (bool, error) {
    51  	config, err := getConfigValue(configPath, configName, configParam)
    52  	if err != nil {
    53  		return false, err
    54  	}
    55  
    56  	val, err := strconv.ParseBool(config)
    57  	if err != nil {
    58  		return false, err
    59  	}
    60  
    61  	return val, nil
    62  }