Skip to content

Commit 05aa7e3

Browse files
committed
PR fixes
1 parent 95967d9 commit 05aa7e3

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

cli/cliui/agent.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/coder/coder/codersdk"
1212
)
1313

14-
var AgentShuttingDown = xerrors.New("agent is shutting down")
14+
var errAgentShuttingDown = xerrors.New("agent is shutting down")
1515

1616
type AgentOptions struct {
1717
FetchInterval time.Duration
@@ -25,8 +25,12 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
2525
if opts.FetchInterval == 0 {
2626
opts.FetchInterval = 500 * time.Millisecond
2727
}
28-
if opts.Wait && opts.FetchLogs == nil {
29-
return xerrors.Errorf("fetch logs required when waiting for agent")
28+
if opts.FetchLogs == nil {
29+
opts.FetchLogs = func(_ context.Context, _ uuid.UUID, _ int64, _ bool) (<-chan []codersdk.WorkspaceAgentStartupLog, io.Closer, error) {
30+
c := make(chan []codersdk.WorkspaceAgentStartupLog)
31+
close(c)
32+
return c, closeFunc(func() error { return nil }), nil
33+
}
3034
}
3135

3236
type fetchAgent struct {
@@ -112,7 +116,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
112116
// It doesn't matter if we're connected or not, if the agent is
113117
// shutting down, we don't know if it's coming back.
114118
if agent.LifecycleState.ShuttingDown() {
115-
return AgentShuttingDown
119+
return errAgentShuttingDown
116120
}
117121

118122
switch agent.Status {
@@ -123,10 +127,6 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
123127
}
124128

125129
case codersdk.WorkspaceAgentConnected:
126-
if opts.FetchLogs == nil {
127-
// Only agent connection status was requested.
128-
return nil
129-
}
130130
if !showStartupLogs && agent.LifecycleState == codersdk.WorkspaceAgentLifecycleReady {
131131
// The workspace is ready, there's nothing to do but connect.
132132
return nil
@@ -209,7 +209,7 @@ func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error {
209209
// We no longer know if the startup script failed or not,
210210
// but we need to tell the user something.
211211
sw.Complete(stage, agent.ReadyAt.Sub(*agent.StartedAt))
212-
return AgentShuttingDown
212+
return errAgentShuttingDown
213213
}
214214
}
215215

0 commit comments

Comments
 (0)