- Notifications
You must be signed in to change notification settings - Fork928
feat: Add config-ssh command#735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions.vscode/settings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"cSpell.words": [ | ||
"cliflag", | ||
"cliui", | ||
"coderd", | ||
"coderdtest", | ||
91 changes: 41 additions & 50 deletionsagent/agent.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletionsagent/conn.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletionagent/usershell/usershell_other.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
21 changes: 11 additions & 10 deletionscli/cliui/agent.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3,11 +3,11 @@ package cliui | ||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"sync" | ||
"time" | ||
"github.com/briandowns/spinner" | ||
"golang.org/x/xerrors" | ||
"github.com/coder/coder/codersdk" | ||
@@ -21,15 +21,15 @@ type AgentOptions struct { | ||
} | ||
// Agent displays a spinning indicator that waits for a workspace agent to connect. | ||
func Agent(ctx context.Context, writer io.Writer, opts AgentOptions) error { | ||
kylecarbs marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if opts.FetchInterval == 0 { | ||
opts.FetchInterval = 500 * time.Millisecond | ||
} | ||
if opts.WarnInterval == 0 { | ||
opts.WarnInterval = 30 * time.Second | ||
} | ||
var resourceMutex sync.Mutex | ||
resource, err := opts.Fetch(ctx) | ||
if err != nil { | ||
return xerrors.Errorf("fetch: %w", err) | ||
} | ||
@@ -40,7 +40,8 @@ func Agent(cmd *cobra.Command, opts AgentOptions) error { | ||
opts.WarnInterval = 0 | ||
} | ||
spin := spinner.New(spinner.CharSets[78], 100*time.Millisecond, spinner.WithColor("fgHiGreen")) | ||
spin.Writer = writer | ||
spin.ForceOutput = true | ||
spin.Suffix = " Waiting for connection from " + Styles.Field.Render(resource.Type+"."+resource.Name) + "..." | ||
spin.Start() | ||
defer spin.Stop() | ||
@@ -51,7 +52,7 @@ func Agent(cmd *cobra.Command, opts AgentOptions) error { | ||
defer timer.Stop() | ||
go func() { | ||
select { | ||
case <-ctx.Done(): | ||
return | ||
case <-timer.C: | ||
} | ||
@@ -63,17 +64,17 @@ func Agent(cmd *cobra.Command, opts AgentOptions) error { | ||
} | ||
// This saves the cursor position, then defers clearing from the cursor | ||
// position to the end of the screen. | ||
_, _ = fmt.Fprintf(writer, "\033[s\r\033[2K%s\n\n", Styles.Paragraph.Render(Styles.Prompt.String()+message)) | ||
defer fmt.Fprintf(writer, "\033[u\033[J") | ||
}() | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
returnctx.Err() | ||
case <-ticker.C: | ||
} | ||
resourceMutex.Lock() | ||
resource, err = opts.Fetch(ctx) | ||
if err != nil { | ||
return xerrors.Errorf("fetch: %w", err) | ||
} | ||
2 changes: 1 addition & 1 deletioncli/cliui/agent_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletionscli/cliui/log.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cliui | ||
import ( | ||
"fmt" | ||
"io" | ||
"strings" | ||
"github.com/charmbracelet/lipgloss" | ||
) | ||
// cliMessage provides a human-readable message for CLI errors and messages. | ||
type cliMessage struct { | ||
Level string | ||
Style lipgloss.Style | ||
Header string | ||
Lines []string | ||
} | ||
// String formats the CLI message for consumption by a human. | ||
func (m cliMessage) String() string { | ||
var str strings.Builder | ||
_, _ = fmt.Fprintf(&str, "%s\r\n", | ||
Styles.Bold.Render(m.Header)) | ||
for _, line := range m.Lines { | ||
_, _ = fmt.Fprintf(&str, " %s %s\r\n", m.Style.Render("|"), line) | ||
} | ||
return str.String() | ||
} | ||
// Warn writes a log to the writer provided. | ||
func Warn(wtr io.Writer, header string, lines ...string) { | ||
_, _ = fmt.Fprint(wtr, cliMessage{ | ||
Level: "warning", | ||
Style: Styles.Warn, | ||
Header: header, | ||
Lines: lines, | ||
}.String()) | ||
} |
7 changes: 6 additions & 1 deletioncli/cliui/prompt.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 1 addition & 3 deletionscli/cliui/prompt_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.