spf13/cobra: don't use PersistentFlags() (#319)

This commit is contained in:
Nikolay Edigaryev 2025-05-26 17:58:37 +02:00 committed by GitHub
parent 3a05fc71ae
commit 76f0672759
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 59 additions and 59 deletions

View File

@ -42,17 +42,17 @@ func newCreateCommand() *cobra.Command {
RunE: runCreate,
}
command.PersistentFlags().StringVar(&contextName, "name", "default",
command.Flags().StringVar(&contextName, "name", "default",
"context name to use")
command.PersistentFlags().StringVar(&bootstrapTokenRaw, "bootstrap-token", "",
command.Flags().StringVar(&bootstrapTokenRaw, "bootstrap-token", "",
"bootstrap token to use")
command.PersistentFlags().StringVar(&serviceAccountName, "service-account-name", "",
command.Flags().StringVar(&serviceAccountName, "service-account-name", "",
"service account name to use (alternative to --bootstrap-token)")
command.PersistentFlags().StringVar(&serviceAccountToken, "service-account-token", "",
command.Flags().StringVar(&serviceAccountToken, "service-account-token", "",
"service account token to use (alternative to --bootstrap-token)")
command.PersistentFlags().BoolVar(&force, "force", false,
command.Flags().BoolVar(&force, "force", false,
"create the context even if a context with the same name already exists")
command.PersistentFlags().BoolVar(&noPKI, "no-pki", false,
command.Flags().BoolVar(&noPKI, "no-pki", false,
"do not use the host's root CA set and instead validate the Controller's presented "+
"certificate using a bootstrap token (or manually via fingerprint, "+
"if no bootstrap token is provided)")

View File

@ -41,31 +41,31 @@ func newRunCommand() *cobra.Command {
port = strconv.FormatInt(netconstants.DefaultControllerPort, 10)
}
cmd.PersistentFlags().StringVarP(&address, "listen", "l", fmt.Sprintf(":%s", port),
cmd.Flags().StringVarP(&address, "listen", "l", fmt.Sprintf(":%s", port),
"address to listen on")
cmd.PersistentFlags().StringVar(&addressSSH, "listen-ssh", "",
cmd.Flags().StringVar(&addressSSH, "listen-ssh", "",
"address for the built-in SSH server to listen on (e.g. \":6122\")")
cmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug logging")
cmd.Flags().BoolVar(&debug, "debug", false, "enable debug logging")
// flags for auto-init if necessary
// this simplifies the user experience to run the controller in serverless environments
cmd.PersistentFlags().StringVar(&controllerCertPath, "controller-cert", "",
cmd.Flags().StringVar(&controllerCertPath, "controller-cert", "",
"use the controller certificate from the specified path instead of the auto-generated one"+
" (requires --controller-key)")
cmd.PersistentFlags().StringVar(&controllerKeyPath, "controller-key", "",
cmd.Flags().StringVar(&controllerKeyPath, "controller-key", "",
"use the controller certificate key from the specified path instead of the auto-generated one"+
" (requires --controller-cert)")
cmd.PersistentFlags().StringVar(&sshHostKeyPath, "ssh-host-key", "",
cmd.Flags().StringVar(&sshHostKeyPath, "ssh-host-key", "",
"use the SSH private host key from the specified path instead of the auto-generated one")
cmd.PersistentFlags().BoolVar(&noTLS, "insecure-no-tls", false,
cmd.Flags().BoolVar(&noTLS, "insecure-no-tls", false,
"disable TLS, making all connections to the controller unencrypted")
cmd.PersistentFlags().BoolVar(&sshNoClientAuth, "insecure-ssh-no-client-auth", false,
cmd.Flags().BoolVar(&sshNoClientAuth, "insecure-ssh-no-client-auth", false,
"allow SSH clients to connect to the controller's SSH server without authentication, "+
"thus only authenticating on the target worker/VM's SSH server")
cmd.PersistentFlags().BoolVar(&experimentalRPCV2, "experimental-rpc-v2", false,
cmd.Flags().BoolVar(&experimentalRPCV2, "experimental-rpc-v2", false,
"enable experimental RPC v2 (https://github.com/cirruslabs/orchard/issues/235)")
_ = cmd.PersistentFlags().MarkHidden("experimental-rpc-v2")
cmd.PersistentFlags().BoolVar(&noExperimentalRPCV2, "no-experimental-rpc-v2", false,
_ = cmd.Flags().MarkHidden("experimental-rpc-v2")
cmd.Flags().BoolVar(&noExperimentalRPCV2, "no-experimental-rpc-v2", false,
"disable experimental RPC v2 (https://github.com/cirruslabs/orchard/issues/235)")
cmd.PersistentFlags().DurationVar(&experimentalPingInterval, "experimental-ping-interval", 0,
"interval between WebSocket PING's sent by the controller to workers and clients, "+

View File

@ -19,14 +19,14 @@ func newCreateServiceAccount() *cobra.Command {
Args: cobra.ExactArgs(1),
}
command.PersistentFlags().StringVar(&token, "token", "",
command.Flags().StringVar(&token, "token", "",
"token to use for this service account (autogenerated by the API server if left empty)")
var serviceAccountRoleList []string
for _, role := range v1.AllServiceAccountRoles() {
serviceAccountRoleList = append(serviceAccountRoleList, string(role))
}
command.PersistentFlags().StringArrayVar(&roles, "roles", []string{},
command.Flags().StringArrayVar(&roles, "roles", []string{},
fmt.Sprintf("roles to grant to this service account (supported roles: %s)",
strings.Join(serviceAccountRoleList, ", ")))

View File

@ -38,34 +38,34 @@ func newCreateVMCommand() *cobra.Command {
Args: cobra.ExactArgs(1),
}
command.PersistentFlags().StringVar(&image, "image", "ghcr.io/cirruslabs/macos-sonoma-base:latest", "image to use")
command.PersistentFlags().Uint64Var(&cpu, "cpu", 4, "number of CPUs to use")
command.PersistentFlags().Uint64Var(&memory, "memory", 8*1024, "megabytes of memory to use")
command.PersistentFlags().Uint64Var(&diskSize, "disk-size", 0, "resize the VMs disk to the specified size in GB "+
command.Flags().StringVar(&image, "image", "ghcr.io/cirruslabs/macos-sonoma-base:latest", "image to use")
command.Flags().Uint64Var(&cpu, "cpu", 4, "number of CPUs to use")
command.Flags().Uint64Var(&memory, "memory", 8*1024, "megabytes of memory to use")
command.Flags().Uint64Var(&diskSize, "disk-size", 0, "resize the VMs disk to the specified size in GB "+
"(no resizing is done by default and VM's image default size is used)")
command.PersistentFlags().BoolVar(&netSoftnet, "net-softnet", false, "whether to use Softnet network isolation")
command.PersistentFlags().StringVar(&netBridged, "net-bridged", "", "whether to use Bridged network mode")
command.PersistentFlags().BoolVar(&headless, "headless", true, "whether to run without graphics")
command.PersistentFlags().StringVar(&username, "username", "admin",
command.Flags().BoolVar(&netSoftnet, "net-softnet", false, "whether to use Softnet network isolation")
command.Flags().StringVar(&netBridged, "net-bridged", "", "whether to use Bridged network mode")
command.Flags().BoolVar(&headless, "headless", true, "whether to run without graphics")
command.Flags().StringVar(&username, "username", "admin",
"SSH username to use when executing a startup script on the VM")
command.PersistentFlags().StringVar(&password, "password", "admin",
command.Flags().StringVar(&password, "password", "admin",
"SSH password to use when executing a startup script on the VM")
command.PersistentFlags().StringToStringVar(&resources, "resources", map[string]string{},
command.Flags().StringToStringVar(&resources, "resources", map[string]string{},
"resources to request for this VM")
command.PersistentFlags().StringToStringVar(&labels, "labels", map[string]string{},
command.Flags().StringToStringVar(&labels, "labels", map[string]string{},
"labels required by this VM")
command.PersistentFlags().BoolVar(&randomSerial, "random-serial", false,
command.Flags().BoolVar(&randomSerial, "random-serial", false,
"generate a new random serial number if this is a macOS VM (no-op for Linux VMs)")
command.PersistentFlags().StringVar(&restartPolicy, "restart-policy", string(v1.RestartPolicyNever),
command.Flags().StringVar(&restartPolicy, "restart-policy", string(v1.RestartPolicyNever),
fmt.Sprintf("restart policy for this VM: specify %q to never restart or %q "+
"to only restart when the VM fails", v1.RestartPolicyNever, v1.RestartPolicyOnFailure))
command.PersistentFlags().StringVar(&startupScript, "startup-script", "",
command.Flags().StringVar(&startupScript, "startup-script", "",
"startup script (e.g. --startup-script=\"sync\") or a path to a script file prefixed with \"@\" "+
"(e.g. \"--startup-script=@script.sh\")")
command.PersistentFlags().StringSliceVar(&hostDirsRaw, "host-dirs", []string{},
command.Flags().StringSliceVar(&hostDirsRaw, "host-dirs", []string{},
"host directories to mount to the VM, can be specified multiple times and/or be comma-separated "+
"(see \"tart run\"'s --dir argument for syntax)")
command.PersistentFlags().StringVar(&imagePullPolicy, "image-pull-policy", string(v1.ImagePullPolicyIfNotPresent),
command.Flags().StringVar(&imagePullPolicy, "image-pull-policy", string(v1.ImagePullPolicyIfNotPresent),
fmt.Sprintf("image pull policy for this VM, by default the image is only pulled if it doesn't "+
"exist in the cache (%q), specify %q to always try to pull the image",
v1.ImagePullPolicyIfNotPresent, v1.ImagePullPolicyAlways))

View File

@ -31,11 +31,11 @@ func NewCommand() *cobra.Command {
RunE: runDev,
}
command.PersistentFlags().StringVarP(&devDataDirPath, "data-dir", "d", ".dev-data",
command.Flags().StringVarP(&devDataDirPath, "data-dir", "d", ".dev-data",
"path to persist data between runs")
command.PersistentFlags().StringToStringVar(&stringToStringResources, "resources", map[string]string{},
command.Flags().StringToStringVar(&stringToStringResources, "resources", map[string]string{},
"resources that the development worker will provide")
command.PersistentFlags().BoolVar(&experimentalRPCV2, "experimental-rpc-v2", false,
command.Flags().BoolVar(&experimentalRPCV2, "experimental-rpc-v2", false,
"enable experimental RPC v2 (https://github.com/cirruslabs/orchard/issues/235)")
return command

View File

@ -14,7 +14,7 @@ func NewCommand() *cobra.Command {
command.AddCommand(newListWorkersCommand(), newListVMsCommand(), newListServiceAccountsCommand())
command.PersistentFlags().BoolVarP(&quiet, "", "q", false, "only show resource names")
command.Flags().BoolVarP(&quiet, "", "q", false, "only show resource names")
return command
}

View File

@ -19,7 +19,7 @@ func newPauseWorkerCommand() *cobra.Command {
Args: cobra.ExactArgs(1),
}
command.PersistentFlags().Uint64Var(&wait, "wait", 0,
command.Flags().Uint64Var(&wait, "wait", 0,
"wait the specified amount of seconds for the worker to stop running any VMs")
return command

View File

@ -18,7 +18,7 @@ func newPortForwardVMCommand() *cobra.Command {
RunE: runPortForwardVMCommand,
}
command.PersistentFlags().Uint16VarP(&wait, "wait", "t", 60,
command.Flags().Uint16VarP(&wait, "wait", "t", 60,
"Amount of seconds to wait for the VM to start running if it's not running already")
return command

View File

@ -28,11 +28,11 @@ func newSSHVMCommand() *cobra.Command {
RunE: runSSHVM,
}
command.PersistentFlags().StringVarP(&username, "username", "u", "",
command.Flags().StringVarP(&username, "username", "u", "",
"SSH username")
command.PersistentFlags().StringVarP(&password, "password", "p", "",
command.Flags().StringVarP(&password, "password", "p", "",
"SSH password")
command.PersistentFlags().Uint16VarP(&wait, "wait", "t", 60,
command.Flags().Uint16VarP(&wait, "wait", "t", 60,
"Amount of seconds to wait for the VM to start running if it's not running already")
return command

View File

@ -24,11 +24,11 @@ func newVNCVMCommand() *cobra.Command {
RunE: runVNCVM,
}
command.PersistentFlags().StringVarP(&username, "username", "u", "",
command.Flags().StringVarP(&username, "username", "u", "",
"VNC username")
command.PersistentFlags().StringVarP(&password, "password", "p", "",
command.Flags().StringVarP(&password, "password", "p", "",
"VNC password")
command.PersistentFlags().Uint16VarP(&wait, "wait", "w", 60,
command.Flags().Uint16VarP(&wait, "wait", "w", 60,
"Amount of seconds to wait for the VM to start running if it's not running already")
return command

View File

@ -17,9 +17,9 @@ func newVNCWorkerCommand() *cobra.Command {
RunE: runVNCWorker,
}
command.PersistentFlags().StringVarP(&username, "username", "u", "",
command.Flags().StringVarP(&username, "username", "u", "",
"VNC username")
command.PersistentFlags().StringVarP(&password, "password", "p", "",
command.Flags().StringVarP(&password, "password", "p", "",
"VNC password")
return command
}

View File

@ -47,31 +47,31 @@ func newRunCommand() *cobra.Command {
Args: cobra.ExactArgs(1),
}
cmd.PersistentFlags().StringVar(&name, "name", "",
cmd.Flags().StringVar(&name, "name", "",
"name of the worker (defaults to the hostname)")
cmd.PersistentFlags().StringVar(&bootstrapTokenRaw, "bootstrap-token", "",
cmd.Flags().StringVar(&bootstrapTokenRaw, "bootstrap-token", "",
"a bootstrap token retrieved via \"orchard get bootstrap-token <service-account-name-for-workers>\"")
cmd.PersistentFlags().BoolVar(&bootstrapTokenStdin, "bootstrap-token-stdin", false,
cmd.Flags().BoolVar(&bootstrapTokenStdin, "bootstrap-token-stdin", false,
"use this flag to provide a bootstrap token via the standard input")
cmd.PersistentFlags().StringVar(&logFilePath, "log-file", "",
cmd.Flags().StringVar(&logFilePath, "log-file", "",
"optional path to a file where logs (up to 100 Mb) will be written.")
cmd.PersistentFlags().StringToStringVar(&stringToStringResources, "resources", map[string]string{},
cmd.Flags().StringToStringVar(&stringToStringResources, "resources", map[string]string{},
"resources that this worker provides")
cmd.PersistentFlags().StringToStringVar(&labels, "labels", map[string]string{},
cmd.Flags().StringToStringVar(&labels, "labels", map[string]string{},
"labels that this worker supports")
cmd.PersistentFlags().BoolVar(&noPKI, "no-pki", false,
cmd.Flags().BoolVar(&noPKI, "no-pki", false,
"do not use the host's root CA set and instead validate the Controller's presented "+
"certificate using a bootstrap token (or manually via fingerprint, "+
"if no bootstrap token is provided)")
cmd.PersistentFlags().Uint64Var(&defaultCPU, "default-cpu", 4, "number of CPUs to use for VMs "+
cmd.Flags().Uint64Var(&defaultCPU, "default-cpu", 4, "number of CPUs to use for VMs "+
"that do not explicitly specify a value")
cmd.PersistentFlags().Uint64Var(&defaultMemory, "default-memory", 8*1024, "megabytes of memory "+
cmd.Flags().Uint64Var(&defaultMemory, "default-memory", 8*1024, "megabytes of memory "+
"to use for VMs that do not explicitly specify a value")
cmd.Flags().StringVar(&username, "user", "", "username to drop privileges to "+
"(\"Local Network\" permission workaround: requires starting \"orchard worker run\" as \"root\", "+
"the privileges will be then dropped to the specified user after starting the \"orchard localnetworkhelper\" "+
"helper process)")
cmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug logging")
cmd.Flags().BoolVar(&debug, "debug", false, "enable debug logging")
return cmd
}