-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
janelletavares
committed
Jan 16, 2022
1 parent
ba8117e
commit c0183ca
Showing
6 changed files
with
217 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,7 +176,7 @@ type CommandWithSubCommands interface { | |
|
||
type CommandWithFeatureFlag interface { | ||
Command | ||
FeatureFlag() string | ||
FeatureFlag() (string, error) | ||
} | ||
|
||
// BuildCobraCommand takes a Command and builds a *cobra.Command from it. It figures out if the command implements any | ||
|
@@ -666,10 +666,6 @@ func buildCommandWithFeatureFlag(cmd *cobra.Command, c Command) { | |
return | ||
} | ||
|
||
// Considering a command with feature flags not ready to be documented and | ||
// publicly available. | ||
cmd.Hidden = true | ||
|
||
old := cmd.PreRunE | ||
cmd.PreRunE = func(cmd *cobra.Command, args []string) error { | ||
if old != nil { | ||
|
@@ -679,14 +675,30 @@ func buildCommandWithFeatureFlag(cmd *cobra.Command, c Command) { | |
} | ||
} | ||
|
||
flagRequired := v.FeatureFlag() | ||
flagRequired, err := v.FeatureFlag() | ||
userFeatureFlags := global.Config.GetStringSlice(global.UserFeatureFlagsEnv) | ||
|
||
if !hasFeatureFlag(userFeatureFlags, flagRequired) { | ||
return fmt.Errorf("your account does not have access to the %q feature. "+ | ||
"Reach out to [email protected] for more information", flagRequired) | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func CheckFeatureFlag(exec Command, cmd CommandWithFeatureFlag) error { | ||
if global.Config == nil { | ||
c := BuildCobraCommand(exec) | ||
_ = global.PersistentPreRunE(c) | ||
} | ||
flagRequired, err := cmd.FeatureFlag() | ||
if global.Config.Get(global.UserFeatureFlagsEnv) == "" { | ||
return err | ||
} | ||
userFeatureFlags := global.Config.GetStringSlice(global.UserFeatureFlagsEnv) | ||
|
||
if !hasFeatureFlag(userFeatureFlags, flagRequired) { | ||
return err | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.