package cmd import ( "fmt" "log" "sort" "github.com/Jaculabilis/intake/core" "github.com/spf13/cobra" ) var crontabCmd = &cobra.Command{ Use: "crontab", Short: "Update crontab entries", Long: `Update crontab entries. A source's cron job is defined by its INTAKE_CRON environment variable. `, Run: func(cmd *cobra.Command, args []string) { crontab(boolArg(cmd, "list")) }, } func init() { rootCmd.AddCommand(crontabCmd) crontabCmd.Flags().BoolP("list", "l", false, "List crontab entries") } func crontab(list bool) { db := openAndMigrateDb() specs, err := core.GetCronSources(db) if err != nil { log.Fatalf("error: failed to get crontab sources: %v", err) } if list { var sources []string for source := range specs { sources = append(sources, source) } sort.Strings(sources) for _, source := range sources { fmt.Println(specs[source]) } } else { if err := core.UpdateCrontab(db, specs); err != nil { log.Fatalf("error: failed to update crontab: %v", err) } } }