mirror of https://github.com/databricks/cli.git
Merge remote-tracking branch 'origin' into fs-rm
This commit is contained in:
commit
188ed170db
|
@ -26,6 +26,7 @@ var Cmd = &cobra.Command{
|
|||
{{- end}}
|
||||
}
|
||||
|
||||
{{- $serviceName := .KebabName -}}
|
||||
{{range .Methods}}
|
||||
|
||||
{{- $excludes := list "put-secret" -}}
|
||||
|
@ -62,11 +63,14 @@ func init() {
|
|||
{{- 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")) -}}
|
||||
{{- $hasSinglePosArg := and $hasPosArgs (eq 1 (len .Request.RequiredFields)) -}}
|
||||
{{- $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"))) -}}
|
||||
{{- $hasRequiredArgs := and (not $hasIdPrompt) $hasPosArgs -}}
|
||||
var {{.CamelName}}Cmd = &cobra.Command{
|
||||
|
|
|
@ -47,7 +47,14 @@ var createCmd = &cobra.Command{
|
|||
pre-existing VPC and subnets.`,
|
||||
|
||||
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) {
|
||||
ctx := cmd.Context()
|
||||
a := root.AccountClient(ctx)
|
||||
|
@ -57,23 +64,6 @@ var createCmd = &cobra.Command{
|
|||
return err
|
||||
}
|
||||
} 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]
|
||||
}
|
||||
|
||||
|
|
|
@ -54,7 +54,14 @@ var createCmd = &cobra.Command{
|
|||
[endpoint service]: https://docs.aws.amazon.com/vpc/latest/privatelink/privatelink-share-your-services.html`,
|
||||
|
||||
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) {
|
||||
ctx := cmd.Context()
|
||||
a := root.AccountClient(ctx)
|
||||
|
@ -64,23 +71,6 @@ var createCmd = &cobra.Command{
|
|||
return err
|
||||
}
|
||||
} 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]
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,14 @@ var createCmd = &cobra.Command{
|
|||
workspace becomes available when the status changes to RUNNING.`,
|
||||
|
||||
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) {
|
||||
ctx := cmd.Context()
|
||||
a := root.AccountClient(ctx)
|
||||
|
@ -83,23 +90,6 @@ var createCmd = &cobra.Command{
|
|||
return err
|
||||
}
|
||||
} 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]
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,14 @@ var createCmd = &cobra.Command{
|
|||
Creates a new policy with prescribed settings.`,
|
||||
|
||||
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) {
|
||||
ctx := cmd.Context()
|
||||
w := root.WorkspaceClient(ctx)
|
||||
|
@ -77,23 +84,6 @@ var createCmd = &cobra.Command{
|
|||
return err
|
||||
}
|
||||
} 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]
|
||||
}
|
||||
|
||||
|
|
|
@ -158,7 +158,14 @@ var createCmd = &cobra.Command{
|
|||
informative error message.`,
|
||||
|
||||
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) {
|
||||
ctx := cmd.Context()
|
||||
w := root.WorkspaceClient(ctx)
|
||||
|
@ -168,23 +175,6 @@ var createCmd = &cobra.Command{
|
|||
return err
|
||||
}
|
||||
} 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]
|
||||
}
|
||||
|
||||
|
|
|
@ -49,7 +49,14 @@ var createCmd = &cobra.Command{
|
|||
DELETE endpoint to delete existing credentials.`,
|
||||
|
||||
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) {
|
||||
ctx := cmd.Context()
|
||||
w := root.WorkspaceClient(ctx)
|
||||
|
@ -59,23 +66,6 @@ var createCmd = &cobra.Command{
|
|||
return err
|
||||
}
|
||||
} 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]
|
||||
}
|
||||
|
||||
|
|
|
@ -178,7 +178,14 @@ var getStatusCmd = &cobra.Command{
|
|||
call returns an error RESOURCE_DOES_NOT_EXIST.`,
|
||||
|
||||
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) {
|
||||
ctx := cmd.Context()
|
||||
w := root.WorkspaceClient(ctx)
|
||||
|
@ -188,23 +195,6 @@ var getStatusCmd = &cobra.Command{
|
|||
return err
|
||||
}
|
||||
} 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]
|
||||
}
|
||||
|
||||
|
@ -244,7 +234,14 @@ var importCmd = &cobra.Command{
|
|||
use DBC format to import a directory.`,
|
||||
|
||||
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) {
|
||||
ctx := cmd.Context()
|
||||
w := root.WorkspaceClient(ctx)
|
||||
|
@ -254,23 +251,6 @@ var importCmd = &cobra.Command{
|
|||
return err
|
||||
}
|
||||
} 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]
|
||||
}
|
||||
|
||||
|
|
|
@ -33,3 +33,8 @@ func TestAccClustersGet(t *testing.T) {
|
|||
assert.Contains(t, outStr, fmt.Sprintf(`"cluster_id":"%s"`, clusterId))
|
||||
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")
|
||||
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