databricks-cli/cmd/fs/ls.go

37 lines
818 B
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/databricks/bricks/project"
2022-05-13 14:21:47 +00:00
"github.com/spf13/cobra"
)
// 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),
PreRunE: project.Configure,
2022-05-13 14:21:47 +00:00
Run: func(cmd *cobra.Command, args []string) {
wsc := project.Get(cmd.Context()).WorkspacesClient()
listStatusResponse, err := wsc.Dbfs.ListByPath(cmd.Context(), 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)
}