mirror of https://github.com/databricks/cli.git
added `fs ls` command prototype
This commit is contained in:
parent
15fd93a012
commit
02e62a7176
|
@ -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")
|
||||||
|
}
|
|
@ -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")
|
||||||
|
}
|
|
@ -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())
|
||||||
|
|
Loading…
Reference in New Issue