2018-11-28 17:07:20 +00:00
|
|
|
package sensor
|
|
|
|
|
2019-02-24 21:46:36 +00:00
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
2018-11-28 17:07:20 +00:00
|
|
|
|
2019-02-24 21:46:36 +00:00
|
|
|
"github.com/spf13/cobra"
|
2019-05-12 09:57:53 +00:00
|
|
|
"github.com/volker-raschek/flucky/pkg/cli"
|
|
|
|
"github.com/volker-raschek/flucky/pkg/config"
|
2019-02-24 21:46:36 +00:00
|
|
|
)
|
2018-11-28 17:07:20 +00:00
|
|
|
|
2019-02-24 21:46:36 +00:00
|
|
|
var listSensorCmd = &cobra.Command{
|
|
|
|
Use: "ls",
|
|
|
|
Short: "List Sensors",
|
|
|
|
Aliases: []string{"list"},
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
// read configuration
|
|
|
|
fc, err := config.Read(cfg)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2018-11-28 17:07:20 +00:00
|
|
|
|
2019-02-24 21:46:36 +00:00
|
|
|
// print sensors on stdout
|
2019-03-04 10:31:01 +00:00
|
|
|
err = cli.PrintSensors(fc, os.Stdout)
|
2019-02-24 21:46:36 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2018-11-28 17:07:20 +00:00
|
|
|
|
2019-02-24 21:46:36 +00:00
|
|
|
// save new configuration
|
|
|
|
err = config.Write(fc, cfg)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2018-11-28 17:07:20 +00:00
|
|
|
|
2019-02-24 21:46:36 +00:00
|
|
|
func init() {
|
|
|
|
sensorCmd.AddCommand(listSensorCmd)
|
|
|
|
}
|