From 060094f70cf32b3c8758b59f6631f73ed7541a64 Mon Sep 17 00:00:00 2001 From: Arthur Amstutz Date: Mon, 23 Feb 2026 21:03:35 +0100 Subject: [PATCH] chore: Merge addInitParameterFileFlag and addFomFileFlag utility funcs Signed-off-by: Arthur Amstutz --- internal/cmd/account.go | 3 +-- internal/cmd/baremetal.go | 5 ++--- internal/cmd/cloud_alerting.go | 3 +-- internal/cmd/cloud_container_registry.go | 12 ++++-------- internal/cmd/cloud_instance.go | 6 ++---- internal/cmd/cloud_kube.go | 12 ++++-------- internal/cmd/cloud_network.go | 9 +++------ internal/cmd/cloud_rancher.go | 3 +-- internal/cmd/cloud_ssh_key.go | 3 +-- internal/cmd/cloud_storage_block.go | 3 +-- internal/cmd/cloud_storage_s3.go | 9 +++------ internal/cmd/cloud_user.go | 6 ++---- internal/cmd/domainzone.go | 6 ++---- internal/cmd/emaildomain.go | 3 +-- internal/cmd/iam.go | 6 ++---- internal/cmd/parameter.go | 13 +++++++------ internal/cmd/parameter_test.go | 8 ++++---- internal/cmd/vps.go | 3 +-- 18 files changed, 42 insertions(+), 71 deletions(-) diff --git a/internal/cmd/account.go b/internal/cmd/account.go index e8ddc857..92605137 100644 --- a/internal/cmd/account.go +++ b/internal/cmd/account.go @@ -78,9 +78,8 @@ func init() { oauth2CreateCmd.Flags().StringVar(&account.Oauth2ClientSpec.Description, "description", "", "Description of the OAuth2 client") oauth2CreateCmd.Flags().StringVar(&account.Oauth2ClientSpec.Flow, "flow", "AUTHORIZATION_CODE", "OAuth2 flow type (default: AUTHORIZATION_CODE)") oauth2CreateCmd.Flags().StringVar(&account.Oauth2ClientSpec.Name, "name", "", "Name of the OAuth2 client") - addInitParameterFileFlag(oauth2CreateCmd, assets.MeOpenapiSchema, "/me/api/oauth2/client", "post", account.Oauth2ClientCreateSample, nil) + addParameterFileFlags(oauth2CreateCmd, false, assets.MeOpenapiSchema, "/me/api/oauth2/client", "post", account.Oauth2ClientCreateSample, nil) addInteractiveEditorFlag(oauth2CreateCmd) - addFromFileFlag(oauth2CreateCmd) oauth2CreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor") oauth2ClientCmd.AddCommand(oauth2CreateCmd) diff --git a/internal/cmd/baremetal.go b/internal/cmd/baremetal.go index 2e8177d7..785de381 100644 --- a/internal/cmd/baremetal.go +++ b/internal/cmd/baremetal.go @@ -132,9 +132,8 @@ Please note that all parameters are not compatible with all OSes. Run: baremetal.ReinstallBaremetal, } - addInitParameterFileFlag(reinstallBaremetalCmd, assets.BaremetalOpenapiSchema, "/dedicated/server/{serviceName}/reinstall", "post", baremetal.BaremetalInstallationExample, nil) + addParameterFileFlags(reinstallBaremetalCmd, false, assets.BaremetalOpenapiSchema, "/dedicated/server/{serviceName}/reinstall", "post", baremetal.BaremetalInstallationExample, nil) addInteractiveEditorFlag(reinstallBaremetalCmd) - addFromFileFlag(reinstallBaremetalCmd) reinstallBaremetalCmd.Flags().StringVar(&baremetal.OperatingSystem, "os", "", "Operating system to install") reinstallBaremetalCmd.Flags().StringVar(&baremetal.Customizations.ConfigDriveUserData, "config-drive-user-data", "", "Config Drive UserData") reinstallBaremetalCmd.Flags().StringVar(&baremetal.Customizations.EfiBootloaderPath, "efi-bootloader-path", "", "Path of the EFI bootloader from the OS installed on the server") @@ -180,7 +179,7 @@ Please note that all parameters are not compatible with all OSes. } baremetalBootSetScriptCmd.Flags().StringVar(&baremetal.EditBaremetalParams.BootScript, "script", "", "Boot script to set on the baremetal") addInteractiveEditorFlag(baremetalBootSetScriptCmd) - addFromFileFlag(baremetalBootSetScriptCmd) + addParameterFileFlags(baremetalBootSetScriptCmd, true, nil, "", "", "", nil) baremetalBootSetScriptCmd.MarkFlagsOneRequired("script", "from-file", "editor") baremetalBootSetScriptCmd.MarkFlagsMutuallyExclusive("script", "from-file", "editor") baremetalBootCmd.AddCommand(baremetalBootSetScriptCmd) diff --git a/internal/cmd/cloud_alerting.go b/internal/cmd/cloud_alerting.go index d34db279..a9f10351 100644 --- a/internal/cmd/cloud_alerting.go +++ b/internal/cmd/cloud_alerting.go @@ -45,9 +45,8 @@ func initCloudAlertingCommand(cloudCmd *cobra.Command) { alertingCreateCmd.Flags().Int64Var(&cloud.AlertingConfigSpec.MonthlyThreshold, "monthly-threshold", 0, "Monthly threshold value") alertingCreateCmd.Flags().StringVar(&cloud.AlertingConfigSpec.Name, "name", "", "Alert name") alertingCreateCmd.Flags().StringVar(&cloud.AlertingConfigSpec.Service, "service", "", "Service of the alert. Allowed: ai_endpoint, all, block_storage, data_platform, instances, instances_gpu, instances_without_gpu, objet_storage, rancher, snapshot") - addInitParameterFileFlag(alertingCreateCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/alerting", "post", cloud.AlertingConfigCreateExample, nil) + addParameterFileFlags(alertingCreateCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/alerting", "post", cloud.AlertingConfigCreateExample, nil) addInteractiveEditorFlag(alertingCreateCmd) - addFromFileFlag(alertingCreateCmd) alertingCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor") alertingCmd.AddCommand(alertingCreateCmd) diff --git a/internal/cmd/cloud_container_registry.go b/internal/cmd/cloud_container_registry.go index 28974b19..38567c71 100644 --- a/internal/cmd/cloud_container_registry.go +++ b/internal/cmd/cloud_container_registry.go @@ -50,9 +50,8 @@ func initContainerRegistryCommand(cloudCmd *cobra.Command) { createCmd.Flags().StringVar(&cloud.CloudContainerRegistrySpec.Name, "name", "", "Name of the container registry") createCmd.Flags().StringVar(&cloud.CloudContainerRegistrySpec.PlanID, "plan-id", "", "Plan ID for the container registry. Available plans can be listed with 'ovhcloud cloud reference container-registry list-plans'") createCmd.Flags().StringVar(&cloud.CloudContainerRegistrySpec.Region, "region", "", "Region for the container registry (e.g., DE, GRA, BHS)") - addInitParameterFileFlag(createCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/containerRegistry", "post", cloud.CloudContainerRegistryCreateSample, nil) + addParameterFileFlags(createCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/containerRegistry", "post", cloud.CloudContainerRegistryCreateSample, nil) addInteractiveEditorFlag(createCmd) - addFromFileFlag(createCmd) createCmd.MarkFlagsMutuallyExclusive("from-file", "editor") registryCmd.AddCommand(createCmd) @@ -101,9 +100,8 @@ func initContainerRegistryUsersCommand(registryCmd *cobra.Command) { } createCmd.Flags().StringVar(&cloud.CloudContainerRegistryUserSpec.Email, "email", "", "User email") createCmd.Flags().StringVar(&cloud.CloudContainerRegistryUserSpec.Login, "login", "", "User login") - addInitParameterFileFlag(createCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/containerRegistry/{registryId}/users", "post", cloud.CloudContainerRegistryUserCreateSample, nil) + addParameterFileFlags(createCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/containerRegistry/{registryId}/users", "post", cloud.CloudContainerRegistryUserCreateSample, nil) addInteractiveEditorFlag(createCmd) - addFromFileFlag(createCmd) createCmd.MarkFlagsMutuallyExclusive("from-file", "editor") usersCmd.AddCommand(createCmd) @@ -137,9 +135,8 @@ func initContainerRegistryIAMCommand(registryCmd *cobra.Command) { Run: cloud.EnableContainerRegistryIAM, } enableCmd.Flags().BoolVar(&cloud.CloudContainerRegistryIamSpec.DeleteUsers, "delete-users", false, "Delete existing container registry users when enabling IAM") - addInitParameterFileFlag(enableCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/containerRegistry/{registryId}/iam", "post", cloud.CloudContainerRegistryIamEnableSample, nil) + addParameterFileFlags(enableCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/containerRegistry/{registryId}/iam", "post", cloud.CloudContainerRegistryIamEnableSample, nil) addInteractiveEditorFlag(enableCmd) - addFromFileFlag(enableCmd) enableCmd.MarkFlagsMutuallyExclusive("from-file", "editor") iamCmd.AddCommand(enableCmd) @@ -277,9 +274,8 @@ func initContainerRegistryOIDCCommand(registryCmd *cobra.Command) { createCmd.Flags().StringVar(&cloud.CloudContainerRegistryOidcCreateSpec.Provider.UserClaim, "user-claim", "", "OIDC claim containing the username") createCmd.Flags().BoolVar(&cloud.CloudContainerRegistryOidcCreateSpec.Provider.AutoOnboard, "auto-onboard", false, "Automatically create users on first login") createCmd.Flags().BoolVar(&cloud.CloudContainerRegistryOidcCreateSpec.Provider.VerifyCert, "verify-cert", false, "Verify the provider TLS certificate") - addInitParameterFileFlag(createCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/containerRegistry/{registryID}/openIdConnect", "post", cloud.CloudContainerRegistryOidcCreateSample, nil) + addParameterFileFlags(createCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/containerRegistry/{registryID}/openIdConnect", "post", cloud.CloudContainerRegistryOidcCreateSample, nil) addInteractiveEditorFlag(createCmd) - addFromFileFlag(createCmd) createCmd.MarkFlagsMutuallyExclusive("from-file", "editor") oidcCmd.AddCommand(createCmd) diff --git a/internal/cmd/cloud_instance.go b/internal/cmd/cloud_instance.go index 620e0fde..029393bc 100644 --- a/internal/cmd/cloud_instance.go +++ b/internal/cmd/cloud_instance.go @@ -128,9 +128,8 @@ There are three ways to define the creation parameters: instanceCreateCmd.Flags().StringVar(&cloud.InstanceCreationParameters.UserData, "user-data", "", "Configuration information or scripts to use upon launch") // Common flags for other mean to define parameters - addInitParameterFileFlag(instanceCreateCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/instance", "post", cloud.CloudInstanceCreationExample, cloud.GetInstanceFlavorAndImageInteractiveSelector) + addParameterFileFlags(instanceCreateCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/instance", "post", cloud.CloudInstanceCreationExample, cloud.GetInstanceFlavorAndImageInteractiveSelector) addInteractiveEditorFlag(instanceCreateCmd) - addFromFileFlag(instanceCreateCmd) instanceCreateCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for instance creation to be done before exiting") if !(runtime.GOARCH == "wasm" && runtime.GOOS == "js") { instanceCreateCmd.Flags().BoolVar(&cloud.InstanceImageViaInteractiveSelector, "image-selector", false, "Use the interactive image selector") @@ -279,9 +278,8 @@ There are three ways to define the installation parameters: Run: cloud.ReinstallInstance, Args: cobra.MaximumNArgs(1), } - addInitParameterFileFlag(reinstallCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/instance/{instanceId}/reinstall", "post", "", nil) + addParameterFileFlags(reinstallCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/instance/{instanceId}/reinstall", "post", "", nil) addInteractiveEditorFlag(reinstallCmd) - addFromFileFlag(reinstallCmd) reinstallCmd.Flags().StringVar(&cloud.InstanceImageID, "image", "", "Image to use for reinstallation") reinstallCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for reinstall to be done before exiting") if !(runtime.GOARCH == "wasm" && runtime.GOOS == "js") { diff --git a/internal/cmd/cloud_kube.go b/internal/cmd/cloud_kube.go index 64ed4346..f00bc2d0 100644 --- a/internal/cmd/cloud_kube.go +++ b/internal/cmd/cloud_kube.go @@ -363,9 +363,8 @@ There are three ways to define the creation parameters: kubeCreateCmd.Flags().StringVar(&cloud.KubeSpec.Customization.KubeProxy.IPVS.UDPTimeout, "customization.kube-proxy.ipvs.udp-timeout", "", "Timeout value used for IPVS UDP packets in RFC3339 duration format (e.g. 'PT60S')") // Common flags for other means to define parameters - addInitParameterFileFlag(kubeCreateCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/kube", "post", cloud.CloudKubeCreationExample, nil) + addParameterFileFlags(kubeCreateCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/kube", "post", cloud.CloudKubeCreationExample, nil) addInteractiveEditorFlag(kubeCreateCmd) - addFromFileFlag(kubeCreateCmd) kubeCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor") return kubeCreateCmd @@ -449,9 +448,8 @@ There are three ways to define the reset parameters: kubeResetCmd.Flags().StringVar(&cloud.KubeSpec.Customization.KubeProxy.IPVS.UDPTimeout, "customization.kube-proxy.ipvs.udp-timeout", "", "Timeout value used for IPVS UDP packets in RFC3339 duration format (e.g. 'PT60S')") // Common flags for other means to define parameters - addInitParameterFileFlag(kubeResetCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/kube/reset", "post", cloud.CloudKubeResetExample, nil) + addParameterFileFlags(kubeResetCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/kube/reset", "post", cloud.CloudKubeResetExample, nil) addInteractiveEditorFlag(kubeResetCmd) - addFromFileFlag(kubeResetCmd) kubeResetCmd.MarkFlagsMutuallyExclusive("from-file", "editor") return kubeResetCmd @@ -565,9 +563,8 @@ There are three ways to define the creation parameters: nodepoolCreateCmd.Flags().BoolVar(&cloud.KubeNodepoolSpec.Template.Spec.Unschedulable, "template-unschedulable", false, "Set the nodes as unschedulable") // Common flags for other means to define parameters - addInitParameterFileFlag(nodepoolCreateCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/kube/{kubeId}/nodepool", "post", cloud.CloudKubeNodePoolCreationExample, cloud.GetKubeFlavorInteractiveSelector) + addParameterFileFlags(nodepoolCreateCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/kube/{kubeId}/nodepool", "post", cloud.CloudKubeNodePoolCreationExample, cloud.GetKubeFlavorInteractiveSelector) addInteractiveEditorFlag(nodepoolCreateCmd) - addFromFileFlag(nodepoolCreateCmd) if !(runtime.GOARCH == "wasm" && runtime.GOOS == "js") { nodepoolCreateCmd.Flags().BoolVar(&cloud.InstanceFlavorViaInteractiveSelector, "flavor-selector", false, "Use the interactive flavor selector") nodepoolCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor") @@ -633,9 +630,8 @@ There are three ways to define the parameters: createCmd.Flags().StringVar(&cloud.KubeOIDCConfig.UsernamePrefix, "username-prefix", "", "Prefix prepended to username claims") // Common flags for other means to define parameters - addInitParameterFileFlag(createCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/kube/{kubeId}/openIdConnect", "post", cloud.CloudKubeOIDCCreationExample, nil) + addParameterFileFlags(createCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/kube/{kubeId}/openIdConnect", "post", cloud.CloudKubeOIDCCreationExample, nil) addInteractiveEditorFlag(createCmd) - addFromFileFlag(createCmd) createCmd.MarkFlagsMutuallyExclusive("from-file", "editor") return createCmd diff --git a/internal/cmd/cloud_network.go b/internal/cmd/cloud_network.go index f145727a..bce1668d 100644 --- a/internal/cmd/cloud_network.go +++ b/internal/cmd/cloud_network.go @@ -299,9 +299,8 @@ There are three ways to define the parameters: privateNetworkCreateCmd.Flags().StringSliceVar(&cloud.CloudNetworkSpec.Subnet.CliHostRoutes, "subnet-host-routes", nil, "Host routes for the subnet in format destination:nextHop") // Common flags for other means to define parameters - addInitParameterFileFlag(privateNetworkCreateCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/region/{regionName}/network", "post", cloud.PrivateNetworkCreationExample, nil) + addParameterFileFlags(privateNetworkCreateCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/region/{regionName}/network", "post", cloud.PrivateNetworkCreationExample, nil) addInteractiveEditorFlag(privateNetworkCreateCmd) - addFromFileFlag(privateNetworkCreateCmd) privateNetworkCreateCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for network creation to be done before exiting") privateNetworkCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor") @@ -361,9 +360,8 @@ There are three ways to define the parameters: privateNetworkSubnetCreateCmd.Flags().StringVar(&cloud.CloudNetworkSubnetSpec.Region, "region", "", "Region for the subnet") // Common flags for other means to define parameters - addInitParameterFileFlag(privateNetworkSubnetCreateCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/network/private/{networkId}/subnet", "post", cloud.PrivateNetworkSubnetCreationExample, nil) + addParameterFileFlags(privateNetworkSubnetCreateCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/network/private/{networkId}/subnet", "post", cloud.PrivateNetworkSubnetCreationExample, nil) addInteractiveEditorFlag(privateNetworkSubnetCreateCmd) - addFromFileFlag(privateNetworkSubnetCreateCmd) privateNetworkSubnetCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor") return privateNetworkSubnetCreateCmd @@ -442,9 +440,8 @@ There are three ways to define the parameters: gatewayCreateCmd.Flags().StringSliceVar(&cloud.CloudGatewaySpec.Network.Subnet.CliHostRoutes, "subnet-host-routes", nil, "Host routes for the subnet in format destination:nextHop") // Common flags for other means to define parameters - addInitParameterFileFlag(gatewayCreateCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/region/{regionName}/gateway", "post", cloud.GatewayCreationExample, nil) + addParameterFileFlags(gatewayCreateCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/region/{regionName}/gateway", "post", cloud.GatewayCreationExample, nil) addInteractiveEditorFlag(gatewayCreateCmd) - addFromFileFlag(gatewayCreateCmd) gatewayCreateCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for gateway creation to be done before exiting") gatewayCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor") diff --git a/internal/cmd/cloud_rancher.go b/internal/cmd/cloud_rancher.go index 39e331e7..cabcd130 100644 --- a/internal/cmd/cloud_rancher.go +++ b/internal/cmd/cloud_rancher.go @@ -136,9 +136,8 @@ There are three ways to define the creation parameters: rancherCreateCmd.Flags().BoolVar(cloud.RancherSpec.TargetSpec.IAMAuthEnabled, "iam-auth-enabled", false, "Allow Rancher to use identities managed by OVHcloud IAM (Identity and Access Management) to control access") // Common flags for other means to define parameters - addInitParameterFileFlag(rancherCreateCmd, assets.CloudV2OpenapiSchema, "/cloud/project/{serviceName}/rancher", "post", cloud.CloudRancherCreationExample, nil) + addParameterFileFlags(rancherCreateCmd, false, assets.CloudV2OpenapiSchema, "/cloud/project/{serviceName}/rancher", "post", cloud.CloudRancherCreationExample, nil) addInteractiveEditorFlag(rancherCreateCmd) - addFromFileFlag(rancherCreateCmd) rancherCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor") return rancherCreateCmd diff --git a/internal/cmd/cloud_ssh_key.go b/internal/cmd/cloud_ssh_key.go index ac4579cd..2c70b32e 100644 --- a/internal/cmd/cloud_ssh_key.go +++ b/internal/cmd/cloud_ssh_key.go @@ -40,9 +40,8 @@ func initCloudSSHKeyCommand(cloudCmd *cobra.Command) { sshKeyCreateCmd.Flags().StringVar(&cloud.SSHKeyCreationParameters.Name, "name", "", "Name for the SSH key to create") sshKeyCreateCmd.Flags().StringVar(&cloud.SSHKeyCreationParameters.PublicKey, "public-key", "", "Public key for the SSH key to create") sshKeyCreateCmd.Flags().StringVar(&cloud.SSHKeyCreationParameters.Region, "region", "", "Region for the SSH key to create (optional)") - addInitParameterFileFlag(sshKeyCreateCmd, assets.CloudOpenapiSchema, "/v1/cloud/project/{serviceName}/sshkey", "post", cloud.SSHKeyCreationExample, nil) + addParameterFileFlags(sshKeyCreateCmd, false, assets.CloudOpenapiSchema, "/v1/cloud/project/{serviceName}/sshkey", "post", cloud.SSHKeyCreationExample, nil) addInteractiveEditorFlag(sshKeyCreateCmd) - addFromFileFlag(sshKeyCreateCmd) sshKeyCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor") sshKeyCmd.AddCommand(sshKeyCreateCmd) diff --git a/internal/cmd/cloud_storage_block.go b/internal/cmd/cloud_storage_block.go index a5fa42bf..11a75f6c 100644 --- a/internal/cmd/cloud_storage_block.go +++ b/internal/cmd/cloud_storage_block.go @@ -178,9 +178,8 @@ func getVolumeCreateCmd() *cobra.Command { volumeCreateCmd.Flags().StringVar(&cloud.VolumeSpec.SnapshotId, "snapshot-id", "", "Snapshot ID to create the volume from") volumeCreateCmd.Flags().StringVar(&cloud.VolumeSpec.Type, "type", "", "Volume type (classic, classic-luks, classic-multiattach, high-speed, high-speed-gen2, high-speed-gen2-luks, high-speed-luks)") - addInitParameterFileFlag(volumeCreateCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/region/{regionName}/volume", "post", cloud.VolumeCreateExample, nil) + addParameterFileFlags(volumeCreateCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/region/{regionName}/volume", "post", cloud.VolumeCreateExample, nil) addInteractiveEditorFlag(volumeCreateCmd) - addFromFileFlag(volumeCreateCmd) volumeCreateCmd.Flags().BoolVar(&flags.WaitForTask, "wait", false, "Wait for volume creation to be done before exiting") volumeCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor") diff --git a/internal/cmd/cloud_storage_s3.go b/internal/cmd/cloud_storage_s3.go index e4f2c3e0..5902b724 100644 --- a/internal/cmd/cloud_storage_s3.go +++ b/internal/cmd/cloud_storage_s3.go @@ -222,9 +222,8 @@ func initCloudStorageS3Command(cloudCmd *cobra.Command) { presignedURLCmd.Flags().IntVar(&cloud.StorageS3PresignedURLParams.Expire, "expire", 60, "Expiration time in seconds for the presigned URL") presignedURLCmd.Flags().StringVar(&cloud.StorageS3PresignedURLParams.VersionId, "version-id", "", "Version ID of the object (if applicable)") presignedURLCmd.Flags().StringVar(&cloud.StorageS3PresignedURLParams.StorageClass, "storage-class", "", "Storage class for the object (HIGH_PERF, STANDARD, STANDARD_IA)") - addInitParameterFileFlag(presignedURLCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/region/{regionName}/storage/{name}/presign", "post", cloud.CloudStorageS3PresignedURLExample, nil) + addParameterFileFlags(presignedURLCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/region/{regionName}/storage/{name}/presign", "post", cloud.CloudStorageS3PresignedURLExample, nil) addInteractiveEditorFlag(presignedURLCmd) - addFromFileFlag(presignedURLCmd) presignedURLCmd.MarkFlagsMutuallyExclusive("from-file", "editor") storageS3Cmd.AddCommand(presignedURLCmd) @@ -256,9 +255,8 @@ func initCloudStorageS3Command(cloudCmd *cobra.Command) { Run: cloud.EditStorageS3Lifecycle, Args: cobra.ExactArgs(1), } - addInitParameterFileFlag(lifecycleEditCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/region/{regionName}/storage/{name}/lifecycle", "put", cloud.CloudStorageS3LifecycleExample, nil) + addParameterFileFlags(lifecycleEditCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/region/{regionName}/storage/{name}/lifecycle", "put", cloud.CloudStorageS3LifecycleExample, nil) addInteractiveEditorFlag(lifecycleEditCmd) - addFromFileFlag(lifecycleEditCmd) lifecycleEditCmd.MarkFlagsMutuallyExclusive("from-file", "editor") lifecycleCmd.AddCommand(lifecycleEditCmd) @@ -410,9 +408,8 @@ There are three ways to define the creation parameters: s3CreateCmd.Flags().StringVar(&cloud.StorageS3Spec.Versioning.Status, "versioning-status", "", "Versioning status (disabled, enabled, suspended)") // Common flags for other means to define parameters - addInitParameterFileFlag(s3CreateCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/region/{regionName}/storage", "post", cloud.CloudStorageS3CreationExample, nil) + addParameterFileFlags(s3CreateCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/region/{regionName}/storage", "post", cloud.CloudStorageS3CreationExample, nil) addInteractiveEditorFlag(s3CreateCmd) - addFromFileFlag(s3CreateCmd) s3CreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor") return s3CreateCmd diff --git a/internal/cmd/cloud_user.go b/internal/cmd/cloud_user.go index eab064dc..e3da818b 100644 --- a/internal/cmd/cloud_user.go +++ b/internal/cmd/cloud_user.go @@ -39,9 +39,8 @@ func initCloudUserCommand(cloudCmd *cobra.Command) { } userCreateCmd.Flags().StringVar(&cloud.UserSpec.Description, "description", "", "Description of the user") userCreateCmd.Flags().StringArrayVar(&cloud.UserSpec.Roles, "roles", nil, "Roles assigned to the user") - addInitParameterFileFlag(userCreateCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/user", "post", cloud.UserCreateExample, nil) + addParameterFileFlags(userCreateCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/user", "post", cloud.UserCreateExample, nil) addInteractiveEditorFlag(userCreateCmd) - addFromFileFlag(userCreateCmd) userCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor") userCmd.AddCommand(userCreateCmd) @@ -73,9 +72,8 @@ func initCloudUserCommand(cloudCmd *cobra.Command) { Args: cobra.ExactArgs(1), } s3PolicyCreateCmd.Flags().StringVar(&cloud.StorageS3ContainerPolicySpec.Policy, "policy", "", "Policy in JSON format") - addInitParameterFileFlag(s3PolicyCreateCmd, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/user/{userId}/policy", "post", cloud.CloudStorageS3ContainerPolicyExample, nil) + addParameterFileFlags(s3PolicyCreateCmd, false, assets.CloudOpenapiSchema, "/cloud/project/{serviceName}/user/{userId}/policy", "post", cloud.CloudStorageS3ContainerPolicyExample, nil) addInteractiveEditorFlag(s3PolicyCreateCmd) - addFromFileFlag(s3PolicyCreateCmd) s3PolicyCreateCmd.MarkFlagsMutuallyExclusive("policy", "from-file", "editor") s3PolicyCmd.AddCommand(s3PolicyCreateCmd) diff --git a/internal/cmd/domainzone.go b/internal/cmd/domainzone.go index 3949eea2..d131e910 100644 --- a/internal/cmd/domainzone.go +++ b/internal/cmd/domainzone.go @@ -74,9 +74,8 @@ func init() { domainZoneRecordPostCmd.Flags().StringVar(&domainzone.CreateRecordSpec.Target, "target", "", "Target of the record") domainZoneRecordPostCmd.Flags().IntVar(&domainzone.CreateRecordSpec.TTL, "ttl", 0, "TTL of the record") - addInitParameterFileFlag(domainZoneRecordPostCmd, assets.DomainOpenapiSchema, "/domain/zone/{zoneName}/record", "post", domainzone.RecordCreateExample, nil) + addParameterFileFlags(domainZoneRecordPostCmd, false, assets.DomainOpenapiSchema, "/domain/zone/{zoneName}/record", "post", domainzone.RecordCreateExample, nil) addInteractiveEditorFlag(domainZoneRecordPostCmd) - addFromFileFlag(domainZoneRecordPostCmd) domainZoneRecordPostCmd.MarkFlagsMutuallyExclusive("from-file", "editor") domainZoneRecordCmd.AddCommand(domainZoneRecordPostCmd) @@ -91,9 +90,8 @@ func init() { domainZoneRecordPutCmd.Flags().StringVar(&domainzone.UpdateRecordSpec.Target, "target", "", "New target to apply") domainZoneRecordPutCmd.Flags().IntVar(&domainzone.UpdateRecordSpec.TTL, "ttl", 0, "New TTL to apply") - addInitParameterFileFlag(domainZoneRecordPutCmd, assets.DomainOpenapiSchema, "/domain/zone/{zoneName}/record/{id}", "put", domainzone.RecordUpdateExample, nil) + addParameterFileFlags(domainZoneRecordPutCmd, false, assets.DomainOpenapiSchema, "/domain/zone/{zoneName}/record/{id}", "put", domainzone.RecordUpdateExample, nil) addInteractiveEditorFlag(domainZoneRecordPutCmd) - addFromFileFlag(domainZoneRecordPutCmd) domainZoneRecordPutCmd.MarkFlagsMutuallyExclusive("from-file", "editor") domainZoneRecordCmd.AddCommand(domainZoneRecordPutCmd) diff --git a/internal/cmd/emaildomain.go b/internal/cmd/emaildomain.go index be6583dd..22de9e67 100644 --- a/internal/cmd/emaildomain.go +++ b/internal/cmd/emaildomain.go @@ -69,9 +69,8 @@ func init() { createRedirectionCmd.Flags().StringVar(&emaildomain.RedirectionSpec.To, "to", "", "Destination email address") createRedirectionCmd.Flags().BoolVar(&emaildomain.RedirectionSpec.LocalCopy, "local-copy", false, "Keep a local copy of the email") - addInitParameterFileFlag(createRedirectionCmd, assets.EmaildomainOpenapiSchema, "/email/domain/{serviceName}/redirection", "post", emaildomain.RedirectionCreateExample, nil) + addParameterFileFlags(createRedirectionCmd, false, assets.EmaildomainOpenapiSchema, "/email/domain/{serviceName}/redirection", "post", emaildomain.RedirectionCreateExample, nil) addInteractiveEditorFlag(createRedirectionCmd) - addFromFileFlag(createRedirectionCmd) createRedirectionCmd.MarkFlagsMutuallyExclusive("from-file", "editor") emaildomainRedirectionCmd.AddCommand(createRedirectionCmd) diff --git a/internal/cmd/iam.go b/internal/cmd/iam.go index ba61bd5f..682bfe77 100644 --- a/internal/cmd/iam.go +++ b/internal/cmd/iam.go @@ -300,9 +300,8 @@ There are three ways to define the creation parameters: userCreateCmd.Flags().StringVar(&iam.UserSpec.Type, "type", "", "Type of the user (ROOT, SERVICE, USER)") // Common flags for other means to define parameters - addInitParameterFileFlag(userCreateCmd, assets.MeOpenapiSchema, "/me/identity/user", "post", iam.UserCreateExample, nil) + addParameterFileFlags(userCreateCmd, false, assets.MeOpenapiSchema, "/me/identity/user", "post", iam.UserCreateExample, nil) addInteractiveEditorFlag(userCreateCmd) - addFromFileFlag(userCreateCmd) userCreateCmd.MarkFlagsMutuallyExclusive("from-file", "editor") return userCreateCmd @@ -358,9 +357,8 @@ There are three ways to define the editing parameters: userEditCmd.Flags().StringVar(&iam.UserSpec.Group, "group", "", "Group of the user") // Common flags for other means to define parameters - addInitParameterFileFlag(userEditCmd, assets.MeOpenapiSchema, "/me/identity/user", "post", iam.UserEditExample, nil) + addParameterFileFlags(userEditCmd, false, assets.MeOpenapiSchema, "/me/identity/user", "post", iam.UserEditExample, nil) addInteractiveEditorFlag(userEditCmd) - addFromFileFlag(userEditCmd) userEditCmd.MarkFlagsMutuallyExclusive("from-file", "editor") return userEditCmd diff --git a/internal/cmd/parameter.go b/internal/cmd/parameter.go index 1a1f07df..d7060b5a 100644 --- a/internal/cmd/parameter.go +++ b/internal/cmd/parameter.go @@ -112,14 +112,16 @@ func addInteractiveEditorFlag(cmd *cobra.Command) { applyInputFlagsTemplate(cmd) } -func addFromFileFlag(cmd *cobra.Command) { +func addParameterFileFlags(cmd *cobra.Command, skipInit bool, openapiSchema []byte, path, method, defaultContent string, replaceValueFn func(*cobra.Command, []string) (map[string]any, error)) { + if runtime.GOARCH == "wasm" && runtime.GOOS == "js" { + return + } + cmd.Flags().StringVar(&flags.ParametersFile, "from-file", "", "File containing parameters") markAsInputFlag(cmd, "from-file") applyInputFlagsTemplate(cmd) -} -func addInitParameterFileFlag(cmd *cobra.Command, openapiSchema []byte, path, method, defaultContent string, replaceValueFn func(*cobra.Command, []string) (map[string]any, error)) { - if runtime.GOARCH == "wasm" && runtime.GOOS == "js" { + if skipInit { return } @@ -246,9 +248,8 @@ There are three ways to define the creation parameters: } // Common flags for other means to define parameters - addInitParameterFileFlag(createCmd, openAPISchema, path, "post", bodyExample, nil) + addParameterFileFlags(createCmd, false, openAPISchema, path, "post", bodyExample, nil) addInteractiveEditorFlag(createCmd) - addFromFileFlag(createCmd) createCmd.MarkFlagsMutuallyExclusive("from-file", "editor") return createCmd diff --git a/internal/cmd/parameter_test.go b/internal/cmd/parameter_test.go index 6ccd805f..f908bbde 100644 --- a/internal/cmd/parameter_test.go +++ b/internal/cmd/parameter_test.go @@ -147,10 +147,10 @@ func TestCreateCmdUsageTemplate_NoInputFlags(t *testing.T) { } } -func TestAddFromFileFlag_AnnotatesAndAppliesTemplate(t *testing.T) { +func TestAddParameterFileFlags_FromFileFlag(t *testing.T) { cmd := &cobra.Command{Use: "create", Run: func(*cobra.Command, []string) {}} - addFromFileFlag(cmd) + addParameterFileFlags(cmd, true, nil, "", "", "", nil) f := cmd.Flags().Lookup("from-file") if f == nil { @@ -175,10 +175,10 @@ func TestAddInteractiveEditorFlag_AnnotatesAndAppliesTemplate(t *testing.T) { } } -func TestAddInitParameterFileFlag_AnnotatesFlags(t *testing.T) { +func TestAddParameterFileFlags_InitFlags(t *testing.T) { cmd := &cobra.Command{Use: "create", Run: func(*cobra.Command, []string) {}} - addInitParameterFileFlag(cmd, nil, "/test", "post", "{}", nil) + addParameterFileFlags(cmd, false, nil, "/test", "post", "{}", nil) for _, name := range []string{"init-file", "replace"} { f := cmd.Flags().Lookup(name) diff --git a/internal/cmd/vps.go b/internal/cmd/vps.go index 4be9c997..c40b35a1 100644 --- a/internal/cmd/vps.go +++ b/internal/cmd/vps.go @@ -357,9 +357,8 @@ func init() { vpsReinstallCmd.Flags().BoolVar(&vps.VpsReinstallSpec.InstallRTM, "install-rtm", false, "Install RTM during reinstallation") vpsReinstallCmd.Flags().StringVar(&vps.VpsReinstallSpec.PublicSshKey, "public-ssh-key", "", "Public SSH key to pre-install on your VPS") vpsReinstallCmd.Flags().StringVar(&vps.VpsReinstallSpec.SshKey, "ssh-key", "", "SSH key name to pre-install on your VPS (name can be found running 'ovhcloud account ssh-key list')") - addInitParameterFileFlag(vpsReinstallCmd, assets.VpsOpenapiSchema, "/vps/{serviceName}/rebuild", "post", vps.VpsReinstallExample, nil) + addParameterFileFlags(vpsReinstallCmd, false, assets.VpsOpenapiSchema, "/vps/{serviceName}/rebuild", "post", vps.VpsReinstallExample, nil) addInteractiveEditorFlag(vpsReinstallCmd) - addFromFileFlag(vpsReinstallCmd) if !(runtime.GOARCH == "wasm" && runtime.GOOS == "js") { vpsReinstallCmd.Flags().BoolVar(&vps.VpsImageViaInteractiveSelector, "image-selector", false, "Use the interactive image selector") vpsReinstallCmd.Flags().BoolVar(&vps.VpsSSHKeyViaInteractiveSelector, "ssh-key-selector", false, "Use the interactive SSH key selector")