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

     1  //go:build search
     2  // +build search
     3  
     4  package client
     5  
     6  import (
     7  	distspec "github.com/opencontainers/distribution-spec/specs-go"
     8  	"github.com/rs/zerolog/log"
     9  	"github.com/spf13/cobra"
    10  
    11  	"zotregistry.dev/zot/pkg/api/config"
    12  )
    13  
    14  // "zli" - client-side cli.
    15  func NewCliRootCmd() *cobra.Command {
    16  	showVersion := false
    17  
    18  	rootCmd := &cobra.Command{
    19  		Use:   "zli",
    20  		Short: "`zli`",
    21  		Long:  "`zli`",
    22  		Run: func(cmd *cobra.Command, args []string) {
    23  			if showVersion {
    24  				log.Info().Str("distribution-spec", distspec.Version).Str("commit", config.Commit).
    25  					Str("binary-type", config.BinaryType).Str("go version", config.GoVersion).Msg("version")
    26  			} else {
    27  				_ = cmd.Usage()
    28  				cmd.SilenceErrors = false
    29  			}
    30  		},
    31  	}
    32  
    33  	rootCmd.SilenceUsage = true
    34  
    35  	// additional cmds
    36  	enableCli(rootCmd)
    37  	// "version"
    38  	rootCmd.Flags().BoolVarP(&showVersion, VersionFlag, "v", false, "show the version and exit")
    39  
    40  	return rootCmd
    41  }