mirror of https://github.com/databricks/cli.git
moved commands to own packages
This commit is contained in:
parent
3cc425f7f1
commit
4e8955085e
|
@ -1,6 +1,7 @@
|
||||||
package cmd
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/databricks/bricks/cmd/root"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ var fsCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(fsCmd)
|
root.RootCmd.AddCommand(fsCmd)
|
||||||
|
|
||||||
// Here you will define your flags and configuration settings.
|
// Here you will define your flags and configuration settings.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package cmd
|
package fs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -16,7 +16,7 @@ var lsCmd = &cobra.Command{
|
||||||
Long: `Lists files`,
|
Long: `Lists files`,
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
api := storage.NewDbfsAPI(cmd.Context(), project.ClientFromContext(cmd.Context()))
|
api := storage.NewDbfsAPI(cmd.Context(), project.Current.Client())
|
||||||
files, err := api.List(args[0], false)
|
files, err := api.List(args[0], false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
|
@ -1,10 +1,11 @@
|
||||||
package cmd
|
package launch
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/databricks/bricks/cmd/root"
|
||||||
"github.com/databricks/bricks/project"
|
"github.com/databricks/bricks/project"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -29,5 +30,5 @@ var launchCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(launchCmd)
|
root.RootCmd.AddCommand(launchCmd)
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package cmd
|
package root
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -6,15 +6,20 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/databricks/bricks/project"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// rootCmd represents the base command when called without any subcommands
|
// RootCmd represents the base command when called without any subcommands
|
||||||
var rootCmd = &cobra.Command{
|
var RootCmd = &cobra.Command{
|
||||||
Use: "bricks",
|
Use: "bricks",
|
||||||
Short: "Databricks project lifecycle management",
|
Short: "Databricks project lifecycle management",
|
||||||
Long: `Where's "data"? Secured by the unity catalog. Projects build lifecycle is secured by bricks`,
|
Long: `Where's "data"? Secured by the unity catalog. Projects build lifecycle is secured by bricks`,
|
||||||
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
if Verbose {
|
||||||
|
logLevel = append(logLevel, "[DEBUG]")
|
||||||
|
}
|
||||||
|
log.SetOutput(&logLevel)
|
||||||
|
},
|
||||||
// Uncomment the following line if your bare application
|
// Uncomment the following line if your bare application
|
||||||
// has an action associated with it:
|
// has an action associated with it:
|
||||||
}
|
}
|
||||||
|
@ -23,7 +28,9 @@ var rootCmd = &cobra.Command{
|
||||||
type levelWriter []string
|
type levelWriter []string
|
||||||
|
|
||||||
var logLevel = levelWriter{"[INFO]", "[ERROR]", "[WARN]"}
|
var logLevel = levelWriter{"[INFO]", "[ERROR]", "[WARN]"}
|
||||||
var verbose bool
|
|
||||||
|
// Verbose means additional debug information, like API logs
|
||||||
|
var Verbose bool
|
||||||
|
|
||||||
func (lw *levelWriter) Write(p []byte) (n int, err error) {
|
func (lw *levelWriter) Write(p []byte) (n int, err error) {
|
||||||
a := string(p)
|
a := string(p)
|
||||||
|
@ -38,17 +45,14 @@ func (lw *levelWriter) Write(p []byte) (n int, err error) {
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
// Execute adds all child commands to the root command and sets flags appropriately.
|
||||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
||||||
func Execute() {
|
func Execute() {
|
||||||
if verbose {
|
// TODO: deferred panic recovery
|
||||||
logLevel = append(logLevel, "[DEBUG]")
|
ctx := context.Background()
|
||||||
}
|
err := RootCmd.ExecuteContext(ctx)
|
||||||
ctx := project.Authenticate(context.Background())
|
|
||||||
err := rootCmd.ExecuteContext(ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "print debug logs")
|
RootCmd.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "print debug logs")
|
||||||
log.SetOutput(&logLevel)
|
|
||||||
}
|
}
|
|
@ -1,8 +1,9 @@
|
||||||
package cmd
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"github.com/databricks/bricks/cmd/root"
|
||||||
"github.com/databricks/bricks/project"
|
"github.com/databricks/bricks/project"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -22,7 +23,7 @@ var testCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(testCmd)
|
root.RootCmd.AddCommand(testCmd)
|
||||||
|
|
||||||
// Here you will define your flags and configuration settings.
|
// Here you will define your flags and configuration settings.
|
||||||
|
|
Loading…
Reference in New Issue