mirror of https://github.com/databricks/cli.git
Do not prompt for List methods (#411)
## Changes Do not prompt for List methods ## Tests Running ``` cli workspace list ``` Before ``` cli workspace list Error: Path () doesn't start with '/' ``` After ``` cli workspace list Error: accepts 1 arg(s), received 0 ```
This commit is contained in:
parent
3c4d6f637f
commit
aed6450baf
|
@ -60,7 +60,7 @@ func init() {
|
|||
|
||||
{{ $hasPosArgs := and .Request (or .Request.IsAllRequiredFieldsPrimitive (eq .PascalName "RunNow")) -}}
|
||||
{{- $hasSinglePosArg := and $hasPosArgs (eq 1 (len .Request.RequiredFields)) -}}
|
||||
{{- $serviceHasNamedIdMap := and .Service.List .Service.List.NamedIdMap -}}
|
||||
{{- $serviceHasNamedIdMap := and (and .Service.List .Service.List.NamedIdMap) (not (eq .PascalName "List")) -}}
|
||||
{{- $hasIdPrompt := and $hasSinglePosArg $serviceHasNamedIdMap -}}
|
||||
{{- $wait := and .Wait (and (not .IsCrudRead) (not (eq .SnakeName "get_run"))) -}}
|
||||
{{- $hasRequiredArgs := and (not $hasIdPrompt) $hasPosArgs -}}
|
||||
|
|
|
@ -214,6 +214,13 @@ var listCmd = &cobra.Command{
|
|||
no guarantee of a specific ordering of the elements in the array.`,
|
||||
|
||||
Annotations: map[string]string{},
|
||||
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()
|
||||
|
@ -224,20 +231,6 @@ var listCmd = &cobra.Command{
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
if len(args) == 0 {
|
||||
names, err := w.Schemas.SchemaInfoNameToFullNameMap(ctx, catalog.ListSchemasRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id, err := cmdio.Select(ctx, names, "Parent catalog for schemas of interest")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
args = append(args, id)
|
||||
}
|
||||
if len(args) != 1 {
|
||||
return fmt.Errorf("expected to have parent catalog for schemas of interest")
|
||||
}
|
||||
listReq.CatalogName = args[0]
|
||||
}
|
||||
|
||||
|
|
|
@ -294,6 +294,13 @@ var listCmd = &cobra.Command{
|
|||
RESOURCE_DOES_NOT_EXIST.`,
|
||||
|
||||
Annotations: map[string]string{},
|
||||
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()
|
||||
|
@ -304,20 +311,6 @@ var listCmd = &cobra.Command{
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
if len(args) == 0 {
|
||||
names, err := w.Workspace.ObjectInfoPathToObjectIdMap(ctx, workspace.ListWorkspaceRequest{})
|
||||
if err != nil {
|
||||
return 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")
|
||||
}
|
||||
listReq.Path = args[0]
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
_ "github.com/databricks/cli/cmd/workspace"
|
||||
)
|
||||
|
||||
var clusterId string
|
||||
|
@ -24,7 +22,6 @@ func TestAccClustersList(t *testing.T) {
|
|||
|
||||
idRegExp := regexp.MustCompile(`[0-9]{4}\-[0-9]{6}-[a-z0-9]{8}`)
|
||||
clusterId = idRegExp.FindString(outStr)
|
||||
fmt.Println(clusterId)
|
||||
assert.NotEmpty(t, clusterId)
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@ import (
|
|||
"github.com/databricks/cli/cmd/root"
|
||||
_ "github.com/databricks/cli/cmd/version"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
_ "github.com/databricks/cli/cmd/workspace"
|
||||
)
|
||||
|
||||
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
|
|
|
@ -4,8 +4,6 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
_ "github.com/databricks/cli/cmd/workspace"
|
||||
)
|
||||
|
||||
func TestSecretsCreateScopeErrWhenNoArguments(t *testing.T) {
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package internal
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAccWorkspaceList(t *testing.T) {
|
||||
t.Log(GetEnvOrSkipTest(t, "CLOUD_ENV"))
|
||||
|
||||
stdout, stderr := RequireSuccessfulRun(t, "workspace", "list", "/")
|
||||
outStr := stdout.String()
|
||||
assert.Contains(t, outStr, "ID")
|
||||
assert.Contains(t, outStr, "Type")
|
||||
assert.Contains(t, outStr, "Language")
|
||||
assert.Contains(t, outStr, "Path")
|
||||
assert.Equal(t, "", stderr.String())
|
||||
}
|
||||
|
||||
func TestWorkpaceListErrorWhenNoArguments(t *testing.T) {
|
||||
_, _, err := RequireErrorRun(t, "workspace", "list")
|
||||
assert.Equal(t, "accepts 1 arg(s), received 0", err.Error())
|
||||
}
|
Loading…
Reference in New Issue