feat(daemon): add new subcommand to start a daemon

This commit is contained in:
2019-06-15 15:45:35 +02:00
parent 82faa1d536
commit 5f859139a4
4 changed files with 80 additions and 19 deletions

View File

@ -5,6 +5,7 @@ import (
"os"
"time"
"github.com/volker-raschek/flucky/cmd/daemon"
"github.com/volker-raschek/flucky/cmd/sensor"
"github.com/volker-raschek/flucky/cmd/temperature"
"github.com/volker-raschek/flucky/pkg/types"
@ -53,7 +54,7 @@ func Execute(version string) {
rootCmd.Version = version
rootCmd.PersistentFlags().StringVar(&configPath, "config", "/etc/flucky/config.json", "Config file")
// humidity.InitCmd(rootCmd, configPath)
daemon.InitCmd(rootCmd, configPath)
sensor.InitCmd(rootCmd, configPath)
temperature.InitCmd(rootCmd, configPath)
rootCmd.Execute()

View File

@ -1,7 +1,11 @@
package daemon
import (
"log"
"github.com/spf13/cobra"
"github.com/volker-raschek/flucky/pkg/config"
"github.com/volker-raschek/flucky/pkg/daemon"
)
var configPath string
@ -11,10 +15,15 @@ var daemonCmd = &cobra.Command{
Short: "Read continuously data from all enabled sensors",
Run: func(cmd *cobra.Command, args []string) {
// read configuration
// cnf, err := config.Read(configPath)
// if err != nil {
// log.Fatalln(err)
// }
cnf, err := config.Read(configPath)
if err != nil {
log.Fatalln(err)
}
err = daemon.Start(cnf)
if err != nil {
panic(err)
}
},
}