Skip to content

feat: add experimental flag #4364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make public
  • Loading branch information
f0ssel committed Oct 4, 2022
commit 19acbf24cfd6f0dfa9db36cd9899f1506ffb989d
6 changes: 3 additions & 3 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,15 +602,15 @@ 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 {
// ExperimentalEnabled returns if the experimental feature flag is enabled.
func ExperimentalEnabled(cmd *cobra.Command) bool {
return cliflag.IsSetBool(cmd, varExperimental)
}

// 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) {
if set && !ExperimentalEnabled(cmd) {
return xerrors.Errorf("flag %s is set but requires flag --experimental or environment variable CODER_EXPERIMENTAL=true.", name)
}

Expand Down
8 changes: 3 additions & 5 deletions cli/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,14 @@ func TestRoot(t *testing.T) {
t.Run("Experimental", func(t *testing.T) {
t.Parallel()

cmd, _ := clitest.New(t, "--verbose", "--experimental")
cmd, _ := clitest.New(t, "--experimental")
err := cmd.Execute()
require.NoError(t, err)
_, set := cliflag.IsSet(cmd, "verbose")
require.True(t, set)
require.NoError(t, cli.EnsureExperimental(cmd, "verbose"))
require.True(t, cli.ExperimentalEnabled(cmd))

cmd, _ = clitest.New(t, "help", "--verbose")
_ = cmd.Execute()
_, set = cliflag.IsSet(cmd, "verbose")
_, set := cliflag.IsSet(cmd, "verbose")
require.True(t, set)
require.ErrorContains(t, cli.EnsureExperimental(cmd, "verbose"), "--experimental")
})
Expand Down
2 changes: 1 addition & 1 deletion cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ func Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, error))
AutoImportTemplates: validatedAutoImportTemplates,
MetricsCacheRefreshInterval: metricsCacheRefreshInterval,
AgentStatsRefreshInterval: agentStatRefreshInterval,
Experimental: experimentalEnabled(cmd),
Experimental: ExperimentalEnabled(cmd),
}

if oauth2GithubClientSecret != "" {
Expand Down