diff --git a/cli/resetpassword.go b/cli/resetpassword.go index 7df9481417b28..aee1798a51db5 100644 --- a/cli/resetpassword.go +++ b/cli/resetpassword.go @@ -1,3 +1,5 @@ +//go:build !slim + package cli import ( diff --git a/cli/resetpassword_slim.go b/cli/resetpassword_slim.go new file mode 100644 index 0000000000000..1b69b8d8b65a5 --- /dev/null +++ b/cli/resetpassword_slim.go @@ -0,0 +1,23 @@ +//go:build slim + +package cli + +import ( + "github.com/coder/coder/v2/cli/clibase" +) + +func (*RootCmd) resetPassword() *clibase.Cmd { + root := &clibase.Cmd{ + Use: "reset-password ", + Short: "Directly connect to the database to reset a user's password", + // We accept RawArgs so all commands and flags are accepted. + RawArgs: true, + Hidden: true, + Handler: func(inv *clibase.Invocation) error { + SlimUnsupported(inv.Stderr, "reset-password") + return nil + }, + } + + return root +} diff --git a/cli/root.go b/cli/root.go index 3849738817b05..fd258e02af454 100644 --- a/cli/root.go +++ b/cli/root.go @@ -1019,3 +1019,14 @@ func (p *prettyErrorFormatter) printf(style lipgloss.Style, format string, a ... ), ) } + +//nolint:unused +func SlimUnsupported(w io.Writer, cmd string) { + _, _ = fmt.Fprintf(w, "You are using a 'slim' build of Coder, which does not support the %s subcommand.\n", cliui.DefaultStyles.Code.Render(cmd)) + _, _ = fmt.Fprintln(w, "") + _, _ = fmt.Fprintln(w, "Please use a build of Coder from GitHub releases:") + _, _ = fmt.Fprintln(w, " https://github.com/coder/coder/releases") + + //nolint:revive + os.Exit(1) +} diff --git a/cli/server_slim.go b/cli/server_slim.go index fadb703cc6466..d3a4693ec7634 100644 --- a/cli/server_slim.go +++ b/cli/server_slim.go @@ -3,12 +3,7 @@ package cli import ( - "fmt" - "io" - "os" - "github.com/coder/coder/v2/cli/clibase" - "github.com/coder/coder/v2/cli/cliui" ) func (r *RootCmd) Server(_ func()) *clibase.Cmd { @@ -19,18 +14,10 @@ func (r *RootCmd) Server(_ func()) *clibase.Cmd { RawArgs: true, Hidden: true, Handler: func(inv *clibase.Invocation) error { - serverUnsupported(inv.Stderr) + SlimUnsupported(inv.Stderr, "server") return nil }, } return root } - -func serverUnsupported(w io.Writer) { - _, _ = fmt.Fprintf(w, "You are using a 'slim' build of Coder, which does not support the %s subcommand.\n", cliui.DefaultStyles.Code.Render("server")) - _, _ = fmt.Fprintln(w, "") - _, _ = fmt.Fprintln(w, "Please use a build of Coder from GitHub releases:") - _, _ = fmt.Fprintln(w, " https://github.com/coder/coder/releases") - os.Exit(1) -} diff --git a/enterprise/cli/provisionerdaemons_slim.go b/enterprise/cli/provisionerdaemons_slim.go index 4478987cf00b1..27fdf74b0ac59 100644 --- a/enterprise/cli/provisionerdaemons_slim.go +++ b/enterprise/cli/provisionerdaemons_slim.go @@ -3,6 +3,7 @@ package cli import ( + agplcli "github.com/coder/coder/v2/cli" "github.com/coder/coder/v2/cli/clibase" ) @@ -14,7 +15,7 @@ func (r *RootCmd) provisionerDaemons() *clibase.Cmd { RawArgs: true, Hidden: true, Handler: func(inv *clibase.Invocation) error { - slimUnsupported(inv.Stderr, "coder provisionerd") + agplcli.SlimUnsupported(inv.Stderr, "provisionerd") return nil }, } diff --git a/enterprise/cli/proxyserver_slim.go b/enterprise/cli/proxyserver_slim.go index 2b5362b01ffc7..c23ccd998aa21 100644 --- a/enterprise/cli/proxyserver_slim.go +++ b/enterprise/cli/proxyserver_slim.go @@ -3,6 +3,7 @@ package cli import ( + agplcli "github.com/coder/coder/v2/cli" "github.com/coder/coder/v2/cli/clibase" ) @@ -15,7 +16,7 @@ func (r *RootCmd) proxyServer() *clibase.Cmd { RawArgs: true, Hidden: true, Handler: func(inv *clibase.Invocation) error { - slimUnsupported(inv.Stderr, "workspace-proxy server") + agplcli.SlimUnsupported(inv.Stderr, "workspace-proxy server") return nil }, } diff --git a/enterprise/cli/root.go b/enterprise/cli/root.go index 6e02ab08a3f9e..360582a3e5193 100644 --- a/enterprise/cli/root.go +++ b/enterprise/cli/root.go @@ -1,13 +1,8 @@ package cli import ( - "fmt" - "io" - "os" - "github.com/coder/coder/v2/cli" "github.com/coder/coder/v2/cli/clibase" - "github.com/coder/coder/v2/cli/cliui" ) type RootCmd struct { @@ -29,14 +24,3 @@ func (r *RootCmd) EnterpriseSubcommands() []*clibase.Cmd { all := append(r.Core(), r.enterpriseOnly()...) return all } - -//nolint:unused -func slimUnsupported(w io.Writer, cmd string) { - _, _ = fmt.Fprintf(w, "You are using a 'slim' build of Coder, which does not support the %s subcommand.\n", cliui.DefaultStyles.Code.Render(cmd)) - _, _ = fmt.Fprintln(w, "") - _, _ = fmt.Fprintln(w, "Please use a build of Coder from GitHub releases:") - _, _ = fmt.Fprintln(w, " https://github.com/coder/coder/releases") - - //nolint:revive - os.Exit(1) -}