diff --git a/cmd/new.go b/cmd/new.go index 94158b3..04f1040 100644 --- a/cmd/new.go +++ b/cmd/new.go @@ -69,19 +69,16 @@ Visit https://www.paperboy.email/ to learn more. ) var newCmd = &cobra.Command{ - Use: "new [path]", - Short: "Create new content for a campaign", - Long: `A longer description...`, + Use: "new [path]", + Short: "Create new content for a campaign", + Example: "paperboy new the-announcement.md", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cfg, err := config.LoadConfig() if err != nil { return err } - if len(args) < 1 { - return newUserError("please provide a path") - } - path := cfg.AppFs.ContentPath(args[0]) return writeTemplate(cfg.AppFs, path, contentTemplate, map[string]string{ "Date": time.Now().Format(time.RFC3339), @@ -91,19 +88,16 @@ var newCmd = &cobra.Command{ } var newListCmd = &cobra.Command{ - Use: "list [path]", - Short: "Create a new recipient list", - Long: `A longer description...`, + Use: "list [path]", + Short: "Create a new recipient list", + Example: "paperboy new list in-the-know", + Args: cobra.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { cfg, err := config.LoadConfig() if err != nil { return err } - if len(args) < 1 { - return newUserError("please provide a path") - } - path := cfg.AppFs.ListPath(args[0]) return writeTemplate(cfg.AppFs, path, listTemplate, nil, false) }, @@ -112,7 +106,7 @@ var newListCmd = &cobra.Command{ var newProjectCmd = &cobra.Command{ Use: "project [path]", Short: "Create new project directory", - Long: `A longer description...`, + Args: cobra.RangeArgs(0, 1), RunE: func(cmd *cobra.Command, args []string) error { path := "." if len(args) > 0 { diff --git a/cmd/preview.go b/cmd/preview.go index cc28d69..fd6a8a3 100644 --- a/cmd/preview.go +++ b/cmd/preview.go @@ -21,21 +21,15 @@ const ( ) var previewCmd = &cobra.Command{ - Use: "preview", + Use: "preview [content] [list]", Short: "Preview campaign in browser", - Long: `A longer description...`, - // Uncomment the following line if your bare application - // has an action associated with it: + Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { cfg, err := config.LoadConfig() if err != nil { return err } - if len(args) != 2 { - return newUserError("Invalid arguments") - } - // Start server, notifies channel when listening return startAPIServer(cfg, func(mux *http.ServeMux, serverReady chan bool) error { diff --git a/cmd/root.go b/cmd/root.go index dc577c4..208e380 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,14 +12,7 @@ import ( // RootCmd represents the base command when called without any subcommands var RootCmd = &cobra.Command{ - Use: "paperboy", - Short: "A brief description of your application", - Long: `A longer description that spans multiple lines and likely contains -examples and usage of using your application. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Use: "paperboy", } // Execute adds all child commands to the root command sets flags appropriately. diff --git a/cmd/send.go b/cmd/send.go index a800e85..a9d9b46 100644 --- a/cmd/send.go +++ b/cmd/send.go @@ -12,9 +12,10 @@ import ( ) var sendCmd = &cobra.Command{ - Use: "send", - Short: "Send campaign to recipients", - Long: `A longer description...`, + Use: "send [content] [list]", + Short: "Send campaign to recipients", + Example: "paperboy send the-announcement in-the-know", + Args: cobra.ExactArgs(2), // Uncomment the following line if your bare application // has an action associated with it: RunE: func(cmd *cobra.Command, args []string) error { @@ -23,10 +24,6 @@ var sendCmd = &cobra.Command{ return err } - if len(args) != 2 { - return newUserError("Invalid arguments") - } - ctx := withSignalTrap(context.Background()) return mail.LoadAndSendCampaign(ctx, cfg, args[0], args[1]) }, diff --git a/cmd/server.go b/cmd/server.go index 2a188a2..12b5c54 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -22,7 +22,6 @@ const ( var serverCmd = &cobra.Command{ Use: "server", Short: "Launch a preview server for emails", - Long: `A longer description...`, RunE: func(cmd *cobra.Command, args []string) error { cfg, err := config.LoadConfig() if err != nil { diff --git a/cmd/version.go b/cmd/version.go index 76f0f77..80bd539 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -10,7 +10,6 @@ import ( var versionCmd = &cobra.Command{ Use: "version", Short: "Print the version number of Paperboy", - Long: `A longer description...`, Run: func(cmd *cobra.Command, args []string) { cfg, _ := config.LoadConfig() fmt.Printf("Paperboy Email Engine %s\n", cfg.Build) diff --git a/mail/campaign.go b/mail/campaign.go index 16fc0ca..8e19cf5 100644 --- a/mail/campaign.go +++ b/mail/campaign.go @@ -138,7 +138,7 @@ func LoadCampaign(cfg *config.AConfig, tmplID, listID string) (*Campaign, error) listFile := cfg.AppFs.FindListPath(listID) who, err := parseRecipients(cfg.AppFs, listFile) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to load campain's recipients: %w", err) } // Populate recipients, and fire! @@ -152,7 +152,7 @@ func LoadContent(cfg *config.AConfig, tmplID string) (*Campaign, error) { tmplFile := cfg.AppFs.FindContentPath(tmplID) email, err := parseTemplate(cfg.AppFs, tmplFile) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to load campain's content: %w", err) } // Read and cast frontmatter