Skip to content

refactor(cli)!: remove reset-password from slim binary #9520

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 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions cli/resetpassword.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !slim

package cli

import (
Expand Down
23 changes: 23 additions & 0 deletions cli/resetpassword_slim.go
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
15 changes: 1 addition & 14 deletions cli/server_slim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
3 changes: 2 additions & 1 deletion enterprise/cli/provisionerdaemons_slim.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package cli

import (
agplcli "github.com/coder/coder/v2/cli"
"github.com/coder/coder/v2/cli/clibase"
)

Expand All @@ -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
},
}
Expand Down
3 changes: 2 additions & 1 deletion enterprise/cli/proxyserver_slim.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package cli

import (
agplcli "github.com/coder/coder/v2/cli"
"github.com/coder/coder/v2/cli/clibase"
)

Expand All @@ -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
},
}
Expand Down
16 changes: 0 additions & 16 deletions enterprise/cli/root.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)
}