mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: move experimental flag to server (#4959)
This commit is contained in:
@@ -367,6 +367,11 @@ func newConfig() *codersdk.DeploymentConfig {
|
||||
Default: 10 * time.Minute,
|
||||
},
|
||||
},
|
||||
Experimental: &codersdk.DeploymentConfigField[bool]{
|
||||
Name: "Experimental",
|
||||
Usage: "Enable experimental features. Experimental features are not ready for production.",
|
||||
Flag: "experimental",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-19
@@ -50,12 +50,10 @@ const (
|
||||
varNoFeatureWarning = "no-feature-warning"
|
||||
varForceTty = "force-tty"
|
||||
varVerbose = "verbose"
|
||||
varExperimental = "experimental"
|
||||
notLoggedInMessage = "You are not logged in. Try logging in using 'coder login <url>'."
|
||||
|
||||
envNoVersionCheck = "CODER_NO_VERSION_WARNING"
|
||||
envNoFeatureWarning = "CODER_NO_FEATURE_WARNING"
|
||||
envExperimental = "CODER_EXPERIMENTAL"
|
||||
envSessionToken = "CODER_SESSION_TOKEN"
|
||||
envURL = "CODER_URL"
|
||||
)
|
||||
@@ -217,7 +215,6 @@ func Root(subcommands []*cobra.Command) *cobra.Command {
|
||||
cmd.PersistentFlags().Bool(varNoOpen, false, "Block automatically opening URLs in the browser.")
|
||||
_ = cmd.PersistentFlags().MarkHidden(varNoOpen)
|
||||
cliflag.Bool(cmd.PersistentFlags(), varVerbose, "v", "CODER_VERBOSE", false, "Enable verbose output.")
|
||||
cliflag.Bool(cmd.PersistentFlags(), varExperimental, "", envExperimental, false, "Enable experimental features. Experimental features are not ready for production.")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -643,19 +640,3 @@ func (h *headerTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
}
|
||||
return h.transport.RoundTrip(req)
|
||||
}
|
||||
|
||||
// ExperimentalEnabled returns if the experimental feature flag is enabled.
|
||||
func ExperimentalEnabled(cmd *cobra.Command) bool {
|
||||
enabled, _ := cmd.Flags().GetBool(varExperimental)
|
||||
return enabled
|
||||
}
|
||||
|
||||
// EnsureExperimental will ensure that the experimental feature flag is set if the given flag is set.
|
||||
func EnsureExperimental(cmd *cobra.Command, name string) error {
|
||||
_, set := cliflag.IsSet(cmd, name)
|
||||
if set && !ExperimentalEnabled(cmd) {
|
||||
return xerrors.Errorf("flag %s is set but requires flag --experimental or environment variable CODER_EXPERIMENTAL=true.", name)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
|
||||
"github.com/coder/coder/buildinfo"
|
||||
"github.com/coder/coder/cli"
|
||||
"github.com/coder/coder/cli/cliflag"
|
||||
"github.com/coder/coder/cli/clitest"
|
||||
"github.com/coder/coder/codersdk"
|
||||
"github.com/coder/coder/testutil"
|
||||
@@ -230,19 +229,4 @@ func TestRoot(t *testing.T) {
|
||||
// This won't succeed, because we're using the login cmd to assert requests.
|
||||
_ = cmd.Execute()
|
||||
})
|
||||
|
||||
t.Run("Experimental", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cmd, _ := clitest.New(t, "--experimental")
|
||||
err := cmd.Execute()
|
||||
require.NoError(t, err)
|
||||
require.True(t, cli.ExperimentalEnabled(cmd))
|
||||
|
||||
cmd, _ = clitest.New(t, "help", "--verbose")
|
||||
_ = cmd.Execute()
|
||||
_, set := cliflag.IsSet(cmd, "verbose")
|
||||
require.True(t, set)
|
||||
require.ErrorContains(t, cli.EnsureExperimental(cmd, "verbose"), "--experimental")
|
||||
})
|
||||
}
|
||||
|
||||
@@ -357,7 +357,6 @@ func Server(vip *viper.Viper, newAPI func(context.Context, *coderd.Options) (*co
|
||||
AutoImportTemplates: validatedAutoImportTemplates,
|
||||
MetricsCacheRefreshInterval: cfg.MetricsCacheRefreshInterval.Value,
|
||||
AgentStatsRefreshInterval: cfg.AgentStatRefreshInterval.Value,
|
||||
Experimental: ExperimentalEnabled(cmd),
|
||||
DeploymentConfig: cfg,
|
||||
PrometheusRegistry: prometheus.NewRegistry(),
|
||||
}
|
||||
|
||||
Vendored
-3
@@ -44,9 +44,6 @@ Workspace Commands:
|
||||
update Update a workspace
|
||||
|
||||
Flags:
|
||||
--experimental Enable experimental features. Experimental features are not
|
||||
ready for production.
|
||||
Consumes $CODER_EXPERIMENTAL
|
||||
--global-config coder Path to the global coder config directory.
|
||||
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
|
||||
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
|
||||
|
||||
+4
-3
@@ -52,6 +52,10 @@ Flags:
|
||||
Consumes
|
||||
$CODER_DERP_SERVER_STUN_ADDRESSES
|
||||
(default [stun.l.google.com:19302])
|
||||
--experimental Enable experimental features.
|
||||
Experimental features are not ready for
|
||||
production.
|
||||
Consumes $CODER_EXPERIMENTAL
|
||||
-h, --help help for server
|
||||
--oauth2-github-allow-signups Whether new users can sign up with
|
||||
GitHub.
|
||||
@@ -190,9 +194,6 @@ Flags:
|
||||
Consumes $CODER_WILDCARD_ACCESS_URL
|
||||
|
||||
Global Flags:
|
||||
--experimental Enable experimental features. Experimental features are not
|
||||
ready for production.
|
||||
Consumes $CODER_EXPERIMENTAL
|
||||
--global-config coder Path to the global coder config directory.
|
||||
Consumes $CODER_CONFIG_DIR (default "/tmp/coder-cli-test-config")
|
||||
--header stringArray HTTP headers added to all requests. Provide as "Key=Value".
|
||||
|
||||
Reference in New Issue
Block a user