mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
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
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
//go:build !slim
|
||||
|
||||
package cli
|
||||
|
||||
import (
|
||||
|
||||
@@ -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 <username>",
|
||||
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
|
||||
}
|
||||
+11
@@ -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)
|
||||
}
|
||||
|
||||
+1
-14
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user