github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/cf/commands/featureflag/enable_feature_flag.go (about) 1 package featureflag 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/cf/api/featureflags" 7 "code.cloudfoundry.org/cli/cf/commandregistry" 8 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 9 "code.cloudfoundry.org/cli/cf/flags" 10 . "code.cloudfoundry.org/cli/cf/i18n" 11 "code.cloudfoundry.org/cli/cf/requirements" 12 "code.cloudfoundry.org/cli/cf/terminal" 13 ) 14 15 type EnableFeatureFlag struct { 16 ui terminal.UI 17 config coreconfig.ReadWriter 18 flagRepo featureflags.FeatureFlagRepository 19 } 20 21 func init() { 22 commandregistry.Register(&EnableFeatureFlag{}) 23 } 24 25 func (cmd *EnableFeatureFlag) MetaData() commandregistry.CommandMetadata { 26 return commandregistry.CommandMetadata{ 27 Name: "enable-feature-flag", 28 Description: T("Enable the use of a feature so that users have access to and can use the feature"), 29 Usage: []string{ 30 T("CF_NAME enable-feature-flag FEATURE_NAME"), 31 }, 32 } 33 } 34 35 func (cmd *EnableFeatureFlag) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) { 36 if len(fc.Args()) != 1 { 37 cmd.ui.Failed(T("Incorrect Usage. Requires an argument\n\n") + commandregistry.Commands.CommandUsage("enable-feature-flag")) 38 return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 1) 39 } 40 41 reqs := []requirements.Requirement{ 42 requirementsFactory.NewLoginRequirement(), 43 } 44 45 return reqs, nil 46 } 47 48 func (cmd *EnableFeatureFlag) SetDependency(deps commandregistry.Dependency, pluginCall bool) commandregistry.Command { 49 cmd.ui = deps.UI 50 cmd.config = deps.Config 51 cmd.flagRepo = deps.RepoLocator.GetFeatureFlagRepository() 52 return cmd 53 } 54 55 func (cmd *EnableFeatureFlag) Execute(c flags.FlagContext) error { 56 flag := c.Args()[0] 57 58 cmd.ui.Say(T("Setting status of {{.FeatureFlag}} as {{.Username}}...", map[string]interface{}{ 59 "FeatureFlag": terminal.EntityNameColor(flag), 60 "Username": terminal.EntityNameColor(cmd.config.Username())})) 61 62 err := cmd.flagRepo.Update(flag, true) 63 if err != nil { 64 return err 65 } 66 67 cmd.ui.Say("") 68 cmd.ui.Ok() 69 cmd.ui.Say("") 70 cmd.ui.Say(T("Feature {{.FeatureFlag}} Enabled.", map[string]interface{}{ 71 "FeatureFlag": terminal.EntityNameColor(flag)})) 72 return nil 73 }