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

35
src/cmd/motor/listen.go Normal file
View file

@ -0,0 +1,35 @@
/*
Copyright © 2024 Antoine Harle antoine.harle@proton.me
*/
package motor
import (
"fmt"
"github.com/spf13/cobra"
)
// listenCmd represents the listen command
var listenCmd = &cobra.Command{
Use: "listen",
Short: "listen command descritpion",
Long: `listen command descritpion`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("listen called with ID: ", cmd.Flag("id").Value)
},
}
func init() {
motorCmd.AddCommand(listenCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// listenCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// listenCmd.Flags().Uint16("id", 0, "Identifier number")
}

38
src/cmd/motor/motor.go Normal file
View file

@ -0,0 +1,38 @@
/*
Copyright © 2024 Antoine Harle antoine.harle@proton.me
*/
package motor
import (
"fmt"
"github.com/AntoineHX/multi-motors-controller/src/cmd"
"github.com/spf13/cobra"
)
// motorCmd represents the motor command
var motorCmd = &cobra.Command{
Use: "motor",
Short: "motor command descritpion",
Long: `motor command descritpion`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("motor called with ID: ", cmd.Flag("id").Value)
},
}
func init() {
cmd.RootCmd.AddCommand(motorCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
motorCmd.PersistentFlags().Uint16("id", 0, "Identifier number")
motorCmd.MarkFlagRequired("id")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// motorCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

36
src/cmd/motor/moveVel.go Normal file
View file

@ -0,0 +1,36 @@
/*
Copyright © 2024 Antoine Harle antoine.harle@proton.me
*/
package motor
import (
"fmt"
"github.com/spf13/cobra"
)
// moveVelCmd represents the moveVel command
var moveVelCmd = &cobra.Command{
Use: "moveVel",
Short: "moveVel command descritpion",
Long: `moveVel command descritpion`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("moveVel called with: ID ", cmd.Flag("id").Value, " Vel ", cmd.Flag("vel").Value)
},
}
func init() {
motorCmd.AddCommand(moveVelCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// moveVelCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
//TODO: Anonymous flag (with anonymous flag group ?)
moveVelCmd.Flags().Float32("vel", 0, "Velocity (degrees/s)")
}

42
src/cmd/motor/serve.go Normal file
View file

@ -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() {
}