package cli import ( "fmt" "os" "github.com/spf13/cobra" ) var ( version = "dev" ) var rootCmd = &cobra.Command{ Use: "ursula", Short: "A little tool for your magazine reading habit", Version: version, Run: func(cmd *cobra.Command, args []string) { printBanner() cmd.Help() }, } var downloadCmd = &cobra.Command{ Use: "download", Short: "Download magazine issues", } var issue string func Execute() error { if err := rootCmd.Execute(); err != nil { fmt.Fprintln(os.Stderr, errorStyle.Render("Error: "+err.Error())) return err } return nil } func init() { rootCmd.AddCommand(downloadCmd) rootCmd.AddCommand(&cobra.Command{ Use: "version", Short: "Display version", Run: func(cmd *cobra.Command, args []string) { fmt.Println("Ursula", version) }, }) downloadCmd.AddCommand(&cobra.Command{ Use: "locus", Short: "Download Locus Magazine", RunE: func(cmd *cobra.Command, args []string) error { return downloadPublisher("locus", issue) }, }) downloadCmd.PersistentFlags().StringVar( &issue, "issue", "", "Issue month (YYYY-MM), defaults to current month", ) } func printBanner() { fmt.Println() fmt.Println(titleStyle.Render(" Ursula")) fmt.Println(mutedStyle.Render(" A little tool for your magazine reading habit")) fmt.Println() }