Skip to content

Commit 6d7ed03

Browse files
committed
Use *mail.Address instead of custom *Author type
Supports #1586
1 parent f983141 commit 6d7ed03

File tree

6 files changed

+17
-49
lines changed

6 files changed

+17
-49
lines changed

app.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"flag"
66
"fmt"
77
"io"
8+
"net/mail"
89
"os"
910
"path/filepath"
1011
"sort"
@@ -79,7 +80,7 @@ type App struct {
7980
// Execute this function when an invalid flag is accessed from the context
8081
InvalidFlagAccessHandler InvalidFlagAccessFunc
8182
// List of all authors who contributed
82-
Authors []*Author
83+
Authors []*mail.Address
8384
// Copyright of the binary if any
8485
Copyright string
8586
// Reader reader to write input to (useful for tests)
@@ -434,22 +435,6 @@ func runFlagActions(c *Context, fs []Flag) error {
434435
return nil
435436
}
436437

437-
// Author represents someone who has contributed to a cli project.
438-
type Author struct {
439-
Name string // The Authors name
440-
Email string // The Authors email
441-
}
442-
443-
// String makes Author comply to the Stringer interface, to allow an easy print in the templating process
444-
func (a *Author) String() string {
445-
e := ""
446-
if a.Email != "" {
447-
e = " <" + a.Email + ">"
448-
}
449-
450-
return fmt.Sprintf("%v%v", a.Name, e)
451-
}
452-
453438
func checkStringSliceIncludes(want string, sSlice []string) bool {
454439
found := false
455440
for _, s := range sSlice {

app_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"flag"
77
"fmt"
88
"io"
9+
"net/mail"
910
"os"
1011
"reflect"
1112
"strconv"
@@ -45,7 +46,7 @@ func ExampleApp_Run() {
4546
return nil
4647
},
4748
UsageText: "app [first_arg] [second_arg]",
48-
Authors: []*Author{{Name: "Oliver Allen", Email: "[email protected]"}},
49+
Authors: []*mail.Address{{Name: "Oliver Allen", Address: "[email protected]"}},
4950
}
5051

5152
app.Run(os.Args)
@@ -100,9 +101,9 @@ func ExampleApp_Run_appHelp() {
100101
Name: "greet",
101102
Version: "0.1.0",
102103
Description: "This is how we describe greet the app",
103-
Authors: []*Author{
104-
{Name: "Harrison", Email: "[email protected]"},
105-
{Name: "Oliver Allen", Email: "[email protected]"},
104+
Authors: []*mail.Address{
105+
{Name: "Harrison", Address: "[email protected]"},
106+
{Name: "Oliver Allen", Address: "[email protected]"},
106107
},
107108
Flags: []Flag{
108109
&StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
@@ -135,8 +136,8 @@ func ExampleApp_Run_appHelp() {
135136
// This is how we describe greet the app
136137
//
137138
// AUTHORS:
138-
// Harrison <[email protected]>
139-
// Oliver Allen <[email protected]>
139+
// "Harrison" <[email protected]>
140+
// "Oliver Allen" <[email protected]>
140141
//
141142
// COMMANDS:
142143
// describeit, d use it to see a description

docs_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package cli
55

66
import (
77
"errors"
8+
"net/mail"
89
"testing"
910
)
1011

@@ -49,7 +50,7 @@ func TestToMarkdownNoCommands(t *testing.T) {
4950
func TestToMarkdownNoAuthors(t *testing.T) {
5051
// Given
5152
app := testApp()
52-
app.Authors = []*Author{}
53+
app.Authors = []*mail.Address{}
5354

5455
// When
5556
res, err := app.ToMarkdown()

fish_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cli
22

33
import (
44
"bytes"
5+
"net/mail"
56
"os"
67
"testing"
78
)
@@ -127,9 +128,9 @@ Should be a part of the same code block
127128
app.UsageText = "app [first_arg] [second_arg]"
128129
app.Description = `Description of the application.`
129130
app.Usage = "Some app"
130-
app.Authors = []*Author{
131-
{Name: "Harrison", Email: "[email protected]"},
132-
{Name: "Oliver Allen", Email: "[email protected]"},
131+
app.Authors = []*mail.Address{
132+
{Name: "Harrison", Address: "[email protected]"},
133+
{Name: "Oliver Allen", Address: "[email protected]"},
133134
}
134135
return app
135136
}

godoc-current.txt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ type App struct {
294294
// Execute this function when an invalid flag is accessed from the context
295295
InvalidFlagAccessHandler InvalidFlagAccessFunc
296296
// List of all authors who contributed
297-
Authors []*Author
297+
Authors []*mail.Address
298298
// Copyright of the binary if any
299299
Copyright string
300300
// Reader reader to write input to (useful for tests)
@@ -399,16 +399,6 @@ type Args interface {
399399
Slice() []string
400400
}
401401

402-
type Author struct {
403-
Name string // The Authors name
404-
Email string // The Authors email
405-
}
406-
Author represents someone who has contributed to a cli project.
407-
408-
func (a *Author) String() string
409-
String makes Author comply to the Stringer interface, to allow an easy print
410-
in the templating process
411-
412402
type BeforeFunc func(*Context) error
413403
BeforeFunc is an action to execute before any subcommands are run, but after
414404
the context is ready if a non-nil error is returned, no subcommands are run

testdata/godoc-v3.x.txt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ type App struct {
294294
// Execute this function when an invalid flag is accessed from the context
295295
InvalidFlagAccessHandler InvalidFlagAccessFunc
296296
// List of all authors who contributed
297-
Authors []*Author
297+
Authors []*mail.Address
298298
// Copyright of the binary if any
299299
Copyright string
300300
// Reader reader to write input to (useful for tests)
@@ -399,16 +399,6 @@ type Args interface {
399399
Slice() []string
400400
}
401401

402-
type Author struct {
403-
Name string // The Authors name
404-
Email string // The Authors email
405-
}
406-
Author represents someone who has contributed to a cli project.
407-
408-
func (a *Author) String() string
409-
String makes Author comply to the Stringer interface, to allow an easy print
410-
in the templating process
411-
412402
type BeforeFunc func(*Context) error
413403
BeforeFunc is an action to execute before any subcommands are run, but after
414404
the context is ready if a non-nil error is returned, no subcommands are run

0 commit comments

Comments
 (0)