databricks-cli/cmd/fs/ls.go

41 lines
1.1 KiB
Go
Raw Normal View History

2022-05-14 17:54:35 +00:00
package fs
2022-05-13 14:21:47 +00:00
import (
"fmt"
"github.com/spf13/cobra"
"github.com/databricks/databricks-sdk-go/workspaces"
"github.com/databricks/databricks-sdk-go/service/dbfs"
2022-05-13 14:21:47 +00:00
)
// lsCmd represents the ls command
var lsCmd = &cobra.Command{
2022-05-20 18:43:29 +00:00
Use: "ls <dir-name>",
2022-05-13 14:21:47 +00:00
Short: "Lists files",
Long: `Lists files`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
// 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]},
)
2022-05-13 14:21:47 +00:00
if err != nil {
panic(err)
}
files := listStatusResponse.Files
2022-05-20 18:43:29 +00:00
// TODO: output formatting: JSON, CSV, tables and default
2022-05-13 14:21:47 +00:00
for _, v := range files {
fmt.Printf("[-] %s (%d, %v)\n", v.Path, v.FileSize, v.IsDir)
}
},
}
func init() {
2022-05-20 18:43:29 +00:00
// TODO: pietern: conditionally register commands
// fabianj: don't do it
2022-05-13 14:21:47 +00:00
fsCmd.AddCommand(lsCmd)
}