Change CLI command structure

This commit is contained in:
AntoineH 2024-09-03 16:50:05 +02:00
parent 42b89b1586
commit 0f5d2df8a5
10 changed files with 74 additions and 30 deletions

View file

@ -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.