mirror of https://github.com/databricks/cli.git
address comments
This commit is contained in:
parent
fc7fbbec6f
commit
b048c8675d
|
@ -0,0 +1,14 @@
|
||||||
|
package fs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func resolveDbfsPath(path string) (string, error) {
|
||||||
|
if !strings.HasPrefix(path, "dbfs:/") {
|
||||||
|
return "", fmt.Errorf("expected dbfs path (with the dbfs:/ prefix): %s", path)
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.TrimPrefix(path, "dbfs:"), nil
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package filer
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -7,32 +7,32 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestResolveDbfsPath(t *testing.T) {
|
func TestResolveDbfsPath(t *testing.T) {
|
||||||
path, err := ResolveDbfsPath("dbfs:/")
|
path, err := resolveDbfsPath("dbfs:/")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "/", path)
|
assert.Equal(t, "/", path)
|
||||||
|
|
||||||
path, err = ResolveDbfsPath("dbfs:/abc")
|
path, err = resolveDbfsPath("dbfs:/abc")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "/abc", path)
|
assert.Equal(t, "/abc", path)
|
||||||
|
|
||||||
path, err = ResolveDbfsPath("dbfs:/a/b/c")
|
path, err = resolveDbfsPath("dbfs:/a/b/c")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "/a/b/c", path)
|
assert.Equal(t, "/a/b/c", path)
|
||||||
|
|
||||||
path, err = ResolveDbfsPath("dbfs:/a/b/.")
|
path, err = resolveDbfsPath("dbfs:/a/b/.")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "/a/b/.", path)
|
assert.Equal(t, "/a/b/.", path)
|
||||||
|
|
||||||
path, err = ResolveDbfsPath("dbfs:/a/../c")
|
path, err = resolveDbfsPath("dbfs:/a/../c")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "/a/../c", path)
|
assert.Equal(t, "/a/../c", path)
|
||||||
|
|
||||||
_, err = ResolveDbfsPath("dbf:/a/b/c")
|
_, err = resolveDbfsPath("dbf:/a/b/c")
|
||||||
assert.ErrorContains(t, err, "expected dbfs path (with the dbfs:/ prefix): dbf:/a/b/c")
|
assert.ErrorContains(t, err, "expected dbfs path (with the dbfs:/ prefix): dbf:/a/b/c")
|
||||||
|
|
||||||
_, err = ResolveDbfsPath("/a/b/c")
|
_, err = resolveDbfsPath("/a/b/c")
|
||||||
assert.ErrorContains(t, err, "expected dbfs path (with the dbfs:/ prefix): /a/b/c")
|
assert.ErrorContains(t, err, "expected dbfs path (with the dbfs:/ prefix): /a/b/c")
|
||||||
|
|
||||||
_, err = ResolveDbfsPath("dbfs:a/b/c")
|
_, err = resolveDbfsPath("dbfs:a/b/c")
|
||||||
assert.ErrorContains(t, err, "expected dbfs path (with the dbfs:/ prefix): dbfs:a/b/c")
|
assert.ErrorContains(t, err, "expected dbfs path (with the dbfs:/ prefix): dbfs:a/b/c")
|
||||||
}
|
}
|
|
@ -34,7 +34,7 @@ func toJsonDirEntry(f fs.DirEntry) (*jsonDirEntry, error) {
|
||||||
|
|
||||||
// lsCmd represents the ls command
|
// lsCmd represents the ls command
|
||||||
var lsCmd = &cobra.Command{
|
var lsCmd = &cobra.Command{
|
||||||
Use: "ls <dir-name>",
|
Use: "ls DIR_PATH",
|
||||||
Short: "Lists files",
|
Short: "Lists files",
|
||||||
Long: `Lists files`,
|
Long: `Lists files`,
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
|
@ -50,7 +50,7 @@ var lsCmd = &cobra.Command{
|
||||||
ctx := cmd.Context()
|
ctx := cmd.Context()
|
||||||
w := root.WorkspaceClient(ctx)
|
w := root.WorkspaceClient(ctx)
|
||||||
|
|
||||||
path, err := filer.ResolveDbfsPath(args[0])
|
path, err := resolveDbfsPath(args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,11 @@ package filer
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/databricks/databricks-sdk-go"
|
"github.com/databricks/databricks-sdk-go"
|
||||||
|
@ -272,11 +270,3 @@ func (w *DbfsClient) Stat(ctx context.Context, name string) (fs.FileInfo, error)
|
||||||
|
|
||||||
return dbfsFileInfo{*info}, nil
|
return dbfsFileInfo{*info}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ResolveDbfsPath(path string) (string, error) {
|
|
||||||
if !strings.HasPrefix(path, "dbfs:/") {
|
|
||||||
return "", fmt.Errorf("expected dbfs path (with the dbfs:/ prefix): %s", path)
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.TrimPrefix(path, "dbfs:"), nil
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue