mirror of https://github.com/databricks/cli.git
Using go sdk for ./bricks fs ls DIR_NAME command
This commit is contained in:
parent
0ae8b60573
commit
6217d20e57
15
cmd/fs/ls.go
15
cmd/fs/ls.go
|
@ -3,10 +3,9 @@ package fs
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/databricks/bricks/project"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/databrickslabs/terraform-provider-databricks/storage"
|
||||
"github.com/databricks/databricks-sdk-go/workspaces"
|
||||
"github.com/databricks/databricks-sdk-go/service/dbfs"
|
||||
)
|
||||
|
||||
// lsCmd represents the ls command
|
||||
|
@ -16,11 +15,17 @@ var lsCmd = &cobra.Command{
|
|||
Long: `Lists files`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
api := storage.NewDbfsAPI(cmd.Context(), project.Current.Client())
|
||||
files, err := api.List(args[0], false)
|
||||
// Question (shreyas): Where does the client pick up the login creds from ? Context ?
|
||||
// Maybe this client can be added on a higher level ?
|
||||
// Create issue to add tests for this ? How to write those for cli ?
|
||||
workspacesClient := workspaces.New()
|
||||
listStatusResponse, err := workspacesClient.Dbfs.ListStatus(cmd.Context(),
|
||||
dbfs.ListStatusRequest{Path: args[0]},
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
files := listStatusResponse.Files
|
||||
// TODO: output formatting: JSON, CSV, tables and default
|
||||
for _, v := range files {
|
||||
fmt.Printf("[-] %s (%d, %v)\n", v.Path, v.FileSize, v.IsDir)
|
||||
|
|
Loading…
Reference in New Issue