fix(cmd): use pointer instead a copied object of the configFile environment
This commit is contained in:
@ -21,7 +21,7 @@ var addRgbLedCmd = &cobra.Command{
|
||||
flucky rgb-led add my-led GPIO13 GPIO17 GPIO26`),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// read configuration
|
||||
cnf, err := config.Read(configFile)
|
||||
cnf, err := config.Read(*configFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@ -62,7 +62,7 @@ flucky rgb-led add my-led GPIO13 GPIO17 GPIO26`),
|
||||
}
|
||||
|
||||
// save new configuration
|
||||
err = config.Write(cnf, configFile)
|
||||
err = config.Write(cnf, *configFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ flucky rgb-led disable 9f8abfc5-91f3-480c-a42d-b990b6f89e5d`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
// read configuration
|
||||
cnf, err := config.Read(configFile)
|
||||
cnf, err := config.Read(*configFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@ -29,7 +29,7 @@ flucky rgb-led disable 9f8abfc5-91f3-480c-a42d-b990b6f89e5d`,
|
||||
}
|
||||
|
||||
// save new configuration
|
||||
err = config.Write(cnf, configFile)
|
||||
err = config.Write(cnf, *configFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ flucky rgb-led enable 9f8abfc5-91f3-480c-a42d-b990b6f89e5d`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
// read configuration
|
||||
cnf, err := config.Read(configFile)
|
||||
cnf, err := config.Read(*configFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@ -29,7 +29,7 @@ flucky rgb-led enable 9f8abfc5-91f3-480c-a42d-b990b6f89e5d`,
|
||||
}
|
||||
|
||||
// save new configuration
|
||||
err = config.Write(cnf, configFile)
|
||||
err = config.Write(cnf, *configFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ var listRgbLedCmd = &cobra.Command{
|
||||
Aliases: []string{"ls"},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// read configuration
|
||||
cnf, err := config.Read(configFile)
|
||||
cnf, err := config.Read(*configFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ var offRgbLedCmd = &cobra.Command{
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
// read configuration
|
||||
cnf, err := config.Read(configFile)
|
||||
cnf, err := config.Read(*configFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ flucky rgb-led on 1c5b9424-f6e9-4a37-be5c-77e531e94aab red`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
// read configuration
|
||||
cnf, err := config.Read(configFile)
|
||||
cnf, err := config.Read(*configFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ flucky rgb-led remove 9f8abfc5-91f3-480c-a42d-b990b6f89e5d`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// read configuration
|
||||
cnf, err := config.Read(configFile)
|
||||
cnf, err := config.Read(*configFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@ -29,7 +29,7 @@ flucky rgb-led remove 9f8abfc5-91f3-480c-a42d-b990b6f89e5d`,
|
||||
}
|
||||
|
||||
// save new configuration
|
||||
err = config.Write(cnf, configFile)
|
||||
err = config.Write(cnf, *configFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ flucky rgb-led disable my-led my-sweet-led
|
||||
flucky rgb-led disable 9f8abfc5-91f3-480c-a42d-b990b6f89e5d my-sweet-led`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// read configuration
|
||||
cnf, err := config.Read(configFile)
|
||||
cnf, err := config.Read(*configFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@ -28,7 +28,7 @@ flucky rgb-led disable 9f8abfc5-91f3-480c-a42d-b990b6f89e5d my-sweet-led`,
|
||||
}
|
||||
|
||||
// save new configuration
|
||||
err = config.Write(cnf, configFile)
|
||||
err = config.Write(cnf, *configFile)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var configFile string
|
||||
var configFile *string
|
||||
|
||||
var rgbLedCmd = &cobra.Command{
|
||||
Use: "rgb-led",
|
||||
@ -12,7 +12,7 @@ var rgbLedCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
// InitCmd da
|
||||
func InitCmd(cmd *cobra.Command, cnfFile string) {
|
||||
func InitCmd(cmd *cobra.Command, cnfFile *string) {
|
||||
configFile = cnfFile
|
||||
|
||||
cmd.AddCommand(rgbLedCmd)
|
||||
|
Reference in New Issue
Block a user