github.com/argoproj/argo-cd/v3@v3.2.1/cmd/argocd/commands/configure.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strconv"
     7  
     8  	"github.com/spf13/cobra"
     9  
    10  	argocdclient "github.com/argoproj/argo-cd/v3/pkg/apiclient"
    11  	"github.com/argoproj/argo-cd/v3/util/errors"
    12  	"github.com/argoproj/argo-cd/v3/util/localconfig"
    13  )
    14  
    15  // NewConfigureCommand returns a new instance of an `argocd configure` command
    16  func NewConfigureCommand(globalClientOpts *argocdclient.ClientOptions) *cobra.Command {
    17  	var promptsEnabled bool
    18  
    19  	command := &cobra.Command{
    20  		Use:   "configure",
    21  		Short: "Manage local configuration",
    22  		Example: `# Enable optional interactive prompts
    23  argocd configure --prompts-enabled
    24  argocd configure --prompts-enabled=true
    25  
    26  # Disable optional interactive prompts
    27  argocd configure --prompts-enabled=false`,
    28  		Run: func(_ *cobra.Command, _ []string) {
    29  			localCfg, err := localconfig.ReadLocalConfig(globalClientOpts.ConfigPath)
    30  			errors.CheckError(err)
    31  			if localCfg == nil {
    32  				fmt.Println("No local configuration found")
    33  				os.Exit(1)
    34  			}
    35  
    36  			localCfg.PromptsEnabled = promptsEnabled
    37  
    38  			err = localconfig.WriteLocalConfig(*localCfg, globalClientOpts.ConfigPath)
    39  			errors.CheckError(err)
    40  
    41  			fmt.Println("Successfully updated the following configuration settings:")
    42  			fmt.Printf("prompts-enabled: %v\n", strconv.FormatBool(localCfg.PromptsEnabled))
    43  		},
    44  	}
    45  
    46  	command.Flags().BoolVar(&promptsEnabled, "prompts-enabled", localconfig.GetPromptsEnabled(false), "Enable (or disable) optional interactive prompts")
    47  
    48  	return command
    49  }