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

     1  package v7
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/v7action"
     5  	"code.cloudfoundry.org/cli/command/flag"
     6  	"code.cloudfoundry.org/cli/command/v7/shared"
     7  	"code.cloudfoundry.org/cli/util/ui"
     8  )
     9  
    10  type FeatureFlagCommand struct {
    11  	BaseCommand
    12  
    13  	RequiredArgs    flag.Feature `positional-args:"yes"`
    14  	usage           interface{}  `usage:"CF_NAME feature-flag FEATURE_FLAG_NAME"`
    15  	relatedCommands interface{}  `related_commands:"disable-feature-flag, enable-feature-flag, feature-flags"`
    16  }
    17  
    18  func (cmd FeatureFlagCommand) Execute(args []string) error {
    19  	err := cmd.SharedActor.CheckTarget(false, false)
    20  	if err != nil {
    21  		return err
    22  	}
    23  
    24  	user, err := cmd.Config.CurrentUser()
    25  	if err != nil {
    26  		return err
    27  	}
    28  
    29  	cmd.UI.DisplayTextWithFlavor("Getting info for feature flag {{.FeatureFlag}} as {{.Username}}...", map[string]interface{}{
    30  		"FeatureFlag": cmd.RequiredArgs.Feature,
    31  		"Username":    user.Name,
    32  	})
    33  	cmd.UI.DisplayNewline()
    34  
    35  	featureFlag, warnings, err := cmd.Actor.GetFeatureFlagByName(cmd.RequiredArgs.Feature)
    36  	cmd.UI.DisplayWarnings(warnings)
    37  	if err != nil {
    38  		return err
    39  	}
    40  
    41  	cmd.displayTable(featureFlag)
    42  	return nil
    43  }
    44  
    45  func (cmd FeatureFlagCommand) displayTable(featureFlag v7action.FeatureFlag) {
    46  	var keyValueTable = [][]string{
    47  		{"Features", "State"},
    48  		{featureFlag.Name, shared.FlagBoolToString(featureFlag.Enabled)},
    49  	}
    50  
    51  	cmd.UI.DisplayTableWithHeader("", keyValueTable, ui.DefaultTableSpacePadding)
    52  }