Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d211594

Browse files
authored
refactor(cli)!: remove reset-password from slim binary (#9520)
This is an alternative approach to #9519 and removes 2 MB instead of 1 MB (1.2 MB accounted for by embedded migration SQL files). Combined with #9481, #9506, #9508, #9517, a total of 5 MB is removed. Ref: #9380
1 parent ad23d33 commit d211594

File tree

7 files changed

+41
-32
lines changed

7 files changed

+41
-32
lines changed

cli/resetpassword.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build !slim
2+
13
package cli
24

35
import (

cli/resetpassword_slim.go

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//go:build slim
2+
3+
package cli
4+
5+
import (
6+
"github.com/coder/coder/v2/cli/clibase"
7+
)
8+
9+
func (*RootCmd) resetPassword() *clibase.Cmd {
10+
root := &clibase.Cmd{
11+
Use: "reset-password <username>",
12+
Short: "Directly connect to the database to reset a user's password",
13+
// We accept RawArgs so all commands and flags are accepted.
14+
RawArgs: true,
15+
Hidden: true,
16+
Handler: func(inv *clibase.Invocation) error {
17+
SlimUnsupported(inv.Stderr, "reset-password")
18+
return nil
19+
},
20+
}
21+
22+
return root
23+
}

cli/root.go

+11
Original file line numberDiff line numberDiff line change
@@ -1019,3 +1019,14 @@ func (p *prettyErrorFormatter) printf(style lipgloss.Style, format string, a ...
10191019
),
10201020
)
10211021
}
1022+
1023+
//nolint:unused
1024+
func SlimUnsupported(w io.Writer, cmd string) {
1025+
_, _ = fmt.Fprintf(w, "You are using a 'slim' build of Coder, which does not support the %s subcommand.\n", cliui.DefaultStyles.Code.Render(cmd))
1026+
_, _ = fmt.Fprintln(w, "")
1027+
_, _ = fmt.Fprintln(w, "Please use a build of Coder from GitHub releases:")
1028+
_, _ = fmt.Fprintln(w, " https://github.com/coder/coder/releases")
1029+
1030+
//nolint:revive
1031+
os.Exit(1)
1032+
}

cli/server_slim.go

+1-14
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
package cli
44

55
import (
6-
"fmt"
7-
"io"
8-
"os"
9-
106
"github.com/coder/coder/v2/cli/clibase"
11-
"github.com/coder/coder/v2/cli/cliui"
127
)
138

149
func (r *RootCmd) Server(_ func()) *clibase.Cmd {
@@ -19,18 +14,10 @@ func (r *RootCmd) Server(_ func()) *clibase.Cmd {
1914
RawArgs: true,
2015
Hidden: true,
2116
Handler: func(inv *clibase.Invocation) error {
22-
serverUnsupported(inv.Stderr)
17+
SlimUnsupported(inv.Stderr, "server")
2318
return nil
2419
},
2520
}
2621

2722
return root
2823
}
29-
30-
func serverUnsupported(w io.Writer) {
31-
_, _ = fmt.Fprintf(w, "You are using a 'slim' build of Coder, which does not support the %s subcommand.\n", cliui.DefaultStyles.Code.Render("server"))
32-
_, _ = fmt.Fprintln(w, "")
33-
_, _ = fmt.Fprintln(w, "Please use a build of Coder from GitHub releases:")
34-
_, _ = fmt.Fprintln(w, " https://github.com/coder/coder/releases")
35-
os.Exit(1)
36-
}

enterprise/cli/provisionerdaemons_slim.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cli
44

55
import (
6+
agplcli "github.com/coder/coder/v2/cli"
67
"github.com/coder/coder/v2/cli/clibase"
78
)
89

@@ -14,7 +15,7 @@ func (r *RootCmd) provisionerDaemons() *clibase.Cmd {
1415
RawArgs: true,
1516
Hidden: true,
1617
Handler: func(inv *clibase.Invocation) error {
17-
slimUnsupported(inv.Stderr, "coder provisionerd")
18+
agplcli.SlimUnsupported(inv.Stderr, "provisionerd")
1819
return nil
1920
},
2021
}

enterprise/cli/proxyserver_slim.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package cli
44

55
import (
6+
agplcli "github.com/coder/coder/v2/cli"
67
"github.com/coder/coder/v2/cli/clibase"
78
)
89

@@ -15,7 +16,7 @@ func (r *RootCmd) proxyServer() *clibase.Cmd {
1516
RawArgs: true,
1617
Hidden: true,
1718
Handler: func(inv *clibase.Invocation) error {
18-
slimUnsupported(inv.Stderr, "workspace-proxy server")
19+
agplcli.SlimUnsupported(inv.Stderr, "workspace-proxy server")
1920
return nil
2021
},
2122
}

enterprise/cli/root.go

-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
package cli
22

33
import (
4-
"fmt"
5-
"io"
6-
"os"
7-
84
"github.com/coder/coder/v2/cli"
95
"github.com/coder/coder/v2/cli/clibase"
10-
"github.com/coder/coder/v2/cli/cliui"
116
)
127

138
type RootCmd struct {
@@ -29,14 +24,3 @@ func (r *RootCmd) EnterpriseSubcommands() []*clibase.Cmd {
2924
all := append(r.Core(), r.enterpriseOnly()...)
3025
return all
3126
}
32-
33-
//nolint:unused
34-
func slimUnsupported(w io.Writer, cmd string) {
35-
_, _ = fmt.Fprintf(w, "You are using a 'slim' build of Coder, which does not support the %s subcommand.\n", cliui.DefaultStyles.Code.Render(cmd))
36-
_, _ = fmt.Fprintln(w, "")
37-
_, _ = fmt.Fprintln(w, "Please use a build of Coder from GitHub releases:")
38-
_, _ = fmt.Fprintln(w, " https://github.com/coder/coder/releases")
39-
40-
//nolint:revive
41-
os.Exit(1)
42-
}

0 commit comments

Comments
 (0)