mirror of https://github.com/databricks/cli.git
cleanup code
This commit is contained in:
parent
a3fbdd33a5
commit
ecb977f4ed
|
@ -235,12 +235,11 @@ See https://docs.databricks.com/en/dev-tools/bundles/templates.html for more inf
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If templatePath refers to a native template, store it's name in a new
|
|
||||||
// variable.
|
|
||||||
nt := getNativeTemplateByName(templatePath)
|
nt := getNativeTemplateByName(templatePath)
|
||||||
templateName := "custom"
|
templateName := "custom"
|
||||||
isTemplateDatabricksOwned := false
|
isTemplateDatabricksOwned := false
|
||||||
if nt != nil {
|
if nt != nil {
|
||||||
|
// If the template is a native template, set it's value.
|
||||||
templateName = templatePath
|
templateName = templatePath
|
||||||
|
|
||||||
// if we have a Git URL for the native template, expand templatePath
|
// if we have a Git URL for the native template, expand templatePath
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"slices"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/databricks/cli/libs/log"
|
"github.com/databricks/cli/libs/log"
|
||||||
|
@ -61,19 +62,6 @@ func Flush(ctx context.Context, apiClient DatabricksApiClient) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// We pass the API client as an arg to mock it in unit tests.
|
|
||||||
// TODO: Cleanup and remove this section.
|
|
||||||
// if apiClient == nil {
|
|
||||||
// var err error
|
|
||||||
|
|
||||||
// // Create API client to make the the telemetry API call.
|
|
||||||
// apiClient, err = client.New(root.WorkspaceClient(ctx).Config)
|
|
||||||
// if err != nil {
|
|
||||||
// log.Debugf(ctx, "error creating API client for telemetry: %v", err)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
resp := &ResponseBody{}
|
resp := &ResponseBody{}
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
"slices"
|
||||||
|
|
||||||
"github.com/databricks/cli/libs/cmdio"
|
"github.com/databricks/cli/libs/cmdio"
|
||||||
"github.com/databricks/cli/libs/jsonschema"
|
"github.com/databricks/cli/libs/jsonschema"
|
||||||
|
@ -279,10 +280,17 @@ func (c *config) validate() error {
|
||||||
func (c *config) enumValues() map[string]string {
|
func (c *config) enumValues() map[string]string {
|
||||||
res := map[string]string{}
|
res := map[string]string{}
|
||||||
for k, p := range c.schema.Properties {
|
for k, p := range c.schema.Properties {
|
||||||
|
if p.Type != jsonschema.StringType {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if p.Enum == nil {
|
if p.Enum == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
res[k] = c.values[k].(string)
|
v := c.values[k]
|
||||||
|
|
||||||
|
if slices.Contains(p.Enum, v) {
|
||||||
|
res[k] = v.(string)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
|
@ -564,3 +564,42 @@ func TestPromptIsSkippedAnyOf(t *testing.T) {
|
||||||
assert.True(t, skip)
|
assert.True(t, skip)
|
||||||
assert.Equal(t, "hello-world", c.values["xyz"])
|
assert.Equal(t, "hello-world", c.values["xyz"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfigEnumValues(t *testing.T) {
|
||||||
|
c := &config{
|
||||||
|
schema: &jsonschema.Schema{
|
||||||
|
Properties: map[string]*jsonschema.Schema{
|
||||||
|
"a": {
|
||||||
|
Type: jsonschema.StringType,
|
||||||
|
},
|
||||||
|
"b": {
|
||||||
|
Type: jsonschema.BooleanType,
|
||||||
|
},
|
||||||
|
"c": {
|
||||||
|
Type: jsonschema.StringType,
|
||||||
|
Enum: []any{"v1", "v2"},
|
||||||
|
},
|
||||||
|
"d": {
|
||||||
|
Type: jsonschema.StringType,
|
||||||
|
Enum: []any{"v3", "v4"},
|
||||||
|
},
|
||||||
|
"e": {
|
||||||
|
Type: jsonschema.StringType,
|
||||||
|
Enum: []any{"v5", "v6"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
values: map[string]any{
|
||||||
|
"a": "w1",
|
||||||
|
"b": false,
|
||||||
|
"c": "v1",
|
||||||
|
"d": "v3",
|
||||||
|
"e": "v7",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Equal(t, map[string]string{
|
||||||
|
"c": "v1",
|
||||||
|
"d": "v3",
|
||||||
|
}, c.enumValues())
|
||||||
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ type TemplateOpts struct {
|
||||||
IsDatabricksOwned bool
|
IsDatabricksOwned bool
|
||||||
// Name of the template. For non-Databricks owned templates, this is set to
|
// Name of the template. For non-Databricks owned templates, this is set to
|
||||||
// custom.
|
// custom.
|
||||||
// TODO: move this enum to the template package.
|
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue