PKGBUILD/cmd/sensor/list.go

39 lines
639 B
Go

package sensor
import (
"log"
"os"
"git.cryptic.systems/fh-trier/go-flucky/pkg/config"
"github.com/spf13/cobra"
)
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)
}
// print sensors on stdout
err = fc.PrintSensors(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)
}