Skip to content

Commit 438a51d

Browse files
committed
621 problems remaining...
1 parent 274c84d commit 438a51d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+191
-237
lines changed

cli/agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/coder/coder/codersdk/agentsdk"
2929
)
3030

31-
func workspaceAgent() *clibase.Cmd {
31+
func (r *RootCmd) workspaceAgent() *clibase.Cmd {
3232
var (
3333
auth string
3434
logDir string

cli/clibase/cmd.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,5 +245,20 @@ func RequireNArgs(want int) MiddlewareFunc {
245245
}
246246
}
247247

248+
func RequireRangeArgs(start, end int) MiddlewareFunc {
249+
return func(next HandlerFunc) HandlerFunc {
250+
return func(i *Invokation) error {
251+
if len(i.Args) < start || len(i.Args) > end {
252+
return fmt.Errorf(
253+
"wanted between %v and %v args but got %v",
254+
start, end,
255+
len(i.Args),
256+
)
257+
}
258+
return next(i)
259+
}
260+
}
261+
}
262+
248263
// HandlerFunc handles an Invokation of a command.
249264
type HandlerFunc func(i *Invokation) error

cli/configssh.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,20 @@ func sshPrepareWorkspaceConfigs(ctx context.Context, client *codersdk.Client) (r
132132
}
133133
}
134134

135-
func configSSH() *clibase.Cmd {
135+
func (r *RootCmd) configSSH() *clibase.Cmd {
136136
var (
137137
sshConfigFile string
138138
sshConfigOpts sshConfigOptions
139139
usePreviousOpts bool
140140
dryRun bool
141141
skipProxyCommand bool
142142
)
143+
var client *codersdk.Client
143144
cmd := &clibase.Cmd{
144145
Annotations: workspaceCommand,
145146
Use: "config-ssh",
146147
Short: "Add an SSH Host entry for your workspaces \"ssh coder.workspace\"",
147-
Example: formatExamples(
148+
Long: formatExamples(
148149
example{
149150
Description: "You can use -o (or --ssh-option) so set SSH options to be used for all your workspaces",
150151
Command: "coder config-ssh -o ForwardAgent=yes",
@@ -154,13 +155,11 @@ func configSSH() *clibase.Cmd {
154155
Command: "coder config-ssh --dry-run",
155156
},
156157
),
157-
Middleware: clibase.RequireNArgs(0),
158+
Middleware: clibase.Chain(
159+
clibase.RequireNArgs(0),
160+
r.useClient(client),
161+
),
158162
Handler: func(inv *clibase.Invokation) error {
159-
client, err := useClient(cmd)
160-
if err != nil {
161-
return err
162-
}
163-
164163
recvWorkspaceConfigs := sshPrepareWorkspaceConfigs(inv.Context(), client)
165164

166165
out := inv.Stdout

cli/create.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/coder/coder/codersdk"
1717
)
1818

19-
func create() *clibase.Cmd {
19+
func (r *RootCmd) create() *clibase.Cmd {
2020
var (
2121
parameterFile string
2222
richParameterFile string
@@ -25,17 +25,14 @@ func create() *clibase.Cmd {
2525
stopAfter time.Duration
2626
workspaceName string
2727
)
28+
var client *codersdk.Client
2829
cmd := &clibase.Cmd{
2930
Annotations: workspaceCommand,
3031
Use: "create [name]",
3132
Short: "Create a workspace",
33+
Middleware: clibase.Chain(r.useClient(client)),
3234
Handler: func(inv *clibase.Invokation) error {
33-
client, err := useClient(cmd)
34-
if err != nil {
35-
return err
36-
}
37-
38-
organization, err := CurrentOrganization(cmd, client)
35+
organization, err := CurrentOrganization(inv, client)
3936
if err != nil {
4037
return err
4138
}
@@ -193,7 +190,7 @@ type buildParameters struct {
193190

194191
// prepWorkspaceBuild will ensure a workspace build will succeed on the latest template version.
195192
// Any missing params will be prompted to the user. It supports legacy and rich parameters.
196-
func prepWorkspaceBuild(cmd *clibase.Cmd, client *codersdk.Client, inv.Args prepWorkspaceBuildArgs) (*buildParameters, error) {
193+
func prepWorkspaceBuild(cmd *clibase.Cmd, client *codersdk.Client, args prepWorkspaceBuildArgs) (*buildParameters, error) {
197194
ctx := inv.Context()
198195

199196
var useRichParameters bool

cli/delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
// nolint
13-
func deleteWorkspace() *clibase.Cmd {
13+
func (r *RootCmd) deleteWorkspace() *clibase.Cmd {
1414
var orphan bool
1515
cmd := &clibase.Cmd{
1616
Annotations: workspaceCommand,
@@ -32,7 +32,7 @@ func deleteWorkspace() *clibase.Cmd {
3232
if err != nil {
3333
return err
3434
}
35-
workspace, err := namedWorkspace(cmd, client, inv.Args[0])
35+
workspace, err := namedWorkspace(inv.Context(), client, inv.Args[0])
3636
if err != nil {
3737
return err
3838
}

cli/dotfiles.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ import (
1717
"github.com/coder/coder/cli/cliui"
1818
)
1919

20-
func dotfiles() *clibase.Cmd {
20+
func (r *RootCmd) dotfiles() *clibase.Cmd {
2121
var symlinkDir string
2222
cmd := &clibase.Cmd{
2323
Use: "dotfiles [git_repo_url]",
2424
Middleware: clibase.RequireNArgs(1),
2525
Short: "Checkout and install a dotfiles repository from a Git URL",
26-
Example: formatExamples(
26+
Long: formatExamples(
2727
example{
2828
Description: "Check out and install a dotfiles repository without prompts",
2929
Command: "coder dotfiles --yes git@github.com:example/dotfiles.git",

cli/gitaskpass.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818

1919
// gitAskpass is used by the Coder agent to automatically authenticate
2020
// with Git providers based on a hostname.
21-
func gitAskpass() *clibase.Cmd {
21+
func (r *RootCmd) gitAskpass() *clibase.Cmd {
2222
return &clibase.Cmd{
2323
Use: "gitaskpass",
2424
Hidden: true,

cli/gitssh.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/coder/coder/cli/cliui"
1919
)
2020

21-
func gitssh() *clibase.Cmd {
21+
func (r *RootCmd) gitssh() *clibase.Cmd {
2222
cmd := &clibase.Cmd{
2323
Use: "gitssh",
2424
Hidden: true,
@@ -166,7 +166,7 @@ func parseIdentityFilesForHost(ctx context.Context, args, env []string) (identit
166166
// OpenSSH on Windows is weird, it supports using (and does
167167
// use) mixed \ and / in paths.
168168
//
169-
// Example: C:\Users\ZeroCool/.ssh/known_hosts
169+
// Long: C:\Users\ZeroCool/.ssh/known_hosts
170170
//
171171
// To check the file existence in Go, though, we want to use
172172
// proper Windows paths.

cli/list.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func workspaceListRowFromWorkspace(now time.Time, usersByID map[uuid.UUID]coders
6464
}
6565
}
6666

67-
func list() *clibase.Cmd {
67+
func (r *RootCmd) list() *clibase.Cmd {
6868
var (
6969
all bool
7070
defaultQuery = "owner:me"
@@ -81,12 +81,8 @@ func list() *clibase.Cmd {
8181
Short: "List workspaces",
8282
Aliases: []string{"ls"},
8383
Middleware: clibase.RequireNArgs(0),
84+
Middleware: clibase.Chain(r.useClient(client)),
8485
Handler: func(inv *clibase.Invokation) error {
85-
client, err := useClient(cmd)
86-
if err != nil {
87-
return err
88-
}
89-
9086
filter := codersdk.WorkspaceFilter{
9187
FilterQuery: searchQuery,
9288
}

cli/login.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func init() {
3939
browser.Stdout = io.Discard
4040
}
4141

42-
func login() *clibase.Cmd {
42+
func (r *RootCmd) login() *clibase.Cmd {
4343
const firstUserTrialEnv = "CODER_FIRST_USER_TRIAL"
4444

4545
var (

0 commit comments

Comments
 (0)