package cmd import ( "os" "os/signal" "syscall" "github.com/bdlm/log" "github.com/spf13/cobra" "dev.sum7.eu/genofire/golang-lib/file" "dev.sum7.eu/genofire/wifictld-analyzer/config" "dev.sum7.eu/genofire/wifictld-analyzer/capture" "dev.sum7.eu/genofire/wifictld-analyzer/controller" "dev.sum7.eu/genofire/wifictld-analyzer/database" ) // queryCmd represents the query command var controllerCmd = &cobra.Command{ Use: "controller ", Short: "simulate a wifictld controller", Example: `analyzer controller "/etc/wifictld.conf"`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { configObj := &config.Config{} file.ReadTOML(args[0], configObj) db := database.NewDB(configObj.StatePath) ctr := controller.NewController(db) defer ctr.Close() coll := capture.NewCollector(ctr.Handler, configObj.Interfaces) defer coll.Close() ctr.Send = coll.Send ctr.SendTo = coll.SendTo // Wait for INT/TERM sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) sig := <-sigs log.Println("received", sig) }, } func init() { RootCmd.AddCommand(controllerCmd) }