package daemon import ( "fmt" "git.cryptic.systems/volker.raschek/flucky/pkg/config" "git.cryptic.systems/volker.raschek/flucky/pkg/daemon" "git.cryptic.systems/volker.raschek/go-logger" "github.com/spf13/cobra" ) // InitCmd initialize all daemon subcommands func InitCmd(cmd *cobra.Command) error { daemonCmd := &cobra.Command{ Use: "daemon", Short: "Read continuously data from all enabled sensors", Example: "flucky daemon", RunE: run, } daemonCmd.Flags().Uint("cached-values", 500, "Number of measured values in the cache before they are stored in the database") cmd.AddCommand(daemonCmd) return nil } func run(cmd *cobra.Command, args []string) error { configFile, err := cmd.Flags().GetString("config") if err != nil { return fmt.Errorf("No config file defined: %v", err) } cachedEntries, err := cmd.Flags().GetUint("cached-values") if err != nil { return fmt.Errorf("No cached-entries defined") } // logLevel, err := cmd.Flags().GetString("loglevel") // if err != nil { // return fmt.Errorf("No loglevel defined: %v", err) // } flogger := logger.NewLogger(logger.LogLevelDebug) cnf, err := config.Read(configFile) if err != nil { return err } return daemon.Start(cnf, cachedEntries, flogger) }