mirror of https://github.com/databricks/cli.git
Compare commits
No commits in common. "26afab2ccb5e5c5a7bc3c9f520c917ec19f46045" and "dd506e23726c57930eadd232f5deebf1ccd1171a" have entirely different histories.
26afab2ccb
...
dd506e2372
|
@ -163,7 +163,7 @@ func (t *translateContext) translateNoOp(literal, localFullPath, localRelPath, r
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *translateContext) retainLocalAbsoluteFilePath(literal, localFullPath, localRelPath, remotePath string) (string, error) {
|
func (t *translateContext) retainLocalAbsoluteFilePath(literal, localFullPath, localRelPath, remotePath string) (string, error) {
|
||||||
info, err := t.b.SyncRoot.Stat(filepath.ToSlash(localRelPath))
|
info, err := t.b.SyncRoot.Stat(localRelPath)
|
||||||
if errors.Is(err, fs.ErrNotExist) {
|
if errors.Is(err, fs.ErrNotExist) {
|
||||||
return "", fmt.Errorf("file %s not found", literal)
|
return "", fmt.Errorf("file %s not found", literal)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,54 +0,0 @@
|
||||||
package mutator_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/databricks/cli/bundle"
|
|
||||||
"github.com/databricks/cli/bundle/config"
|
|
||||||
"github.com/databricks/cli/bundle/config/mutator"
|
|
||||||
"github.com/databricks/cli/bundle/config/resources"
|
|
||||||
"github.com/databricks/cli/bundle/internal/bundletest"
|
|
||||||
"github.com/databricks/cli/libs/dyn"
|
|
||||||
"github.com/databricks/cli/libs/vfs"
|
|
||||||
"github.com/databricks/databricks-sdk-go/service/dashboards"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestTranslatePathsDashboards_FilePathRelativeSubDirectory(t *testing.T) {
|
|
||||||
dir := t.TempDir()
|
|
||||||
touchEmptyFile(t, filepath.Join(dir, "src", "my_dashboard.lvdash.json"))
|
|
||||||
|
|
||||||
b := &bundle.Bundle{
|
|
||||||
SyncRootPath: dir,
|
|
||||||
SyncRoot: vfs.MustNew(dir),
|
|
||||||
Config: config.Root{
|
|
||||||
Resources: config.Resources{
|
|
||||||
Dashboards: map[string]*resources.Dashboard{
|
|
||||||
"dashboard": {
|
|
||||||
CreateDashboardRequest: &dashboards.CreateDashboardRequest{
|
|
||||||
DisplayName: "My Dashboard",
|
|
||||||
},
|
|
||||||
FilePath: "../src/my_dashboard.lvdash.json",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
bundletest.SetLocation(b, "resources.dashboards", []dyn.Location{{
|
|
||||||
File: filepath.Join(dir, "resources/dashboard.yml"),
|
|
||||||
}})
|
|
||||||
|
|
||||||
diags := bundle.Apply(context.Background(), b, mutator.TranslatePaths())
|
|
||||||
require.NoError(t, diags.Error())
|
|
||||||
|
|
||||||
// Assert that the file path for the dashboard has been converted to its local absolute path.
|
|
||||||
assert.Equal(
|
|
||||||
t,
|
|
||||||
filepath.Join(dir, "src", "my_dashboard.lvdash.json"),
|
|
||||||
b.Config.Resources.Dashboards["dashboard"].FilePath,
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -35,23 +35,17 @@ func promptRunArgument(ctx context.Context, b *bundle.Bundle) (string, error) {
|
||||||
return key, nil
|
return key, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// resolveRunArgument resolves the resource key to run.
|
func resolveRunArgument(ctx context.Context, b *bundle.Bundle, args []string) (string, error) {
|
||||||
// It returns the remaining arguments to pass to the runner, if applicable.
|
|
||||||
func resolveRunArgument(ctx context.Context, b *bundle.Bundle, args []string) (string, []string, error) {
|
|
||||||
// If no arguments are specified, prompt the user to select something to run.
|
// If no arguments are specified, prompt the user to select something to run.
|
||||||
if len(args) == 0 && cmdio.IsPromptSupported(ctx) {
|
if len(args) == 0 && cmdio.IsPromptSupported(ctx) {
|
||||||
key, err := promptRunArgument(ctx, b)
|
return promptRunArgument(ctx, b)
|
||||||
if err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
return key, args, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
return "", nil, fmt.Errorf("expected a KEY of the resource to run")
|
return "", fmt.Errorf("expected a KEY of the resource to run")
|
||||||
}
|
}
|
||||||
|
|
||||||
return args[0], args[1:], nil
|
return args[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func keyToRunner(b *bundle.Bundle, arg string) (run.Runner, error) {
|
func keyToRunner(b *bundle.Bundle, arg string) (run.Runner, error) {
|
||||||
|
@ -115,7 +109,7 @@ task or a Python wheel task, the second example applies.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
key, args, err := resolveRunArgument(ctx, b, args)
|
arg, err := resolveRunArgument(ctx, b, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -130,13 +124,13 @@ task or a Python wheel task, the second example applies.
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
runner, err := keyToRunner(b, key)
|
runner, err := keyToRunner(b, arg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse additional positional arguments.
|
// Parse additional positional arguments.
|
||||||
err = runner.ParseArgs(args, &runOptions)
|
err = runner.ParseArgs(args[1:], &runOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue