mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: refactor to directly create Client in Command Handlers (#19760)
Refactors the CLI to create the `*codersdk.Client` in the handlers. This is groundwork for changing the `rootCmd.InitClient()` to use the new `ClientOption`s. It also improves variable locality, scoping the Client to the handler. This makes misuse less likely and reduces the memory allocations to just the command being executed, rather than allocating a Client for every command regardless of whether it is executed.
This commit is contained in:
+7
-5
@@ -79,15 +79,12 @@ func (r *RootCmd) ssh() *serpent.Command {
|
||||
env []string
|
||||
usageApp string
|
||||
disableAutostart bool
|
||||
appearanceConfig codersdk.AppearanceConfig
|
||||
networkInfoDir string
|
||||
networkInfoInterval time.Duration
|
||||
|
||||
containerName string
|
||||
containerUser string
|
||||
)
|
||||
client := new(codersdk.Client)
|
||||
wsClient := workspacesdk.New(client)
|
||||
cmd := &serpent.Command{
|
||||
Annotations: workspaceCommand,
|
||||
Use: "ssh <workspace> [command]",
|
||||
@@ -111,10 +108,15 @@ func (r *RootCmd) ssh() *serpent.Command {
|
||||
return next(i)
|
||||
}
|
||||
},
|
||||
r.InitClient(client),
|
||||
initAppearance(client, &appearanceConfig),
|
||||
),
|
||||
Handler: func(inv *serpent.Invocation) (retErr error) {
|
||||
client, err := r.InitClient(inv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
appearanceConfig := initAppearance(inv.Context(), client)
|
||||
wsClient := workspacesdk.New(client)
|
||||
|
||||
command := strings.Join(inv.Args[1:], " ")
|
||||
|
||||
// Before dialing the SSH server over TCP, capture Interrupt signals
|
||||
|
||||
Reference in New Issue
Block a user