Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit31856cf

Browse files
committed
359 problems left...
Started refactoring production code too 🥴
1 parente7ced4c commit31856cf

File tree

74 files changed

+582
-553
lines changed

Some content is hidden

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

74 files changed

+582
-553
lines changed

‎cli/agent.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"time"
1616

1717
"cloud.google.com/go/compute/metadata"
18-
"github.com/spf13/cobra"
1918
"golang.org/x/xerrors"
2019
"gopkg.in/natefinch/lumberjack.v2"
2120

@@ -24,23 +23,24 @@ import (
2423
"github.com/coder/coder/agent"
2524
"github.com/coder/coder/agent/reaper"
2625
"github.com/coder/coder/buildinfo"
26+
"github.com/coder/coder/cli/clibase"
2727
"github.com/coder/coder/cli/cliflag"
2828
"github.com/coder/coder/codersdk/agentsdk"
2929
)
3030

31-
funcworkspaceAgent()*cobra.Command {
31+
funcworkspaceAgent()*clibase.Command {
3232
var (
3333
authstring
3434
logDirstring
3535
pprofAddressstring
3636
noReapbool
3737
)
38-
cmd:=&cobra.Command{
38+
cmd:=&clibase.Command{
3939
Use:"agent",
4040
// This command isn't useful to manually execute.
4141
Hidden:true,
42-
RunE:func(cmd*cobra.Command,_ []string)error {
43-
ctx,cancel:=context.WithCancel(cmd.Context())
42+
Handler:func(inv*clibase.Invokation)error {
43+
ctx,cancel:=context.WithCancel(inv.Context())
4444
defercancel()
4545

4646
rawURL,err:=cmd.Flags().GetString(varAgentURL)
@@ -62,7 +62,7 @@ func workspaceAgent() *cobra.Command {
6262
MaxSize:5,// MB
6363
}
6464
deferlogWriter.Close()
65-
logger:=slog.Make(sloghuman.Sink(cmd.ErrOrStderr()),sloghuman.Sink(logWriter)).Leveled(slog.LevelDebug)
65+
logger:=slog.Make(sloghuman.Sink(inv.Stderr),sloghuman.Sink(logWriter)).Leveled(slog.LevelDebug)
6666

6767
logger.Info(ctx,"spawning reaper process")
6868
// Do not start a reaper on the child process. It's important
@@ -104,7 +104,7 @@ func workspaceAgent() *cobra.Command {
104104
logWriter:=&closeWriter{w:ljLogger}
105105
deferlogWriter.Close()
106106

107-
logger:=slog.Make(sloghuman.Sink(cmd.ErrOrStderr()),sloghuman.Sink(logWriter)).Leveled(slog.LevelDebug)
107+
logger:=slog.Make(sloghuman.Sink(inv.Stderr),sloghuman.Sink(logWriter)).Leveled(slog.LevelDebug)
108108

109109
version:=buildinfo.Version()
110110
logger.Info(ctx,"starting agent",

‎cli/cliflag/cliflag.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ import (
1616
"strings"
1717
"time"
1818

19-
"github.com/spf13/cobra"
2019
"github.com/spf13/pflag"
2120

21+
"github.com/coder/coder/cli/clibase"
2222
"github.com/coder/coder/cli/cliui"
2323
)
2424

2525
// IsSetBool returns the value of the boolean flag if it is set.
2626
// It returns false if the flag isn't set or if any error occurs attempting
2727
// to parse the value of the flag.
28-
funcIsSetBool(cmd*cobra.Command,namestring)bool {
28+
funcIsSetBool(cmd*clibase.Command,namestring)bool {
2929
val,ok:=IsSet(cmd,name)
3030
if!ok {
3131
returnfalse
@@ -36,7 +36,7 @@ func IsSetBool(cmd *cobra.Command, name string) bool {
3636
}
3737

3838
// IsSet returns the string value of the flag and whether it was set.
39-
funcIsSet(cmd*cobra.Command,namestring) (string,bool) {
39+
funcIsSet(cmd*clibase.Command,namestring) (string,bool) {
4040
flag:=cmd.Flag(name)
4141
ifflag==nil {
4242
return"",false

‎cli/cliui/agent_test.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"testing"
66
"time"
77

8-
"github.com/spf13/cobra"
98
"github.com/stretchr/testify/assert"
109
"github.com/stretchr/testify/require"
1110
"go.uber.org/atomic"
@@ -67,9 +66,9 @@ func TestAgent_TimeoutWithTroubleshootingURL(t *testing.T) {
6766
wantURL:="https://coder.com/troubleshoot"
6867

6968
varconnected,timeout atomic.Bool
70-
cmd:=&cobra.Command{
71-
RunE:func(cmd*cobra.Command,_ []string)error {
72-
err:=cliui.Agent(cmd.Context(),cmd.OutOrStdout(), cliui.AgentOptions{
69+
cmd:=&clibase.Command{
70+
Handler:func(inv*clibase.Invokation)error {
71+
err:=cliui.Agent(inv.Context(),cmd.OutOrStdout(), cliui.AgentOptions{
7372
WorkspaceName:"example",
7473
Fetch:func(_ context.Context) (codersdk.WorkspaceAgent,error) {
7574
agent:= codersdk.WorkspaceAgent{
@@ -116,9 +115,9 @@ func TestAgent_StartupTimeout(t *testing.T) {
116115
varstatus,state atomic.String
117116
setStatus:=func(s codersdk.WorkspaceAgentStatus) {status.Store(string(s)) }
118117
setState:=func(s codersdk.WorkspaceAgentLifecycle) {state.Store(string(s)) }
119-
cmd:=&cobra.Command{
120-
RunE:func(cmd*cobra.Command,_ []string)error {
121-
err:=cliui.Agent(cmd.Context(),cmd.OutOrStdout(), cliui.AgentOptions{
118+
cmd:=&clibase.Command{
119+
Handler:func(inv*clibase.Invokation)error {
120+
err:=cliui.Agent(inv.Context(),cmd.OutOrStdout(), cliui.AgentOptions{
122121
WorkspaceName:"example",
123122
Fetch:func(_ context.Context) (codersdk.WorkspaceAgent,error) {
124123
agent:= codersdk.WorkspaceAgent{
@@ -174,9 +173,9 @@ func TestAgent_StartErrorExit(t *testing.T) {
174173
varstatus,state atomic.String
175174
setStatus:=func(s codersdk.WorkspaceAgentStatus) {status.Store(string(s)) }
176175
setState:=func(s codersdk.WorkspaceAgentLifecycle) {state.Store(string(s)) }
177-
cmd:=&cobra.Command{
178-
RunE:func(cmd*cobra.Command,_ []string)error {
179-
err:=cliui.Agent(cmd.Context(),cmd.OutOrStdout(), cliui.AgentOptions{
176+
cmd:=&clibase.Command{
177+
Handler:func(inv*clibase.Invokation)error {
178+
err:=cliui.Agent(inv.Context(),cmd.OutOrStdout(), cliui.AgentOptions{
180179
WorkspaceName:"example",
181180
Fetch:func(_ context.Context) (codersdk.WorkspaceAgent,error) {
182181
agent:= codersdk.WorkspaceAgent{
@@ -229,9 +228,9 @@ func TestAgent_NoWait(t *testing.T) {
229228
varstatus,state atomic.String
230229
setStatus:=func(s codersdk.WorkspaceAgentStatus) {status.Store(string(s)) }
231230
setState:=func(s codersdk.WorkspaceAgentLifecycle) {state.Store(string(s)) }
232-
cmd:=&cobra.Command{
233-
RunE:func(cmd*cobra.Command,_ []string)error {
234-
err:=cliui.Agent(cmd.Context(),cmd.OutOrStdout(), cliui.AgentOptions{
231+
cmd:=&clibase.Command{
232+
Handler:func(inv*clibase.Invokation)error {
233+
err:=cliui.Agent(inv.Context(),cmd.OutOrStdout(), cliui.AgentOptions{
235234
WorkspaceName:"example",
236235
Fetch:func(_ context.Context) (codersdk.WorkspaceAgent,error) {
237236
agent:= codersdk.WorkspaceAgent{
@@ -298,9 +297,9 @@ func TestAgent_LoginBeforeReadyEnabled(t *testing.T) {
298297
varstatus,state atomic.String
299298
setStatus:=func(s codersdk.WorkspaceAgentStatus) {status.Store(string(s)) }
300299
setState:=func(s codersdk.WorkspaceAgentLifecycle) {state.Store(string(s)) }
301-
cmd:=&cobra.Command{
302-
RunE:func(cmd*cobra.Command,_ []string)error {
303-
err:=cliui.Agent(cmd.Context(),cmd.OutOrStdout(), cliui.AgentOptions{
300+
cmd:=&clibase.Command{
301+
Handler:func(inv*clibase.Invokation)error {
302+
err:=cliui.Agent(inv.Context(),cmd.OutOrStdout(), cliui.AgentOptions{
304303
WorkspaceName:"example",
305304
Fetch:func(_ context.Context) (codersdk.WorkspaceAgent,error) {
306305
agent:= codersdk.WorkspaceAgent{

‎cli/cliui/gitauth_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/spf13/cobra"
1110
"github.com/stretchr/testify/assert"
1211

12+
"github.com/coder/coder/cli/clibase"
1313
"github.com/coder/coder/cli/cliui"
1414
"github.com/coder/coder/codersdk"
1515
"github.com/coder/coder/pty/ptytest"
@@ -23,10 +23,10 @@ func TestGitAuth(t *testing.T) {
2323
defercancel()
2424

2525
ptty:=ptytest.New(t)
26-
cmd:=&cobra.Command{
27-
RunE:func(cmd*cobra.Command,args []string)error {
26+
cmd:=&clibase.Command{
27+
Handler:func(inv*clibase.Invokation)error {
2828
varfetched atomic.Bool
29-
returncliui.GitAuth(cmd.Context(),cmd.OutOrStdout(), cliui.GitAuthOptions{
29+
returncliui.GitAuth(inv.Context(),cmd.OutOrStdout(), cliui.GitAuthOptions{
3030
Fetch:func(ctx context.Context) ([]codersdk.TemplateVersionGitAuth,error) {
3131
deferfetched.Store(true)
3232
return []codersdk.TemplateVersionGitAuth{{

‎cli/cliui/output.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66
"reflect"
77
"strings"
88

9-
"github.com/spf13/cobra"
9+
"github.com/coder/coder/cli/clibase"
1010
"golang.org/x/xerrors"
1111
)
1212

1313
typeOutputFormatinterface {
1414
ID()string
15-
AttachFlags(cmd*cobra.Command)
15+
AttachFlags(cmd*clibase.Command)
1616
Format(ctx context.Context,dataany) (string,error)
1717
}
1818

@@ -47,7 +47,7 @@ func NewOutputFormatter(formats ...OutputFormat) *OutputFormatter {
4747

4848
// AttachFlags attaches the --output flag to the given command, and any
4949
// additional flags required by the output formatters.
50-
func (f*OutputFormatter)AttachFlags(cmd*cobra.Command) {
50+
func (f*OutputFormatter)AttachFlags(cmd*clibase.Command) {
5151
for_,format:=rangef.formats {
5252
format.AttachFlags(cmd)
5353
}
@@ -119,7 +119,7 @@ func (*tableFormat) ID() string {
119119
}
120120

121121
// AttachFlags implements OutputFormat.
122-
func (f*tableFormat)AttachFlags(cmd*cobra.Command) {
122+
func (f*tableFormat)AttachFlags(cmd*clibase.Command) {
123123
cmd.Flags().StringSliceVarP(&f.columns,"column","c",f.defaultColumns,"Columns to display in table output. Available columns: "+strings.Join(f.allColumns,", "))
124124
}
125125

@@ -143,7 +143,7 @@ func (jsonFormat) ID() string {
143143
}
144144

145145
// AttachFlags implements OutputFormat.
146-
func (jsonFormat)AttachFlags(_*cobra.Command) {}
146+
func (jsonFormat)AttachFlags(_*clibase.Command) {}
147147

148148
// Format implements OutputFormat.
149149
func (jsonFormat)Format(_ context.Context,dataany) (string,error) {

‎cli/cliui/output_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import (
66
"sync/atomic"
77
"testing"
88

9-
"github.com/spf13/cobra"
109
"github.com/stretchr/testify/require"
1110

11+
"github.com/coder/coder/cli/clibase"
1212
"github.com/coder/coder/cli/cliui"
1313
)
1414

1515
typeformatstruct {
1616
idstring
17-
attachFlagsFnfunc(cmd*cobra.Command)
17+
attachFlagsFnfunc(cmd*clibase.Command)
1818
formatFnfunc(ctx context.Context,dataany) (string,error)
1919
}
2020

@@ -24,7 +24,7 @@ func (f *format) ID() string {
2424
returnf.id
2525
}
2626

27-
func (f*format)AttachFlags(cmd*cobra.Command) {
27+
func (f*format)AttachFlags(cmd*clibase.Command) {
2828
iff.attachFlagsFn!=nil {
2929
f.attachFlagsFn(cmd)
3030
}
@@ -82,7 +82,7 @@ func Test_OutputFormatter(t *testing.T) {
8282
cliui.JSONFormat(),
8383
&format{
8484
id:"foo",
85-
attachFlagsFn:func(cmd*cobra.Command) {
85+
attachFlagsFn:func(cmd*clibase.Command) {
8686
cmd.Flags().StringP("foo","f","","foo flag 1234")
8787
},
8888
formatFn:func(_ context.Context,_any) (string,error) {
@@ -92,7 +92,7 @@ func Test_OutputFormatter(t *testing.T) {
9292
},
9393
)
9494

95-
cmd:=&cobra.Command{}
95+
cmd:=&clibase.Command{}
9696
f.AttachFlags(cmd)
9797

9898
selected,err:=cmd.Flags().GetString("output")

‎cli/cliui/parameter.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import (
44
"fmt"
55
"strings"
66

7-
"github.com/spf13/cobra"
8-
7+
"github.com/coder/coder/cli/clibase"
98
"github.com/coder/coder/coderd/parameter"
109
"github.com/coder/coder/codersdk"
1110
)
1211

13-
funcParameterSchema(cmd*cobra.Command,parameterSchema codersdk.ParameterSchema) (string,error) {
12+
funcParameterSchema(cmd*clibase.Command,parameterSchema codersdk.ParameterSchema) (string,error) {
1413
_,_=fmt.Fprintln(cmd.OutOrStdout(),Styles.Bold.Render("var."+parameterSchema.Name))
1514
ifparameterSchema.Description!="" {
1615
_,_=fmt.Fprintln(cmd.OutOrStdout()," "+strings.TrimSpace(strings.Join(strings.Split(parameterSchema.Description,"\n"),"\n "))+"\n")
@@ -61,7 +60,7 @@ func ParameterSchema(cmd *cobra.Command, parameterSchema codersdk.ParameterSchem
6160
returnvalue,nil
6261
}
6362

64-
funcRichParameter(cmd*cobra.Command,templateVersionParameter codersdk.TemplateVersionParameter) (string,error) {
63+
funcRichParameter(cmd*clibase.Command,templateVersionParameter codersdk.TemplateVersionParameter) (string,error) {
6564
_,_=fmt.Fprintln(cmd.OutOrStdout(),Styles.Bold.Render(templateVersionParameter.Name))
6665
iftemplateVersionParameter.DescriptionPlaintext!="" {
6766
_,_=fmt.Fprintln(cmd.OutOrStdout()," "+strings.TrimSpace(strings.Join(strings.Split(templateVersionParameter.DescriptionPlaintext,"\n"),"\n "))+"\n")

‎cli/cliui/prompt.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import (
1010
"strings"
1111

1212
"github.com/bgentry/speakeasy"
13+
"github.com/coder/coder/cli/clibase"
1314
"github.com/mattn/go-isatty"
14-
"github.com/spf13/cobra"
1515
"golang.org/x/xerrors"
1616
)
1717

@@ -26,7 +26,7 @@ type PromptOptions struct {
2626

2727
constskipPromptFlag="yes"
2828

29-
funcAllowSkipPrompt(cmd*cobra.Command) {
29+
funcAllowSkipPrompt(cmd*clibase.Command) {
3030
cmd.Flags().BoolP(skipPromptFlag,"y",false,"Bypass prompts")
3131
}
3232

@@ -36,7 +36,7 @@ const (
3636
)
3737

3838
// Prompt asks the user for input.
39-
funcPrompt(cmd*cobra.Command,optsPromptOptions) (string,error) {
39+
funcPrompt(cmd*clibase.Command,optsPromptOptions) (string,error) {
4040
// If the cmd has a "yes" flag for skipping confirm prompts, honor it.
4141
// If it's not a "Confirm" prompt, then don't skip. As the default value of
4242
// "yes" makes no sense.
@@ -114,8 +114,8 @@ func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error) {
114114
}
115115
}
116116
returnline,nil
117-
case<-cmd.Context().Done():
118-
return"",cmd.Context().Err()
117+
case<-inv.Context().Done():
118+
return"",inv.Context().Err()
119119
case<-interrupt:
120120
// Print a newline so that any further output starts properly on a new line.
121121
_,_=fmt.Fprintln(cmd.OutOrStdout())

‎cli/cliui/prompt_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"os/exec"
99
"testing"
1010

11-
"github.com/spf13/cobra"
1211
"github.com/stretchr/testify/assert"
1312
"github.com/stretchr/testify/require"
1413

14+
"github.com/coder/coder/cli/clibase"
1515
"github.com/coder/coder/cli/cliui"
1616
"github.com/coder/coder/pty"
1717
"github.com/coder/coder/pty/ptytest"
@@ -77,7 +77,7 @@ func TestPrompt(t *testing.T) {
7777
resp,err:=newPrompt(ptty, cliui.PromptOptions{
7878
Text:"ShouldNotSeeThis",
7979
IsConfirm:true,
80-
},func(cmd*cobra.Command) {
80+
},func(cmd*clibase.Command) {
8181
cliui.AllowSkipPrompt(cmd)
8282
cmd.SetArgs([]string{"-y"})
8383
})
@@ -145,10 +145,10 @@ func TestPrompt(t *testing.T) {
145145
})
146146
}
147147

148-
funcnewPrompt(ptty*ptytest.PTY,opts cliui.PromptOptions,cmdOptfunc(cmd*cobra.Command)) (string,error) {
148+
funcnewPrompt(ptty*ptytest.PTY,opts cliui.PromptOptions,cmdOptfunc(cmd*clibase.Command)) (string,error) {
149149
value:=""
150-
cmd:=&cobra.Command{
151-
RunE:func(cmd*cobra.Command,args []string)error {
150+
cmd:=&clibase.Command{
151+
Handler:func(inv*clibase.Invokation)error {
152152
varerrerror
153153
value,err=cliui.Prompt(cmd,opts)
154154
returnerr
@@ -208,8 +208,8 @@ func TestPasswordTerminalState(t *testing.T) {
208208

209209
// nolint:unused
210210
funcpasswordHelper() {
211-
cmd:=&cobra.Command{
212-
Run:func(cmd*cobra.Command,args []string) {
211+
cmd:=&clibase.Command{
212+
Run:func(inv*clibase.Invokation) {
213213
cliui.Prompt(cmd, cliui.PromptOptions{
214214
Text:"Password:",
215215
Secret:true,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp