Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean code #41

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
},
Expand All @@ -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 {
Expand Down
10 changes: 2 additions & 8 deletions cmd/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
9 changes: 1 addition & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 4 additions & 7 deletions cmd/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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])
},
Expand Down
1 change: 0 additions & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions mail/campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
Expand Down
Loading