Skip to content

Commit a852fd2

Browse files
committed
spf13/cobra: don't use PersistentFlags()
1 parent d52aa91 commit a852fd2

File tree

13 files changed

+60
-60
lines changed

13 files changed

+60
-60
lines changed

internal/command/context/create.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ func newCreateCommand() *cobra.Command {
4242
RunE: runCreate,
4343
}
4444

45-
command.PersistentFlags().StringVar(&contextName, "name", "default",
45+
command.Flags().StringVar(&contextName, "name", "default",
4646
"context name to use")
47-
command.PersistentFlags().StringVar(&bootstrapTokenRaw, "bootstrap-token", "",
47+
command.Flags().StringVar(&bootstrapTokenRaw, "bootstrap-token", "",
4848
"bootstrap token to use")
49-
command.PersistentFlags().StringVar(&serviceAccountName, "service-account-name", "",
49+
command.Flags().StringVar(&serviceAccountName, "service-account-name", "",
5050
"service account name to use (alternative to --bootstrap-token)")
51-
command.PersistentFlags().StringVar(&serviceAccountToken, "service-account-token", "",
51+
command.Flags().StringVar(&serviceAccountToken, "service-account-token", "",
5252
"service account token to use (alternative to --bootstrap-token)")
53-
command.PersistentFlags().BoolVar(&force, "force", false,
53+
command.Flags().BoolVar(&force, "force", false,
5454
"create the context even if a context with the same name already exists")
55-
command.PersistentFlags().BoolVar(&noPKI, "no-pki", false,
55+
command.Flags().BoolVar(&noPKI, "no-pki", false,
5656
"do not use the host's root CA set and instead validate the Controller's presented "+
5757
"certificate using a bootstrap token (or manually via fingerprint, "+
5858
"if no bootstrap token is provided)")

internal/command/controller/run.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,31 +39,31 @@ func newRunCommand() *cobra.Command {
3939
port = strconv.FormatInt(netconstants.DefaultControllerPort, 10)
4040
}
4141

42-
cmd.PersistentFlags().StringVarP(&address, "listen", "l", fmt.Sprintf(":%s", port),
42+
cmd.Flags().StringVarP(&address, "listen", "l", fmt.Sprintf(":%s", port),
4343
"address to listen on")
44-
cmd.PersistentFlags().StringVar(&addressSSH, "listen-ssh", "",
44+
cmd.Flags().StringVar(&addressSSH, "listen-ssh", "",
4545
"address for the built-in SSH server to listen on (e.g. \":6122\")")
46-
cmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug logging")
46+
cmd.Flags().BoolVar(&debug, "debug", false, "enable debug logging")
4747

4848
// flags for auto-init if necessary
4949
// this simplifies the user experience to run the controller in serverless environments
50-
cmd.PersistentFlags().StringVar(&controllerCertPath, "controller-cert", "",
50+
cmd.Flags().StringVar(&controllerCertPath, "controller-cert", "",
5151
"use the controller certificate from the specified path instead of the auto-generated one"+
5252
" (requires --controller-key)")
53-
cmd.PersistentFlags().StringVar(&controllerKeyPath, "controller-key", "",
53+
cmd.Flags().StringVar(&controllerKeyPath, "controller-key", "",
5454
"use the controller certificate key from the specified path instead of the auto-generated one"+
5555
" (requires --controller-cert)")
56-
cmd.PersistentFlags().StringVar(&sshHostKeyPath, "ssh-host-key", "",
56+
cmd.Flags().StringVar(&sshHostKeyPath, "ssh-host-key", "",
5757
"use the SSH private host key from the specified path instead of the auto-generated one")
58-
cmd.PersistentFlags().BoolVar(&noTLS, "insecure-no-tls", false,
58+
cmd.Flags().BoolVar(&noTLS, "insecure-no-tls", false,
5959
"disable TLS, making all connections to the controller unencrypted")
60-
cmd.PersistentFlags().BoolVar(&sshNoClientAuth, "insecure-ssh-no-client-auth", false,
60+
cmd.Flags().BoolVar(&sshNoClientAuth, "insecure-ssh-no-client-auth", false,
6161
"allow SSH clients to connect to the controller's SSH server without authentication, "+
6262
"thus only authenticating on the target worker/VM's SSH server")
63-
cmd.PersistentFlags().BoolVar(&experimentalRPCV2, "experimental-rpc-v2", false,
63+
cmd.Flags().BoolVar(&experimentalRPCV2, "experimental-rpc-v2", false,
6464
"enable experimental RPC v2 (https://github.com/cirruslabs/orchard/issues/235)")
65-
_ = cmd.PersistentFlags().MarkHidden("experimental-rpc-v2")
66-
cmd.PersistentFlags().BoolVar(&noExperimentalRPCV2, "no-experimental-rpc-v2", false,
65+
_ = cmd.Flags().MarkHidden("experimental-rpc-v2")
66+
cmd.Flags().BoolVar(&noExperimentalRPCV2, "no-experimental-rpc-v2", false,
6767
"disable experimental RPC v2 (https://github.com/cirruslabs/orchard/issues/235)")
6868

6969
return cmd

internal/command/create/service_account.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ func newCreateServiceAccount() *cobra.Command {
1919
Args: cobra.ExactArgs(1),
2020
}
2121

22-
command.PersistentFlags().StringVar(&token, "token", "",
22+
command.Flags().StringVar(&token, "token", "",
2323
"token to use for this service account (autogenerated by the API server if left empty)")
2424

2525
var serviceAccountRoleList []string
2626
for _, role := range v1.AllServiceAccountRoles() {
2727
serviceAccountRoleList = append(serviceAccountRoleList, string(role))
2828
}
29-
command.PersistentFlags().StringArrayVar(&roles, "roles", []string{},
29+
command.Flags().StringArrayVar(&roles, "roles", []string{},
3030
fmt.Sprintf("roles to grant to this service account (supported roles: %s)",
3131
strings.Join(serviceAccountRoleList, ", ")))
3232

internal/command/create/vm.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,34 @@ func newCreateVMCommand() *cobra.Command {
3838
Args: cobra.ExactArgs(1),
3939
}
4040

41-
command.PersistentFlags().StringVar(&image, "image", "ghcr.io/cirruslabs/macos-sonoma-base:latest", "image to use")
42-
command.PersistentFlags().Uint64Var(&cpu, "cpu", 4, "number of CPUs to use")
43-
command.PersistentFlags().Uint64Var(&memory, "memory", 8*1024, "megabytes of memory to use")
44-
command.PersistentFlags().Uint64Var(&diskSize, "disk-size", 0, "resize the VMs disk to the specified size in GB "+
41+
command.Flags().StringVar(&image, "image", "ghcr.io/cirruslabs/macos-sonoma-base:latest", "image to use")
42+
command.Flags().Uint64Var(&cpu, "cpu", 4, "number of CPUs to use")
43+
command.Flags().Uint64Var(&memory, "memory", 8*1024, "megabytes of memory to use")
44+
command.Flags().Uint64Var(&diskSize, "disk-size", 0, "resize the VMs disk to the specified size in GB "+
4545
"(no resizing is done by default and VM's image default size is used)")
46-
command.PersistentFlags().BoolVar(&netSoftnet, "net-softnet", false, "whether to use Softnet network isolation")
47-
command.PersistentFlags().StringVar(&netBridged, "net-bridged", "", "whether to use Bridged network mode")
48-
command.PersistentFlags().BoolVar(&headless, "headless", true, "whether to run without graphics")
49-
command.PersistentFlags().StringVar(&username, "username", "admin",
46+
command.Flags().BoolVar(&netSoftnet, "net-softnet", false, "whether to use Softnet network isolation")
47+
command.Flags().StringVar(&netBridged, "net-bridged", "", "whether to use Bridged network mode")
48+
command.Flags().BoolVar(&headless, "headless", true, "whether to run without graphics")
49+
command.Flags().StringVar(&username, "username", "admin",
5050
"SSH username to use when executing a startup script on the VM")
51-
command.PersistentFlags().StringVar(&password, "password", "admin",
51+
command.Flags().StringVar(&password, "password", "admin",
5252
"SSH password to use when executing a startup script on the VM")
53-
command.PersistentFlags().StringToStringVar(&resources, "resources", map[string]string{},
53+
command.Flags().StringToStringVar(&resources, "resources", map[string]string{},
5454
"resources to request for this VM")
55-
command.PersistentFlags().StringToStringVar(&labels, "labels", map[string]string{},
55+
command.Flags().StringToStringVar(&labels, "labels", map[string]string{},
5656
"labels required by this VM")
57-
command.PersistentFlags().BoolVar(&randomSerial, "random-serial", false,
57+
command.Flags().BoolVar(&randomSerial, "random-serial", false,
5858
"generate a new random serial number if this is a macOS VM (no-op for Linux VMs)")
59-
command.PersistentFlags().StringVar(&restartPolicy, "restart-policy", string(v1.RestartPolicyNever),
59+
command.Flags().StringVar(&restartPolicy, "restart-policy", string(v1.RestartPolicyNever),
6060
fmt.Sprintf("restart policy for this VM: specify %q to never restart or %q "+
6161
"to only restart when the VM fails", v1.RestartPolicyNever, v1.RestartPolicyOnFailure))
62-
command.PersistentFlags().StringVar(&startupScript, "startup-script", "",
62+
command.Flags().StringVar(&startupScript, "startup-script", "",
6363
"startup script (e.g. --startup-script=\"sync\") or a path to a script file prefixed with \"@\" "+
6464
"(e.g. \"[email protected]\")")
65-
command.PersistentFlags().StringSliceVar(&hostDirsRaw, "host-dirs", []string{},
65+
command.Flags().StringSliceVar(&hostDirsRaw, "host-dirs", []string{},
6666
"host directories to mount to the VM, can be specified multiple times and/or be comma-separated "+
6767
"(see \"tart run\"'s --dir argument for syntax)")
68-
command.PersistentFlags().StringVar(&imagePullPolicy, "image-pull-policy", string(v1.ImagePullPolicyIfNotPresent),
68+
command.Flags().StringVar(&imagePullPolicy, "image-pull-policy", string(v1.ImagePullPolicyIfNotPresent),
6969
fmt.Sprintf("image pull policy for this VM, by default the image is only pulled if it doesn't "+
7070
"exist in the cache (%q), specify %q to always try to pull the image",
7171
v1.ImagePullPolicyIfNotPresent, v1.ImagePullPolicyAlways))

internal/command/dev/dev.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ func NewCommand() *cobra.Command {
3131
RunE: runDev,
3232
}
3333

34-
command.PersistentFlags().StringVarP(&devDataDirPath, "data-dir", "d", ".dev-data",
34+
command.Flags().StringVarP(&devDataDirPath, "data-dir", "d", ".dev-data",
3535
"path to persist data between runs")
36-
command.PersistentFlags().StringToStringVar(&stringToStringResources, "resources", map[string]string{},
36+
command.Flags().StringToStringVar(&stringToStringResources, "resources", map[string]string{},
3737
"resources that the development worker will provide")
38-
command.PersistentFlags().BoolVar(&experimentalRPCV2, "experimental-rpc-v2", false,
38+
command.Flags().BoolVar(&experimentalRPCV2, "experimental-rpc-v2", false,
3939
"enable experimental RPC v2 (https://github.com/cirruslabs/orchard/issues/235)")
4040

4141
return command

internal/command/list/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func NewCommand() *cobra.Command {
1414

1515
command.AddCommand(newListWorkersCommand(), newListVMsCommand(), newListServiceAccountsCommand())
1616

17-
command.PersistentFlags().BoolVarP(&quiet, "", "q", false, "only show resource names")
17+
command.Flags().BoolVarP(&quiet, "", "q", false, "only show resource names")
1818

1919
return command
2020
}

internal/command/pause/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func newPauseWorkerCommand() *cobra.Command {
1919
Args: cobra.ExactArgs(1),
2020
}
2121

22-
command.PersistentFlags().Uint64Var(&wait, "wait", 0,
22+
command.Flags().Uint64Var(&wait, "wait", 0,
2323
"wait the specified amount of seconds for the worker to stop running any VMs")
2424

2525
return command

internal/command/portforward/vm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func newPortForwardVMCommand() *cobra.Command {
1818
RunE: runPortForwardVMCommand,
1919
}
2020

21-
command.PersistentFlags().Uint16VarP(&wait, "wait", "t", 60,
21+
command.Flags().Uint16VarP(&wait, "wait", "t", 60,
2222
"Amount of seconds to wait for the VM to start running if it's not running already")
2323

2424
return command

internal/command/ssh/vm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ func newSSHVMCommand() *cobra.Command {
2828
RunE: runSSHVM,
2929
}
3030

31-
command.PersistentFlags().StringVarP(&username, "username", "u", "",
31+
command.Flags().StringVarP(&username, "username", "u", "",
3232
"SSH username")
33-
command.PersistentFlags().StringVarP(&password, "password", "p", "",
33+
command.Flags().StringVarP(&password, "password", "p", "",
3434
"SSH password")
35-
command.PersistentFlags().Uint16VarP(&wait, "wait", "t", 60,
35+
command.Flags().Uint16VarP(&wait, "wait", "t", 60,
3636
"Amount of seconds to wait for the VM to start running if it's not running already")
3737

3838
return command

internal/command/vnc/vm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ func newVNCVMCommand() *cobra.Command {
2424
RunE: runVNCVM,
2525
}
2626

27-
command.PersistentFlags().StringVarP(&username, "username", "u", "",
27+
command.Flags().StringVarP(&username, "username", "u", "",
2828
"VNC username")
29-
command.PersistentFlags().StringVarP(&password, "password", "p", "",
29+
command.Flags().StringVarP(&password, "password", "p", "",
3030
"VNC password")
31-
command.PersistentFlags().Uint16VarP(&wait, "wait", "w", 60,
31+
command.Flags().Uint16VarP(&wait, "wait", "w", 60,
3232
"Amount of seconds to wait for the VM to start running if it's not running already")
3333

3434
return command

internal/command/vnc/worker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ func newVNCWorkerCommand() *cobra.Command {
1717
RunE: runVNCWorker,
1818
}
1919

20-
command.PersistentFlags().StringVarP(&username, "username", "u", "",
20+
command.Flags().StringVarP(&username, "username", "u", "",
2121
"VNC username")
22-
command.PersistentFlags().StringVarP(&password, "password", "p", "",
22+
command.Flags().StringVarP(&password, "password", "p", "",
2323
"VNC password")
2424
return command
2525
}

internal/command/worker/run.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,31 @@ func newRunCommand() *cobra.Command {
4747
Args: cobra.ExactArgs(1),
4848
}
4949

50-
cmd.PersistentFlags().StringVar(&name, "name", "",
50+
cmd.Flags().StringVar(&name, "name", "",
5151
"name of the worker (defaults to the hostname)")
52-
cmd.PersistentFlags().StringVar(&bootstrapTokenRaw, "bootstrap-token", "",
52+
cmd.Flags().StringVar(&bootstrapTokenRaw, "bootstrap-token", "",
5353
"a bootstrap token retrieved via \"orchard get bootstrap-token <service-account-name-for-workers>\"")
54-
cmd.PersistentFlags().BoolVar(&bootstrapTokenStdin, "bootstrap-token-stdin", false,
54+
cmd.Flags().BoolVar(&bootstrapTokenStdin, "bootstrap-token-stdin", false,
5555
"use this flag to provide a bootstrap token via the standard input")
56-
cmd.PersistentFlags().StringVar(&logFilePath, "log-file", "",
56+
cmd.Flags().StringVar(&logFilePath, "log-file", "",
5757
"optional path to a file where logs (up to 100 Mb) will be written.")
58-
cmd.PersistentFlags().StringToStringVar(&stringToStringResources, "resources", map[string]string{},
58+
cmd.Flags().StringToStringVar(&stringToStringResources, "resources", map[string]string{},
5959
"resources that this worker provides")
60-
cmd.PersistentFlags().StringToStringVar(&labels, "labels", map[string]string{},
60+
cmd.Flags().StringToStringVar(&labels, "labels", map[string]string{},
6161
"labels that this worker supports")
62-
cmd.PersistentFlags().BoolVar(&noPKI, "no-pki", false,
62+
cmd.Flags().BoolVar(&noPKI, "no-pki", false,
6363
"do not use the host's root CA set and instead validate the Controller's presented "+
6464
"certificate using a bootstrap token (or manually via fingerprint, "+
6565
"if no bootstrap token is provided)")
66-
cmd.PersistentFlags().Uint64Var(&defaultCPU, "default-cpu", 4, "number of CPUs to use for VMs "+
66+
cmd.Flags().Uint64Var(&defaultCPU, "default-cpu", 4, "number of CPUs to use for VMs "+
6767
"that do not explicitly specify a value")
68-
cmd.PersistentFlags().Uint64Var(&defaultMemory, "default-memory", 8*1024, "megabytes of memory "+
68+
cmd.Flags().Uint64Var(&defaultMemory, "default-memory", 8*1024, "megabytes of memory "+
6969
"to use for VMs that do not explicitly specify a value")
7070
cmd.Flags().StringVar(&username, "user", "", "username to drop privileges to "+
7171
"(\"Local Network\" permission workaround: requires starting \"orchard worker run\" as \"root\", "+
7272
"the privileges will be then dropped to the specified user after starting the \"orchard localnetworkhelper\" "+
7373
"helper process)")
74-
cmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug logging")
74+
cmd.Flags().BoolVar(&debug, "debug", false, "enable debug logging")
7575

7676
return cmd
7777
}

pkg/client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func New(opts ...Option) (*Client, error) {
9292
// the requests may hang indefinitely. See [1] for more details.
9393
//
9494
// [1]: https://github.com/cirruslabs/orchard/issues/152#issuecomment-1927091747
95-
Timeout: 30 * time.Second,
95+
Timeout: 1 * time.Second,
9696
Transport: transport,
9797
}
9898

0 commit comments

Comments
 (0)