mirror of https://github.com/databricks/cli.git
Do not generate prompts for certain commands (#438)
## Changes Some of the commands do not support prompts, for example `workspace get-status` but we were wrongly suggesting customers some option. Quick fix for this is not to provide prompts for these known commands. Note: it uses a method from this PR in Go SDK https://github.com/databricks/databricks-sdk-go/pull/416 ## Tests Running `workspace get-status` Before ``` andrew.nester@HFW9Y94129 multiples-tasks % ../../cli/cli workspace get-status Error: Path () doesn't start with '/' ``` After ``` andrew.nester@HFW9Y94129 multiples-tasks % ../../cli/cli workspace get-status Error: accepts 1 arg(s), received 0 ```
This commit is contained in:
parent
6ff00122ad
commit
df3f5863c7
|
@ -26,6 +26,7 @@ var Cmd = &cobra.Command{
|
||||||
{{- end}}
|
{{- end}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{{- $serviceName := .KebabName -}}
|
||||||
{{range .Methods}}
|
{{range .Methods}}
|
||||||
|
|
||||||
{{- $excludes := list "put-secret" -}}
|
{{- $excludes := list "put-secret" -}}
|
||||||
|
@ -62,11 +63,14 @@ func init() {
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
}
|
}
|
||||||
|
{{- $excludeFromPrompts := list "workspace get-status" -}}
|
||||||
|
{{- $fullCommandName := (print $serviceName " " .KebabName) -}}
|
||||||
|
{{- $noPrompt := or .IsCrudCreate (in $excludeFromPrompts $fullCommandName) }}
|
||||||
|
|
||||||
{{ $hasPosArgs := and .Request (or .Request.IsAllRequiredFieldsPrimitive (eq .PascalName "RunNow")) -}}
|
{{ $hasPosArgs := and .Request (or .Request.IsAllRequiredFieldsPrimitive (eq .PascalName "RunNow")) -}}
|
||||||
{{- $hasSinglePosArg := and $hasPosArgs (eq 1 (len .Request.RequiredFields)) -}}
|
{{- $hasSinglePosArg := and $hasPosArgs (eq 1 (len .Request.RequiredFields)) -}}
|
||||||
{{- $serviceHasNamedIdMap := and (and .Service.List .Service.List.NamedIdMap) (not (eq .PascalName "List")) -}}
|
{{- $serviceHasNamedIdMap := and (and .Service.List .Service.List.NamedIdMap) (not (eq .PascalName "List")) -}}
|
||||||
{{- $hasIdPrompt := and $hasSinglePosArg $serviceHasNamedIdMap -}}
|
{{- $hasIdPrompt := and (not $noPrompt) (and $hasSinglePosArg $serviceHasNamedIdMap) -}}
|
||||||
{{- $wait := and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) -}}
|
{{- $wait := and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) -}}
|
||||||
{{- $hasRequiredArgs := and (not $hasIdPrompt) $hasPosArgs -}}
|
{{- $hasRequiredArgs := and (not $hasIdPrompt) $hasPosArgs -}}
|
||||||
var {{.CamelName}}Cmd = &cobra.Command{
|
var {{.CamelName}}Cmd = &cobra.Command{
|
||||||
|
|
|
@ -47,7 +47,14 @@ var createCmd = &cobra.Command{
|
||||||
pre-existing VPC and subnets.`,
|
pre-existing VPC and subnets.`,
|
||||||
|
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
PreRunE: root.MustAccountClient,
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
check := cobra.ExactArgs(1)
|
||||||
|
if cmd.Flags().Changed("json") {
|
||||||
|
check = cobra.ExactArgs(0)
|
||||||
|
}
|
||||||
|
return check(cmd, args)
|
||||||
|
},
|
||||||
|
PreRunE: root.MustAccountClient,
|
||||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
a := root.AccountClient(ctx)
|
a := root.AccountClient(ctx)
|
||||||
|
@ -57,23 +64,6 @@ var createCmd = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(args) == 0 {
|
|
||||||
promptSpinner := cmdio.Spinner(ctx)
|
|
||||||
promptSpinner <- "No NETWORK_NAME argument specified. Loading names for Networks drop-down."
|
|
||||||
names, err := a.Networks.NetworkNetworkNameToNetworkIdMap(ctx)
|
|
||||||
close(promptSpinner)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to load names for Networks drop-down. Please manually specify required arguments. Original error: %w", err)
|
|
||||||
}
|
|
||||||
id, err := cmdio.Select(ctx, names, "The human-readable name of the network configuration")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
args = append(args, id)
|
|
||||||
}
|
|
||||||
if len(args) != 1 {
|
|
||||||
return fmt.Errorf("expected to have the human-readable name of the network configuration")
|
|
||||||
}
|
|
||||||
createReq.NetworkName = args[0]
|
createReq.NetworkName = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,14 @@ var createCmd = &cobra.Command{
|
||||||
[endpoint service]: https://docs.aws.amazon.com/vpc/latest/privatelink/privatelink-share-your-services.html`,
|
[endpoint service]: https://docs.aws.amazon.com/vpc/latest/privatelink/privatelink-share-your-services.html`,
|
||||||
|
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
PreRunE: root.MustAccountClient,
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
check := cobra.ExactArgs(1)
|
||||||
|
if cmd.Flags().Changed("json") {
|
||||||
|
check = cobra.ExactArgs(0)
|
||||||
|
}
|
||||||
|
return check(cmd, args)
|
||||||
|
},
|
||||||
|
PreRunE: root.MustAccountClient,
|
||||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
a := root.AccountClient(ctx)
|
a := root.AccountClient(ctx)
|
||||||
|
@ -64,23 +71,6 @@ var createCmd = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(args) == 0 {
|
|
||||||
promptSpinner := cmdio.Spinner(ctx)
|
|
||||||
promptSpinner <- "No VPC_ENDPOINT_NAME argument specified. Loading names for Vpc Endpoints drop-down."
|
|
||||||
names, err := a.VpcEndpoints.VpcEndpointVpcEndpointNameToVpcEndpointIdMap(ctx)
|
|
||||||
close(promptSpinner)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to load names for Vpc Endpoints drop-down. Please manually specify required arguments. Original error: %w", err)
|
|
||||||
}
|
|
||||||
id, err := cmdio.Select(ctx, names, "The human-readable name of the storage configuration")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
args = append(args, id)
|
|
||||||
}
|
|
||||||
if len(args) != 1 {
|
|
||||||
return fmt.Errorf("expected to have the human-readable name of the storage configuration")
|
|
||||||
}
|
|
||||||
createReq.VpcEndpointName = args[0]
|
createReq.VpcEndpointName = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,14 @@ var createCmd = &cobra.Command{
|
||||||
workspace becomes available when the status changes to RUNNING.`,
|
workspace becomes available when the status changes to RUNNING.`,
|
||||||
|
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
PreRunE: root.MustAccountClient,
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
check := cobra.ExactArgs(1)
|
||||||
|
if cmd.Flags().Changed("json") {
|
||||||
|
check = cobra.ExactArgs(0)
|
||||||
|
}
|
||||||
|
return check(cmd, args)
|
||||||
|
},
|
||||||
|
PreRunE: root.MustAccountClient,
|
||||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
a := root.AccountClient(ctx)
|
a := root.AccountClient(ctx)
|
||||||
|
@ -83,23 +90,6 @@ var createCmd = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(args) == 0 {
|
|
||||||
promptSpinner := cmdio.Spinner(ctx)
|
|
||||||
promptSpinner <- "No WORKSPACE_NAME argument specified. Loading names for Workspaces drop-down."
|
|
||||||
names, err := a.Workspaces.WorkspaceWorkspaceNameToWorkspaceIdMap(ctx)
|
|
||||||
close(promptSpinner)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to load names for Workspaces drop-down. Please manually specify required arguments. Original error: %w", err)
|
|
||||||
}
|
|
||||||
id, err := cmdio.Select(ctx, names, "The workspace's human-readable name")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
args = append(args, id)
|
|
||||||
}
|
|
||||||
if len(args) != 1 {
|
|
||||||
return fmt.Errorf("expected to have the workspace's human-readable name")
|
|
||||||
}
|
|
||||||
createReq.WorkspaceName = args[0]
|
createReq.WorkspaceName = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,14 @@ var createCmd = &cobra.Command{
|
||||||
Creates a new policy with prescribed settings.`,
|
Creates a new policy with prescribed settings.`,
|
||||||
|
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
PreRunE: root.MustWorkspaceClient,
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
check := cobra.ExactArgs(1)
|
||||||
|
if cmd.Flags().Changed("json") {
|
||||||
|
check = cobra.ExactArgs(0)
|
||||||
|
}
|
||||||
|
return check(cmd, args)
|
||||||
|
},
|
||||||
|
PreRunE: root.MustWorkspaceClient,
|
||||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
w := root.WorkspaceClient(ctx)
|
w := root.WorkspaceClient(ctx)
|
||||||
|
@ -77,23 +84,6 @@ var createCmd = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(args) == 0 {
|
|
||||||
promptSpinner := cmdio.Spinner(ctx)
|
|
||||||
promptSpinner <- "No NAME argument specified. Loading names for Cluster Policies drop-down."
|
|
||||||
names, err := w.ClusterPolicies.PolicyNameToPolicyIdMap(ctx, compute.ListClusterPoliciesRequest{})
|
|
||||||
close(promptSpinner)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to load names for Cluster Policies drop-down. Please manually specify required arguments. Original error: %w", err)
|
|
||||||
}
|
|
||||||
id, err := cmdio.Select(ctx, names, "Cluster Policy name requested by the user")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
args = append(args, id)
|
|
||||||
}
|
|
||||||
if len(args) != 1 {
|
|
||||||
return fmt.Errorf("expected to have cluster policy name requested by the user")
|
|
||||||
}
|
|
||||||
createReq.Name = args[0]
|
createReq.Name = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,14 @@ var createCmd = &cobra.Command{
|
||||||
informative error message.`,
|
informative error message.`,
|
||||||
|
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
PreRunE: root.MustWorkspaceClient,
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
check := cobra.ExactArgs(1)
|
||||||
|
if cmd.Flags().Changed("json") {
|
||||||
|
check = cobra.ExactArgs(0)
|
||||||
|
}
|
||||||
|
return check(cmd, args)
|
||||||
|
},
|
||||||
|
PreRunE: root.MustWorkspaceClient,
|
||||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
w := root.WorkspaceClient(ctx)
|
w := root.WorkspaceClient(ctx)
|
||||||
|
@ -168,23 +175,6 @@ var createCmd = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(args) == 0 {
|
|
||||||
promptSpinner := cmdio.Spinner(ctx)
|
|
||||||
promptSpinner <- "No SPARK_VERSION argument specified. Loading names for Clusters drop-down."
|
|
||||||
names, err := w.Clusters.ClusterInfoClusterNameToClusterIdMap(ctx, compute.ListClustersRequest{})
|
|
||||||
close(promptSpinner)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to load names for Clusters drop-down. Please manually specify required arguments. Original error: %w", err)
|
|
||||||
}
|
|
||||||
id, err := cmdio.Select(ctx, names, "The Spark version of the cluster, e.g")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
args = append(args, id)
|
|
||||||
}
|
|
||||||
if len(args) != 1 {
|
|
||||||
return fmt.Errorf("expected to have the spark version of the cluster, e.g")
|
|
||||||
}
|
|
||||||
createReq.SparkVersion = args[0]
|
createReq.SparkVersion = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,14 @@ var createCmd = &cobra.Command{
|
||||||
DELETE endpoint to delete existing credentials.`,
|
DELETE endpoint to delete existing credentials.`,
|
||||||
|
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
PreRunE: root.MustWorkspaceClient,
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
check := cobra.ExactArgs(1)
|
||||||
|
if cmd.Flags().Changed("json") {
|
||||||
|
check = cobra.ExactArgs(0)
|
||||||
|
}
|
||||||
|
return check(cmd, args)
|
||||||
|
},
|
||||||
|
PreRunE: root.MustWorkspaceClient,
|
||||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
w := root.WorkspaceClient(ctx)
|
w := root.WorkspaceClient(ctx)
|
||||||
|
@ -59,23 +66,6 @@ var createCmd = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(args) == 0 {
|
|
||||||
promptSpinner := cmdio.Spinner(ctx)
|
|
||||||
promptSpinner <- "No GIT_PROVIDER argument specified. Loading names for Git Credentials drop-down."
|
|
||||||
names, err := w.GitCredentials.CredentialInfoGitProviderToCredentialIdMap(ctx)
|
|
||||||
close(promptSpinner)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to load names for Git Credentials drop-down. Please manually specify required arguments. Original error: %w", err)
|
|
||||||
}
|
|
||||||
id, err := cmdio.Select(ctx, names, "Git provider")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
args = append(args, id)
|
|
||||||
}
|
|
||||||
if len(args) != 1 {
|
|
||||||
return fmt.Errorf("expected to have git provider")
|
|
||||||
}
|
|
||||||
createReq.GitProvider = args[0]
|
createReq.GitProvider = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,14 @@ var getStatusCmd = &cobra.Command{
|
||||||
call returns an error RESOURCE_DOES_NOT_EXIST.`,
|
call returns an error RESOURCE_DOES_NOT_EXIST.`,
|
||||||
|
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
PreRunE: root.MustWorkspaceClient,
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
check := cobra.ExactArgs(1)
|
||||||
|
if cmd.Flags().Changed("json") {
|
||||||
|
check = cobra.ExactArgs(0)
|
||||||
|
}
|
||||||
|
return check(cmd, args)
|
||||||
|
},
|
||||||
|
PreRunE: root.MustWorkspaceClient,
|
||||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
w := root.WorkspaceClient(ctx)
|
w := root.WorkspaceClient(ctx)
|
||||||
|
@ -188,23 +195,6 @@ var getStatusCmd = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(args) == 0 {
|
|
||||||
promptSpinner := cmdio.Spinner(ctx)
|
|
||||||
promptSpinner <- "No PATH argument specified. Loading names for Workspace drop-down."
|
|
||||||
names, err := w.Workspace.ObjectInfoPathToObjectIdMap(ctx, workspace.ListWorkspaceRequest{})
|
|
||||||
close(promptSpinner)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to load names for Workspace drop-down. Please manually specify required arguments. Original error: %w", err)
|
|
||||||
}
|
|
||||||
id, err := cmdio.Select(ctx, names, "The absolute path of the notebook or directory")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
args = append(args, id)
|
|
||||||
}
|
|
||||||
if len(args) != 1 {
|
|
||||||
return fmt.Errorf("expected to have the absolute path of the notebook or directory")
|
|
||||||
}
|
|
||||||
getStatusReq.Path = args[0]
|
getStatusReq.Path = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +234,14 @@ var importCmd = &cobra.Command{
|
||||||
use DBC format to import a directory.`,
|
use DBC format to import a directory.`,
|
||||||
|
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
PreRunE: root.MustWorkspaceClient,
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
|
check := cobra.ExactArgs(1)
|
||||||
|
if cmd.Flags().Changed("json") {
|
||||||
|
check = cobra.ExactArgs(0)
|
||||||
|
}
|
||||||
|
return check(cmd, args)
|
||||||
|
},
|
||||||
|
PreRunE: root.MustWorkspaceClient,
|
||||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
w := root.WorkspaceClient(ctx)
|
w := root.WorkspaceClient(ctx)
|
||||||
|
@ -254,23 +251,6 @@ var importCmd = &cobra.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if len(args) == 0 {
|
|
||||||
promptSpinner := cmdio.Spinner(ctx)
|
|
||||||
promptSpinner <- "No PATH argument specified. Loading names for Workspace drop-down."
|
|
||||||
names, err := w.Workspace.ObjectInfoPathToObjectIdMap(ctx, workspace.ListWorkspaceRequest{})
|
|
||||||
close(promptSpinner)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to load names for Workspace drop-down. Please manually specify required arguments. Original error: %w", err)
|
|
||||||
}
|
|
||||||
id, err := cmdio.Select(ctx, names, "The absolute path of the object or directory")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
args = append(args, id)
|
|
||||||
}
|
|
||||||
if len(args) != 1 {
|
|
||||||
return fmt.Errorf("expected to have the absolute path of the object or directory")
|
|
||||||
}
|
|
||||||
importReq.Path = args[0]
|
importReq.Path = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,3 +33,8 @@ func TestAccClustersGet(t *testing.T) {
|
||||||
assert.Contains(t, outStr, fmt.Sprintf(`"cluster_id":"%s"`, clusterId))
|
assert.Contains(t, outStr, fmt.Sprintf(`"cluster_id":"%s"`, clusterId))
|
||||||
assert.Equal(t, "", stderr.String())
|
assert.Equal(t, "", stderr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClusterCreateErrorWhenNoArguments(t *testing.T) {
|
||||||
|
_, _, err := RequireErrorRun(t, "clusters", "create")
|
||||||
|
assert.Equal(t, "accepts 1 arg(s), received 0", err.Error())
|
||||||
|
}
|
||||||
|
|
|
@ -22,3 +22,8 @@ func TestWorkpaceListErrorWhenNoArguments(t *testing.T) {
|
||||||
_, _, err := RequireErrorRun(t, "workspace", "list")
|
_, _, err := RequireErrorRun(t, "workspace", "list")
|
||||||
assert.Equal(t, "accepts 1 arg(s), received 0", err.Error())
|
assert.Equal(t, "accepts 1 arg(s), received 0", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestWorkpaceGetStatusErrorWhenNoArguments(t *testing.T) {
|
||||||
|
_, _, err := RequireErrorRun(t, "workspace", "get-status")
|
||||||
|
assert.Equal(t, "accepts 1 arg(s), received 0", err.Error())
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue