Skip to content

Commit 2aceb68

Browse files
authored
Merge pull request #41 from gbonnefille/clean-code
Clean code
2 parents 2fe3ddd + 9671b4a commit 2aceb68

File tree

7 files changed

+18
-42
lines changed

7 files changed

+18
-42
lines changed

cmd/new.go

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,16 @@ Visit https://www.paperboy.email/ to learn more.
6969
)
7070

7171
var newCmd = &cobra.Command{
72-
Use: "new [path]",
73-
Short: "Create new content for a campaign",
74-
Long: `A longer description...`,
72+
Use: "new [path]",
73+
Short: "Create new content for a campaign",
74+
Example: "paperboy new the-announcement.md",
75+
Args: cobra.ExactArgs(1),
7576
RunE: func(cmd *cobra.Command, args []string) error {
7677
cfg, err := config.LoadConfig()
7778
if err != nil {
7879
return err
7980
}
8081

81-
if len(args) < 1 {
82-
return newUserError("please provide a path")
83-
}
84-
8582
path := cfg.AppFs.ContentPath(args[0])
8683
return writeTemplate(cfg.AppFs, path, contentTemplate, map[string]string{
8784
"Date": time.Now().Format(time.RFC3339),
@@ -91,19 +88,16 @@ var newCmd = &cobra.Command{
9188
}
9289

9390
var newListCmd = &cobra.Command{
94-
Use: "list [path]",
95-
Short: "Create a new recipient list",
96-
Long: `A longer description...`,
91+
Use: "list [path]",
92+
Short: "Create a new recipient list",
93+
Example: "paperboy new list in-the-know",
94+
Args: cobra.ExactArgs(1),
9795
RunE: func(cmd *cobra.Command, args []string) error {
9896
cfg, err := config.LoadConfig()
9997
if err != nil {
10098
return err
10199
}
102100

103-
if len(args) < 1 {
104-
return newUserError("please provide a path")
105-
}
106-
107101
path := cfg.AppFs.ListPath(args[0])
108102
return writeTemplate(cfg.AppFs, path, listTemplate, nil, false)
109103
},
@@ -112,7 +106,7 @@ var newListCmd = &cobra.Command{
112106
var newProjectCmd = &cobra.Command{
113107
Use: "project [path]",
114108
Short: "Create new project directory",
115-
Long: `A longer description...`,
109+
Args: cobra.RangeArgs(0, 1),
116110
RunE: func(cmd *cobra.Command, args []string) error {
117111
path := "."
118112
if len(args) > 0 {

cmd/preview.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,15 @@ const (
2121
)
2222

2323
var previewCmd = &cobra.Command{
24-
Use: "preview",
24+
Use: "preview [content] [list]",
2525
Short: "Preview campaign in browser",
26-
Long: `A longer description...`,
27-
// Uncomment the following line if your bare application
28-
// has an action associated with it:
26+
Args: cobra.ExactArgs(2),
2927
RunE: func(cmd *cobra.Command, args []string) error {
3028
cfg, err := config.LoadConfig()
3129
if err != nil {
3230
return err
3331
}
3432

35-
if len(args) != 2 {
36-
return newUserError("Invalid arguments")
37-
}
38-
3933
// Start server, notifies channel when listening
4034
return startAPIServer(cfg, func(mux *http.ServeMux, serverReady chan bool) error {
4135

cmd/root.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ import (
1212

1313
// RootCmd represents the base command when called without any subcommands
1414
var RootCmd = &cobra.Command{
15-
Use: "paperboy",
16-
Short: "A brief description of your application",
17-
Long: `A longer description that spans multiple lines and likely contains
18-
examples and usage of using your application. For example:
19-
20-
Cobra is a CLI library for Go that empowers applications.
21-
This application is a tool to generate the needed files
22-
to quickly create a Cobra application.`,
15+
Use: "paperboy",
2316
}
2417

2518
// Execute adds all child commands to the root command sets flags appropriately.

cmd/send.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import (
1212
)
1313

1414
var sendCmd = &cobra.Command{
15-
Use: "send",
16-
Short: "Send campaign to recipients",
17-
Long: `A longer description...`,
15+
Use: "send [content] [list]",
16+
Short: "Send campaign to recipients",
17+
Example: "paperboy send the-announcement in-the-know",
18+
Args: cobra.ExactArgs(2),
1819
// Uncomment the following line if your bare application
1920
// has an action associated with it:
2021
RunE: func(cmd *cobra.Command, args []string) error {
@@ -23,10 +24,6 @@ var sendCmd = &cobra.Command{
2324
return err
2425
}
2526

26-
if len(args) != 2 {
27-
return newUserError("Invalid arguments")
28-
}
29-
3027
ctx := withSignalTrap(context.Background())
3128
return mail.LoadAndSendCampaign(ctx, cfg, args[0], args[1])
3229
},

cmd/server.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const (
2222
var serverCmd = &cobra.Command{
2323
Use: "server",
2424
Short: "Launch a preview server for emails",
25-
Long: `A longer description...`,
2625
RunE: func(cmd *cobra.Command, args []string) error {
2726
cfg, err := config.LoadConfig()
2827
if err != nil {

cmd/version.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
var versionCmd = &cobra.Command{
1111
Use: "version",
1212
Short: "Print the version number of Paperboy",
13-
Long: `A longer description...`,
1413
Run: func(cmd *cobra.Command, args []string) {
1514
cfg, _ := config.LoadConfig()
1615
fmt.Printf("Paperboy Email Engine %s\n", cfg.Build)

mail/campaign.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func LoadCampaign(cfg *config.AConfig, tmplID, listID string) (*Campaign, error)
138138
listFile := cfg.AppFs.FindListPath(listID)
139139
who, err := parseRecipients(cfg.AppFs, listFile)
140140
if err != nil {
141-
return nil, err
141+
return nil, fmt.Errorf("failed to load campain's recipients: %w", err)
142142
}
143143

144144
// Populate recipients, and fire!
@@ -152,7 +152,7 @@ func LoadContent(cfg *config.AConfig, tmplID string) (*Campaign, error) {
152152
tmplFile := cfg.AppFs.FindContentPath(tmplID)
153153
email, err := parseTemplate(cfg.AppFs, tmplFile)
154154
if err != nil {
155-
return nil, err
155+
return nil, fmt.Errorf("failed to load campain's content: %w", err)
156156
}
157157

158158
// Read and cast frontmatter

0 commit comments

Comments
 (0)