diff --git a/src/cmd/controller.go b/src/cmd/controller/controller.go similarity index 87% rename from src/cmd/controller.go rename to src/cmd/controller/controller.go index 4babf1c..664d0cd 100644 --- a/src/cmd/controller.go +++ b/src/cmd/controller/controller.go @@ -2,11 +2,13 @@ Copyright © 2024 Antoine Harle antoine.harle@proton.me */ -package cmd +package controller import ( "fmt" + "github.com/AntoineHX/multi-motors-controller/src/cmd" + "github.com/spf13/cobra" ) @@ -21,7 +23,7 @@ var controllerCmd = &cobra.Command{ } func init() { - rootCmd.AddCommand(controllerCmd) + cmd.RootCmd.AddCommand(controllerCmd) // Here you will define your flags and configuration settings. diff --git a/src/cmd/getJoints.go b/src/cmd/controller/getJoints.go similarity index 97% rename from src/cmd/getJoints.go rename to src/cmd/controller/getJoints.go index 8dd059e..a9bd56b 100644 --- a/src/cmd/getJoints.go +++ b/src/cmd/controller/getJoints.go @@ -2,7 +2,7 @@ Copyright © 2024 Antoine Harle antoine.harle@proton.me */ -package cmd +package controller import ( "fmt" diff --git a/src/cmd/serve.go b/src/cmd/controller/serve.go similarity index 62% rename from src/cmd/serve.go rename to src/cmd/controller/serve.go index 60e32fe..a63d0f7 100644 --- a/src/cmd/serve.go +++ b/src/cmd/controller/serve.go @@ -2,7 +2,7 @@ Copyright © 2024 Antoine Harle antoine.harle@proton.me */ -package cmd +package controller import ( "fmt" @@ -13,21 +13,17 @@ import ( // serveCmd represents the serve command var serveCmd = &cobra.Command{ Use: "serve", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Short: "serve command descritpion", + Long: `serve command descritpion`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("serve called with: Port ", cmd.Flag("port").Value, " - ID ", cmd.Flag("id").Value) + fmt.Println("serve called with: Port ", cmd.Flag("port").Value) + fmt.Println(cmd.CommandPath()) }, } func init() { controllerCmd.AddCommand(serveCmd) - motorCmd.AddCommand(serveCmd) + // motorCmd.AddCommand(serveCmd) // Here you will define your flags and configuration settings. @@ -38,6 +34,4 @@ func init() { // Cobra supports local flags which will only run when this command // is called directly, e.g.: serveCmd.Flags().Uint16P("port", "p", 8080, "Port") - - //TODO: Support Motor ID flag -} +} \ No newline at end of file diff --git a/src/cmd/setJoints.go b/src/cmd/controller/setJoints.go similarity index 98% rename from src/cmd/setJoints.go rename to src/cmd/controller/setJoints.go index 29b73d1..38c38ec 100644 --- a/src/cmd/setJoints.go +++ b/src/cmd/controller/setJoints.go @@ -2,7 +2,7 @@ Copyright © 2024 Antoine Harle antoine.harle@proton.me */ -package cmd +package controller import ( "fmt" diff --git a/src/cmd/listen.go b/src/cmd/motor/listen.go similarity index 98% rename from src/cmd/listen.go rename to src/cmd/motor/listen.go index e13157f..0562f55 100644 --- a/src/cmd/listen.go +++ b/src/cmd/motor/listen.go @@ -2,7 +2,7 @@ Copyright © 2024 Antoine Harle antoine.harle@proton.me */ -package cmd +package motor import ( "fmt" diff --git a/src/cmd/motor.go b/src/cmd/motor/motor.go similarity index 88% rename from src/cmd/motor.go rename to src/cmd/motor/motor.go index 623acc2..799e099 100644 --- a/src/cmd/motor.go +++ b/src/cmd/motor/motor.go @@ -2,11 +2,13 @@ Copyright © 2024 Antoine Harle antoine.harle@proton.me */ -package cmd +package motor import ( "fmt" + "github.com/AntoineHX/multi-motors-controller/src/cmd" + "github.com/spf13/cobra" ) @@ -21,7 +23,7 @@ var motorCmd = &cobra.Command{ } func init() { - rootCmd.AddCommand(motorCmd) + cmd.RootCmd.AddCommand(motorCmd) // Here you will define your flags and configuration settings. diff --git a/src/cmd/moveVel.go b/src/cmd/motor/moveVel.go similarity index 98% rename from src/cmd/moveVel.go rename to src/cmd/motor/moveVel.go index 27c7b79..d2438c8 100644 --- a/src/cmd/moveVel.go +++ b/src/cmd/motor/moveVel.go @@ -2,7 +2,7 @@ Copyright © 2024 Antoine Harle antoine.harle@proton.me */ -package cmd +package motor import ( "fmt" diff --git a/src/cmd/motor/serve.go b/src/cmd/motor/serve.go new file mode 100644 index 0000000..b269281 --- /dev/null +++ b/src/cmd/motor/serve.go @@ -0,0 +1,42 @@ +/* +Copyright © 2024 Antoine Harle antoine.harle@proton.me + +*/ +package motor + +import ( + "fmt" + + "github.com/spf13/cobra" +) + +// serveCmd represents the serve command +var serveCmd = &cobra.Command{ + Use: "serve", + Short: "serve command descritpion", + Long: `serve command descritpion`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println("serve called with ID ", cmd.Flag("id").Value) + fmt.Println(cmd.CommandPath()) + }, +} + +func init() { + motorCmd.AddCommand(serveCmd) + + // Here you will define your flags and configuration settings. + + // Cobra supports Persistent Flags which will work for this command + // and all subcommands, e.g.: + // serveCmd.PersistentFlags().String("foo", "", "A help for foo") + + // Cobra supports local flags which will only run when this command + // is called directly, e.g.: + // serveCmd.Flags().Uint16P("port", "p", 8080, "Port") + + //TODO: Support Motor ID flag +} + +func controller() { + +} \ No newline at end of file diff --git a/src/cmd/root.go b/src/cmd/root.go index 6ef9079..2f0dcd2 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -14,8 +14,8 @@ import ( var cfgFile string -// rootCmd represents the base command when called without any subcommands -var rootCmd = &cobra.Command{ +// RootCmd represents the base command when called without any subcommands +var RootCmd = &cobra.Command{ Use: "src", Short: "Multi Motors Controller", Long: `Root command of Multi Motors Controller`, @@ -26,9 +26,9 @@ var rootCmd = &cobra.Command{ } // 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() { - err := rootCmd.Execute() + err := RootCmd.Execute() if err != nil { os.Exit(1) } @@ -41,13 +41,13 @@ func init() { // Cobra supports persistent flags, which, if defined here, // will be global for your application. - rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.cobra.yaml)") - //rootCmd.MarkFlagRequired("config") - // viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config")) + RootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.cobra.yaml)") + //RootCmd.MarkFlagRequired("config") + // viper.BindPFlag("config", RootCmd.PersistentFlags().Lookup("config")) // Cobra also supports local flags, which will only run // when this action is called directly. - rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + RootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") } // initConfig reads in config file and ENV variables if set. diff --git a/src/main.go b/src/main.go index 7047f83..721b212 100644 --- a/src/main.go +++ b/src/main.go @@ -4,7 +4,11 @@ Copyright © 2024 Antoine Harle antoine.harle@proton.me */ package main -import "github.com/AntoineHX/multi-motors-controller/src/cmd" +import ( + "github.com/AntoineHX/multi-motors-controller/src/cmd" + _ "github.com/AntoineHX/multi-motors-controller/src/cmd/controller" + _ "github.com/AntoineHX/multi-motors-controller/src/cmd/motor" +) func main() { cmd.Execute()