// Package cli is the bsdaily command line: the command, its flags, the // rules for combining them and the dates they name. The extraction itself // is in package bsdaily. package cli import ( "log/slog" "os" "git.eeqj.de/sneak/bsdaily/internal/bsdaily" "github.com/spf13/cobra" ) // Main runs the bsdaily command on the program's command-line arguments // and returns the status for the process to exit with. version is the // build's version; an empty one is reported as dev. func Main(version string) int { if version == "" { version = "dev" } logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{ Level: slog.LevelInfo, })) slog.SetDefault(logger) var dateFlag, fromFlag, toFlag string rootCmd := &cobra.Command{ Use: "bsdaily", Short: "Extract a single day's data from the latest daily snapshot", Version: version, SilenceUsage: true, RunE: func(_ *cobra.Command, _ []string) error { slog.Info("starting", "version", version) targetDates, err := ParseTargetDates(dateFlag, fromFlag, toFlag) if err != nil { return err } err = bsdaily.Run(targetDates) if err != nil { return err } slog.Info("completed successfully") return nil }, } rootCmd.Flags().StringVarP(&dateFlag, "date", "d", "", "target date to extract (YYYY-MM-DD); "+ "defaults to snapshot date minus one day") rootCmd.Flags().StringVar(&fromFlag, "from", "", "start of date range to extract (YYYY-MM-DD, inclusive); use with --to") rootCmd.Flags().StringVar(&toFlag, "to", "", "end of date range to extract (YYYY-MM-DD, inclusive); use with --from") err := rootCmd.Execute() if err != nil { return 1 } return 0 }