Skip to content

Commit

Permalink
check (#739)
Browse files Browse the repository at this point in the history
* check

* check

---------

Co-authored-by: AlvoBen <[email protected]>
  • Loading branch information
AlvoBen and BenAlvo1 authored May 19, 2024
1 parent e639d4a commit 2981c57
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 20 additions & 0 deletions internal/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ func NewAstCLI(
// This monitors and traps situations where "extra/garbage" commands
// are passed to Cobra.
rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
if wrappers.DefaultFFLoad {
if requiredFeatureFlagsCheck(cmd) {
err := wrappers.HandleFeatureFlags(featureFlagsWrapper)

if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
}
PrintConfiguration()
// Need to check the __complete command to allow correct behavior of the autocomplete
if len(args) > 0 && cmd.Name() != params.Help && cmd.Name() != "__complete" {
Expand Down Expand Up @@ -219,6 +229,16 @@ func PrintConfiguration() {
}
}

func requiredFeatureFlagsCheck(cmd *cobra.Command) bool {
for _, cmdFlag := range wrappers.FeatureFlagsBaseMap {
if cmdFlag.CommandName == cmd.CommandPath() {
return true
}
}

return false
}

func setUpFeatureFlags(featureFlagsWrapper wrappers.FeatureFlagsWrapper) {
err := wrappers.HandleFeatureFlags(featureFlagsWrapper)

Expand Down
7 changes: 5 additions & 2 deletions internal/wrappers/feature-flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ const MinioEnabled = "MINIO_ENABLED"
const ContainerEngineCLIEnabled = "CONTAINER_ENGINE_CLI_ENABLED"
const NewScanReportEnabled = "NEW_SAST_SCAN_REPORT_ENABLED"

var DefaultFFLoad bool = false

var FeatureFlagsBaseMap = []CommandFlags{
{
CommandName: "cx scan create",
Expand All @@ -21,7 +23,7 @@ var FeatureFlagsBaseMap = []CommandFlags{
},
{
Name: MinioEnabled,
Default: true,
Default: false,
},
},
},
Expand All @@ -33,7 +35,7 @@ var FeatureFlagsBaseMap = []CommandFlags{
FeatureFlags: []FlagBase{
{
Name: MinioEnabled,
Default: true,
Default: false,
},
{
Name: feature_flags.ByorEnabled,
Expand Down Expand Up @@ -91,6 +93,7 @@ func loadFeatureFlagsDefaultValues() {
FeatureFlags[flag.Name] = flag.Default
}
}
DefaultFFLoad = true
}

type FeatureFlagsWrapper interface {
Expand Down

0 comments on commit 2981c57

Please sign in to comment.