package cmd import ( "fmt" "log" "runtime" "code.icod.de/dalu/gomanager/ent" "code.icod.de/dalu/gomanager/runner" "github.com/spf13/cobra" _ "github.com/mattn/go-sqlite3" ) // cronCmd represents the cron command var cronCmd = &cobra.Command{ Use: "cron", Short: "this command is meant to be ran via cron", RunE: func(cmd *cobra.Command, args []string) error { log.Println("setting GOMAXPROCS=1") runtime.GOMAXPROCS(1) log.Println("opening database file") client, err := ent.Open("sqlite3", fmt.Sprintf("file:%s?mode=rwc&cache=private&_fk=1", sqliteFilename)) if err != nil { return fmt.Errorf("failed opening connection to sqlite: %v", err) } defer func(client *ent.Client) { err := client.Close() if err != nil { log.Println("error closing client", err.Error()) } }(client) r := runner.NewRunner(client) return r.Run() }, } func init() { rootCmd.AddCommand(cronCmd) // Here you will define your flags and configuration settings. // Cobra supports Persistent Flags which will work for this command // and all subcommands, e.g.: // cronCmd.PersistentFlags().String("foo", "", "A help for foo") // Cobra supports local flags which will only run when this command // is called directly, e.g.: // cronCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") }