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-06-15 13:58:41 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/cli"
|
|
|
|
"github.com/go-flucky/flucky/pkg/config"
|
2019-02-24 21:46:36 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
2018-11-28 17:07:20 +00:00
|
|
|
|
2019-02-24 21:46:36 +00:00
|
|
|
var listSensorCmd = &cobra.Command{
|
2019-06-15 11:56:41 +00:00
|
|
|
Use: "list",
|
2019-02-24 21:46:36 +00:00
|
|
|
Short: "List Sensors",
|
2019-06-15 11:56:41 +00:00
|
|
|
Aliases: []string{"ls"},
|
2019-02-24 21:46:36 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
// read configuration
|
2019-08-19 10:24:08 +00:00
|
|
|
cnf, err := config.Read(*configFile)
|
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
|
|
|
// print sensors on stdout
|
2019-06-16 11:00:50 +00:00
|
|
|
err = cli.PrintSensors(cnf, 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
|
2019-08-19 10:24:08 +00:00
|
|
|
err = config.Write(cnf, *configFile)
|
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
|
|
|
func init() {
|
|
|
|
sensorCmd.AddCommand(listSensorCmd)
|
|
|
|
}
|