github.com/sleungcy/cli@v7.1.0+incompatible/command/v7/config_command.go (about)

     1  package v7
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/command"
     5  	"code.cloudfoundry.org/cli/command/flag"
     6  	"code.cloudfoundry.org/cli/command/translatableerror"
     7  )
     8  
     9  type ConfigCommand struct {
    10  	UI           command.UI
    11  	Config       command.Config
    12  	AsyncTimeout flag.Timeout      `long:"async-timeout" description:"Timeout in minutes for async HTTP requests"`
    13  	Color        flag.Color        `long:"color" description:"Enable or disable color in CLI output"`
    14  	Locale       flag.Locale       `long:"locale" description:"Set default locale. If LOCALE is 'CLEAR', previous locale is deleted."`
    15  	Trace        flag.PathWithBool `long:"trace" description:"Trace HTTP requests by default. If a file path is provided then output will write to the file provided. If the file does not exist it will be created."`
    16  	usage        interface{}       `usage:"CF_NAME config [--async-timeout TIMEOUT_IN_MINUTES] [--trace (true | false | path/to/file)] [--color (true | false)] [--locale (LOCALE | CLEAR)]"`
    17  }
    18  
    19  func (cmd *ConfigCommand) Setup(config command.Config, ui command.UI) error {
    20  	cmd.Config = config
    21  	cmd.UI = ui
    22  
    23  	return nil
    24  }
    25  
    26  func (cmd ConfigCommand) Execute(args []string) error {
    27  	if !cmd.Color.IsSet && cmd.Trace == "" && cmd.Locale.Locale == "" && !cmd.AsyncTimeout.IsSet {
    28  		return translatableerror.IncorrectUsageError{Message: "at least one flag must be provided"}
    29  	}
    30  
    31  	cmd.UI.DisplayText("Setting values in config...")
    32  
    33  	if cmd.AsyncTimeout.IsSet {
    34  		cmd.Config.SetAsyncTimeout(cmd.AsyncTimeout.Value)
    35  	}
    36  
    37  	if cmd.Color.IsSet {
    38  		cmd.Config.SetColorEnabled(cmd.Color.Value)
    39  	}
    40  
    41  	if cmd.Locale.Locale != "" {
    42  		cmd.Config.SetLocale(cmd.Locale.Locale)
    43  	}
    44  
    45  	if cmd.Trace != "" {
    46  		cmd.Config.SetTrace(string(cmd.Trace))
    47  	}
    48  
    49  	cmd.UI.DisplayOK()
    50  	return nil
    51  }