40 lines
672 B
Go
40 lines
672 B
Go
package sensor
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/go-flucky/flucky/pkg/cli"
|
|
"github.com/go-flucky/flucky/pkg/config"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var listSensorCmd = &cobra.Command{
|
|
Use: "list",
|
|
Short: "List Sensors",
|
|
Aliases: []string{"ls"},
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
// read configuration
|
|
fc, err := config.Read(cfg)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
// print sensors on stdout
|
|
err = cli.PrintSensors(fc, os.Stdout)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
// save new configuration
|
|
err = config.Write(fc, cfg)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
sensorCmd.AddCommand(listSensorCmd)
|
|
}
|