Skip to content

Commit 180a9ac

Browse files
feat: add --quiet flag to coder ssh command
Adds a --quiet (-q) flag to suppress machine setup logs and connection indicators when connecting to workspaces via SSH. This provides a cleaner SSH experience for users who don't want to see the startup logs. Changes: - Add Quiet field to AgentOptions struct - Modify Agent() function to skip logging in quiet mode - Add --quiet flag with -q shorthand to SSH command - Support CODER_SSH_QUIET environment variable Co-authored-by: kylecarbs <7122116+kylecarbs@users.noreply.github.com>
1 parent 52c4b61 commit 180a9ac

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

cli/cliui/agent.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type AgentOptions struct {
2525
Fetch func(ctx context.Context, agentID uuid.UUID) (codersdk.WorkspaceAgent, error)
2626
FetchLogs func(ctx context.Context, agentID uuid.UUID, after int64, follow bool) (<-chan []codersdk.WorkspaceAgentLog, io.Closer, error)
2727
Wait bool // If true, wait for the agent to be ready (startup script).
28+
Quiet bool // If true, suppress startup logs and connection indicators.
2829
DocsURL string
2930
}
3031

@@ -103,6 +104,18 @@ func Agent(ctx context.Context, writer io.Writer, agentID uuid.UUID, opts AgentO
103104
return errAgentShuttingDown
104105
}
105106

107+
// In quiet mode, skip all logging and just wait for ready state
108+
if opts.Quiet {
109+
if agent.Status == codersdk.WorkspaceAgentConnected && agent.LifecycleState == codersdk.WorkspaceAgentLifecycleReady {
110+
return nil
111+
}
112+
// Just fetch the next state without showing any output
113+
if agent, err = fetch(); err != nil {
114+
return xerrors.Errorf("fetch: %w", err)
115+
}
116+
continue
117+
}
118+
106119
switch agent.Status {
107120
case codersdk.WorkspaceAgentConnecting, codersdk.WorkspaceAgentTimeout:
108121
// Since we were waiting for the agent to connect, also show

cli/ssh.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func (r *RootCmd) ssh() *serpent.Command {
7474
wsPollInterval time.Duration
7575
waitEnum string
7676
noWait bool
77+
quiet bool
7778
logDirPath string
7879
remoteForwards []string
7980
env []string
@@ -288,6 +289,7 @@ func (r *RootCmd) ssh() *serpent.Command {
288289
Fetch: client.WorkspaceAgent,
289290
FetchLogs: client.WorkspaceAgentLogsAfter,
290291
Wait: wait,
292+
Quiet: quiet,
291293
DocsURL: appearanceConfig.DocsURL,
292294
})
293295
if err != nil {
@@ -670,6 +672,13 @@ func (r *RootCmd) ssh() *serpent.Command {
670672
Value: serpent.BoolOf(&noWait),
671673
UseInstead: []serpent.Option{waitOption},
672674
},
675+
{
676+
Flag: "quiet",
677+
FlagShorthand: "q",
678+
Env: "CODER_SSH_QUIET",
679+
Description: "Suppress machine setup logs and connection indicators.",
680+
Value: serpent.BoolOf(&quiet),
681+
},
673682
{
674683
Flag: "log-dir",
675684
Description: "Specify the directory containing SSH diagnostic log files.",

0 commit comments

Comments
 (0)