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:
@@ -16,7 +16,6 @@ import (
|
||||
func (r *RootCmd) taskCreate() *serpent.Command {
|
||||
var (
|
||||
orgContext = NewOrganizationContext()
|
||||
client = new(codersdk.Client)
|
||||
|
||||
templateName string
|
||||
templateVersionName string
|
||||
@@ -30,7 +29,6 @@ func (r *RootCmd) taskCreate() *serpent.Command {
|
||||
Short: "Create an experimental task",
|
||||
Middleware: serpent.Chain(
|
||||
serpent.RequireRangeArgs(0, 1),
|
||||
r.InitClient(client),
|
||||
),
|
||||
Options: serpent.OptionSet{
|
||||
{
|
||||
@@ -67,6 +65,11 @@ func (r *RootCmd) taskCreate() *serpent.Command {
|
||||
},
|
||||
},
|
||||
Handler: func(inv *serpent.Invocation) error {
|
||||
client, err := r.InitClient(inv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var (
|
||||
ctx = inv.Context()
|
||||
expClient = codersdk.NewExperimentalClient(client)
|
||||
|
||||
Reference in New Issue
Block a user