From be22f25a9e23b034ddc01a0452749f53ffe0bee2 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Fri, 1 Sep 2023 17:20:34 +0000 Subject: [PATCH] refactor(enterprise/cli): remove provisionerd from slim binary This change saves 8 MB in the slim binary. Ref: #9380 --- enterprise/cli/provisionerdaemons.go | 2 ++ enterprise/cli/provisionerdaemons_slim.go | 23 +++++++++++++++++++++++ enterprise/cli/proxyserver_slim.go | 15 +-------------- enterprise/cli/root.go | 16 ++++++++++++++++ 4 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 enterprise/cli/provisionerdaemons_slim.go diff --git a/enterprise/cli/provisionerdaemons.go b/enterprise/cli/provisionerdaemons.go index 00b2c9dafdf95..124c253595ac2 100644 --- a/enterprise/cli/provisionerdaemons.go +++ b/enterprise/cli/provisionerdaemons.go @@ -1,3 +1,5 @@ +//go:build !slim + package cli import ( diff --git a/enterprise/cli/provisionerdaemons_slim.go b/enterprise/cli/provisionerdaemons_slim.go new file mode 100644 index 0000000000000..4478987cf00b1 --- /dev/null +++ b/enterprise/cli/provisionerdaemons_slim.go @@ -0,0 +1,23 @@ +//go:build slim + +package cli + +import ( + "github.com/coder/coder/v2/cli/clibase" +) + +func (r *RootCmd) provisionerDaemons() *clibase.Cmd { + cmd := &clibase.Cmd{ + Use: "provisionerd", + Short: "Manage provisioner daemons", + // We accept RawArgs so all commands and flags are accepted. + RawArgs: true, + Hidden: true, + Handler: func(inv *clibase.Invocation) error { + slimUnsupported(inv.Stderr, "coder provisionerd") + return nil + }, + } + + return cmd +} diff --git a/enterprise/cli/proxyserver_slim.go b/enterprise/cli/proxyserver_slim.go index 85570a98d45fc..2b5362b01ffc7 100644 --- a/enterprise/cli/proxyserver_slim.go +++ b/enterprise/cli/proxyserver_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) proxyServer() *clibase.Cmd { @@ -20,18 +15,10 @@ func (r *RootCmd) proxyServer() *clibase.Cmd { RawArgs: true, Hidden: true, Handler: func(inv *clibase.Invocation) error { - serverUnsupported(inv.Stderr) + slimUnsupported(inv.Stderr, "workspace-proxy 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/root.go b/enterprise/cli/root.go index 360582a3e5193..6e02ab08a3f9e 100644 --- a/enterprise/cli/root.go +++ b/enterprise/cli/root.go @@ -1,8 +1,13 @@ 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 { @@ -24,3 +29,14 @@ 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) +}