Skip to content

Commit 6c0b64a

Browse files
committed
248 problems left...
* Start the enterprise
1 parent 6757d66 commit 6c0b64a

Some content is hidden

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

46 files changed

+258
-198
lines changed

cli/clibase/clibasetest/invokation.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ func TestWriter(t *testing.T, prefix string) io.Writer {
4545

4646
// Invoke creates a fake invokation and IO.
4747
func Invoke(cmd *clibase.Cmd, args ...string) (*clibase.Invokation, *IO) {
48-
i := clibase.Invokation{
49-
Args: args,
50-
Command: cmd,
51-
}
52-
return &i, FakeIO(&i)
48+
i := cmd.Invoke(args...)
49+
return i, FakeIO(i)
5350
}

cli/clibase/cmd.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ func (c *Cmd) FullUsage() string {
8282
return strings.Join(uses, " ")
8383
}
8484

85+
// Invoke creates a new invokation of the command, with
86+
// stdio discarded.
87+
//
88+
// The returned invokation is not live until Run() is called.
89+
func (c *Cmd) Invoke(args ...string) *Invokation {
90+
return &Invokation{
91+
Command: c,
92+
Args: args,
93+
Stdout: io.Discard,
94+
Stderr: io.Discard,
95+
Stdin: strings.NewReader(""),
96+
}
97+
}
98+
8599
// Invokation represents an instance of a command being executed.
86100
type Invokation struct {
87101
parent *Invokation

cli/cliui/agent_test.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ func TestAgent(t *testing.T) {
4545
},
4646
}
4747

48-
inv := (&clibase.Invokation{
49-
Command: cmd,
50-
})
48+
inv := cmd.Invoke()
5149
inv.Stdout = ptty.Output()
5250
inv.Stdin = ptty.Input()
5351
done := make(chan struct{})
@@ -96,9 +94,7 @@ func TestAgent_TimeoutWithTroubleshootingURL(t *testing.T) {
9694
}
9795
ptty := ptytest.New(t)
9896

99-
inv := (&clibase.Invokation{
100-
Command: cmd,
101-
})
97+
inv := cmd.Invoke()
10298
inv.Stdout = ptty.Output()
10399
inv.Stdin = ptty.Input()
104100
done := make(chan error, 1)
@@ -154,9 +150,7 @@ func TestAgent_StartupTimeout(t *testing.T) {
154150

155151
ptty := ptytest.New(t)
156152

157-
inv := (&clibase.Invokation{
158-
Command: cmd,
159-
})
153+
inv := cmd.Invoke()
160154
inv.Stdout = ptty.Output()
161155
inv.Stdin = ptty.Input()
162156
done := make(chan error, 1)
@@ -216,9 +210,7 @@ func TestAgent_StartErrorExit(t *testing.T) {
216210

217211
ptty := ptytest.New(t)
218212

219-
inv := (&clibase.Invokation{
220-
Command: cmd,
221-
})
213+
inv := cmd.Invoke()
222214
inv.Stdout = ptty.Output()
223215
inv.Stdin = ptty.Input()
224216
done := make(chan error, 1)
@@ -275,9 +267,7 @@ func TestAgent_NoWait(t *testing.T) {
275267

276268
ptty := ptytest.New(t)
277269

278-
inv := (&clibase.Invokation{
279-
Command: cmd,
280-
})
270+
inv := cmd.Invoke()
281271
inv.Stdout = ptty.Output()
282272
inv.Stdin = ptty.Input()
283273
done := make(chan error, 1)
@@ -346,9 +336,7 @@ func TestAgent_LoginBeforeReadyEnabled(t *testing.T) {
346336
},
347337
}
348338

349-
inv := (&clibase.Invokation{
350-
Command: cmd,
351-
})
339+
inv := cmd.Invoke()
352340

353341
ptty := ptytest.New(t)
354342
inv.Stdout = ptty.Output()

cli/cliui/gitauth_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ func TestGitAuth(t *testing.T) {
4141
},
4242
}
4343

44-
inv := (&clibase.Invokation{
45-
Command: cmd,
46-
}).WithContext(ctx)
44+
inv := cmd.Invoke().WithContext(ctx)
4745

4846
inv.Stdout = ptty.Output()
4947
inv.Stdin = ptty.Input()

cli/cliui/prompt_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ func newPrompt(ptty *ptytest.PTY, opts cliui.PromptOptions, invOpt func(inv *cli
156156
},
157157
}
158158

159-
inv := (&clibase.Invokation{
160-
Command: cmd,
161-
})
159+
inv := cmd.Invoke()
162160
// Optionally modify the cmd
163161
if invOpt != nil {
164162
invOpt(inv)

cli/cliui/provisionerjob_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,7 @@ func newProvisionerJob(t *testing.T) provisionerJobTest {
145145
})
146146
},
147147
}
148-
inv := (&clibase.Invokation{
149-
Command: cmd,
150-
})
148+
inv := cmd.Invoke()
151149

152150
ptty := ptytest.New(t)
153151
inv.Stdout = ptty.Output()

cli/configssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (r *RootCmd) configSSH() *clibase.Cmd {
156156
),
157157
Middleware: clibase.Chain(
158158
clibase.RequireNArgs(0),
159-
r.useClient(client),
159+
r.UseClient(client),
160160
),
161161
Handler: func(inv *clibase.Invokation) error {
162162
recvWorkspaceConfigs := sshPrepareWorkspaceConfigs(inv.Context(), client)

cli/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (r *RootCmd) create() *clibase.Cmd {
2929
Annotations: workspaceCommand,
3030
Use: "create [name]",
3131
Short: "Create a workspace",
32-
Middleware: clibase.Chain(r.useClient(client)),
32+
Middleware: clibase.Chain(r.UseClient(client)),
3333
Handler: func(inv *clibase.Invokation) error {
3434
organization, err := CurrentOrganization(inv, client)
3535
if err != nil {

cli/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (r *RootCmd) deleteWorkspace() *clibase.Cmd {
2020
Aliases: []string{"rm"},
2121
Middleware: clibase.Chain(
2222
clibase.RequireNArgs(1),
23-
r.useClient(client),
23+
r.UseClient(client),
2424
),
2525
Handler: func(inv *clibase.Invokation) error {
2626
_, err := cliui.Prompt(inv, cliui.PromptOptions{

cli/gitssh.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ import (
2020

2121
func (r *RootCmd) gitssh() *clibase.Cmd {
2222
cmd := &clibase.Cmd{
23-
Use: "gitssh",
24-
Hidden: true,
25-
Short: `Wraps the "ssh" command and uses the coder gitssh key for authentication`,
23+
Use: "gitssh",
24+
Hidden: true,
25+
RawArgs: true,
26+
Short: `Wraps the "ssh" command and uses the coder gitssh key for authentication`,
2627
Handler: func(inv *clibase.Invokation) error {
2728
ctx := inv.Context()
2829
env := os.Environ()
@@ -147,9 +148,9 @@ func parseIdentityFilesForHost(ctx context.Context, args, env []string) (identit
147148
args = append([]string{"-G"}, args...)
148149
cmd := exec.CommandContext(ctx, "ssh", args...)
149150
cmd.Env = append(cmd.Env, env...)
150-
inv.Stdout = &outBuf
151-
inv.Stderr = io.Discard
152-
err = inv.Run()
151+
cmd.Stdout = &outBuf
152+
cmd.Stderr = io.Discard
153+
err = cmd.Run()
153154
if err != nil {
154155
// If ssh -G failed, the SSH version is likely too old, fallback
155156
// to using the default identity files.

0 commit comments

Comments
 (0)