added `fs ls` command prototype

This commit is contained in:
Serge Smertin 2022-05-13 16:21:47 +02:00
parent 15fd93a012
commit 02e62a7176
3 changed files with 68 additions and 1 deletions

26
cmd/fs.go Normal file
View File

@ -0,0 +1,26 @@
package cmd
import (
"github.com/spf13/cobra"
)
// fsCmd represents the fs command
var fsCmd = &cobra.Command{
Use: "fs",
Short: "Filesystem related commands",
Long: `Commands to do DBFS operations.`,
}
func init() {
rootCmd.AddCommand(fsCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// fsCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// fsCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

42
cmd/ls.go Normal file
View File

@ -0,0 +1,42 @@
package cmd
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{
Use: "ls",
Short: "Lists files",
Long: `Lists files`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
api := storage.NewDbfsAPI(cmd.Context(), project.ClientFromContext(cmd.Context()))
files, err := api.List(args[0], false)
if err != nil {
panic(err)
}
for _, v := range files {
fmt.Printf("[-] %s (%d, %v)\n", v.Path, v.FileSize, v.IsDir)
}
},
}
func init() {
fsCmd.AddCommand(lsCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// lsCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// lsCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

View File

@ -13,7 +13,6 @@ var testCmd = &cobra.Command{
Short: "run tests for the project", Short: "run tests for the project",
Long: `This is longer description of the command`, Long: `This is longer description of the command`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
results := project.RunPythonOnDev(cmd.Context(), `print("hello, world!")`) results := project.RunPythonOnDev(cmd.Context(), `print("hello, world!")`)
if results.Failed() { if results.Failed() {
log.Fatal(results.Error()) log.Fatal(results.Error())