Skip to content

Commit

Permalink
Delay the display of warnings related to experimental features
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy committed Dec 5, 2022
1 parent 843543a commit f9d807c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pkg/odo/cli/feature/doc.go
@@ -1,2 +1,4 @@
// Package feature allows to determine whether a given feature is enabled or not at the CLI level.
// Active features are accumulated in a global `enabledFeatures` variable, and warning
// can be displayed with the DisplayWarnings function
package feature
18 changes: 17 additions & 1 deletion pkg/odo/cli/feature/features.go
Expand Up @@ -2,6 +2,7 @@ package feature

import (
"context"
"sort"

"github.com/redhat-developer/odo/pkg/log"
)
Expand All @@ -28,6 +29,8 @@ var (
isExperimental: true,
description: "flag: --run-on",
}

enabledFeatures = map[OdoFeature]struct{}{}
)

// IsEnabled returns whether the specified feature should be enabled or not.
Expand All @@ -42,8 +45,21 @@ func IsEnabled(ctx context.Context, feat OdoFeature) bool {
// Features marked as experimental are enabled only if the experimental mode is set
experimentalModeEnabled := isExperimentalModeEnabled(ctx)
if experimentalModeEnabled {
enabledFeatures[feat] = struct{}{}
}
return experimentalModeEnabled
}

func DisplayWarnings() {
features := make([]OdoFeature, 0, len(enabledFeatures))
for k := range enabledFeatures {
features = append(features, k)
}
sort.Slice(features, func(i, j int) bool {
return features[i].id < features[j].id
})
for _, feat := range features {
log.Experimentalf("Experimental mode enabled for %s. Use at your own risk. More details on https://odo.dev/docs/user-guides/advanced/experimental-mode",
feat.description)
}
return experimentalModeEnabled
}
3 changes: 3 additions & 0 deletions pkg/odo/genericclioptions/runnable.go
Expand Up @@ -26,6 +26,7 @@ import (

"gopkg.in/AlecAivazis/survey.v1"

"github.com/redhat-developer/odo/pkg/odo/cli/feature"
"github.com/redhat-developer/odo/pkg/odo/cli/ui"

"k8s.io/klog"
Expand Down Expand Up @@ -202,6 +203,8 @@ func GenericRun(o Runnable, cmd *cobra.Command, args []string) error {
}
o.SetClientset(deps)

feature.DisplayWarnings()

ctx = fcontext.WithJsonOutput(ctx, commonflags.GetJsonOutputValue(cmdLineObj))
ctx = fcontext.WithRunOn(ctx, platform)
ctx = odocontext.WithApplication(ctx, defaultAppName)
Expand Down

0 comments on commit f9d807c

Please sign in to comment.