databricks-cli/cmd/fs/ls.go

36 lines
802 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"
"github.com/spf13/cobra"
"github.com/databrickslabs/terraform-provider-databricks/storage"
)
// 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) {
2022-05-14 17:54:35 +00:00
api := storage.NewDbfsAPI(cmd.Context(), project.Current.Client())
2022-05-13 14:21:47 +00:00
files, err := api.List(args[0], false)
if err != nil {
panic(err)
}
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)
}