mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
bddb808b25
Fixes all our Go file imports to match the preferred spec that we've _mostly_ been using. For example: ``` import ( "context" "time" "github.com/prometheus/client_golang/prometheus" "golang.org/x/xerrors" "gopkg.in/natefinch/lumberjack.v2" "cdr.dev/slog/v3" "github.com/coder/coder/v2/codersdk/agentsdk" "github.com/coder/serpent" ) ``` 3 groups: standard library, 3rd partly libs, Coder libs. This PR makes the change across the codebase. The PR in the stack above modifies our formatting to maintain this state of affairs, and is a separate PR so it's possible to review that one in detail.
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package cli
|
|
|
|
import (
|
|
"github.com/coder/coder/v2/codersdk/workspacesdk"
|
|
"github.com/coder/serpent"
|
|
)
|
|
|
|
func (r *RootCmd) connectCmd() *serpent.Command {
|
|
cmd := &serpent.Command{
|
|
Use: "connect",
|
|
Short: "Commands related to Coder Connect (OS-level tunneled connection to workspaces).",
|
|
Handler: func(i *serpent.Invocation) error {
|
|
return i.Command.HelpHandler(i)
|
|
},
|
|
Hidden: true,
|
|
Children: []*serpent.Command{
|
|
r.existsCmd(),
|
|
},
|
|
}
|
|
return cmd
|
|
}
|
|
|
|
func (*RootCmd) existsCmd() *serpent.Command {
|
|
cmd := &serpent.Command{
|
|
Use: "exists <hostname>",
|
|
Short: "Checks if the given hostname exists via Coder Connect.",
|
|
Long: "This command is designed to be used in scripts to check if the given hostname exists via Coder " +
|
|
"Connect. It prints no output. It returns exit code 0 if it does exist and code 1 if it does not.",
|
|
Middleware: serpent.Chain(
|
|
serpent.RequireNArgs(1),
|
|
),
|
|
Handler: func(inv *serpent.Invocation) error {
|
|
hostname := inv.Args[0]
|
|
exists, err := workspacesdk.ExistsViaCoderConnect(inv.Context(), hostname)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !exists {
|
|
// we don't want to print any output, since this command is designed to be a check in scripts / SSH config.
|
|
return ErrSilent
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
return cmd
|
|
}
|