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

Allow any instead of custom *Author type #1630

Merged
merged 2 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 2 additions & 17 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"io"
"net/mail"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -79,7 +80,7 @@ type App struct {
// Execute this function when an invalid flag is accessed from the context
InvalidFlagAccessHandler InvalidFlagAccessFunc
// List of all authors who contributed
Authors []*Author
Authors []*mail.Address
// Copyright of the binary if any
Copyright string
// Reader reader to write input to (useful for tests)
Expand Down Expand Up @@ -434,22 +435,6 @@ func runFlagActions(c *Context, fs []Flag) error {
return nil
}

// Author represents someone who has contributed to a cli project.
type Author struct {
Name string // The Authors name
Email string // The Authors email
}

// String makes Author comply to the Stringer interface, to allow an easy print in the templating process
func (a *Author) String() string {
e := ""
if a.Email != "" {
e = " <" + a.Email + ">"
}

return fmt.Sprintf("%v%v", a.Name, e)
}

func checkStringSliceIncludes(want string, sSlice []string) bool {
found := false
for _, s := range sSlice {
Expand Down
13 changes: 7 additions & 6 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"flag"
"fmt"
"io"
"net/mail"
"os"
"reflect"
"strconv"
Expand Down Expand Up @@ -45,7 +46,7 @@ func ExampleApp_Run() {
return nil
},
UsageText: "app [first_arg] [second_arg]",
Authors: []*Author{{Name: "Oliver Allen", Email: "oliver@toyshop.example.com"}},
Authors: []*mail.Address{{Name: "Oliver Allen", Address: "oliver@toyshop.example.com"}},
}

app.Run(os.Args)
Expand Down Expand Up @@ -100,9 +101,9 @@ func ExampleApp_Run_appHelp() {
Name: "greet",
Version: "0.1.0",
Description: "This is how we describe greet the app",
Authors: []*Author{
{Name: "Harrison", Email: "harrison@lolwut.com"},
{Name: "Oliver Allen", Email: "oliver@toyshop.com"},
Authors: []*mail.Address{
{Name: "Harrison", Address: "harrison@lolwut.com"},
{Name: "Oliver Allen", Address: "oliver@toyshop.com"},
},
Flags: []Flag{
&StringFlag{Name: "name", Value: "bob", Usage: "a name to say"},
Expand Down Expand Up @@ -135,8 +136,8 @@ func ExampleApp_Run_appHelp() {
// This is how we describe greet the app
//
// AUTHORS:
// Harrison <harrison@lolwut.com>
// Oliver Allen <oliver@toyshop.com>
// "Harrison" <harrison@lolwut.com>
// "Oliver Allen" <oliver@toyshop.com>
//
// COMMANDS:
// describeit, d use it to see a description
Expand Down
3 changes: 2 additions & 1 deletion docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cli

import (
"errors"
"net/mail"
"testing"
)

Expand Down Expand Up @@ -49,7 +50,7 @@ func TestToMarkdownNoCommands(t *testing.T) {
func TestToMarkdownNoAuthors(t *testing.T) {
// Given
app := testApp()
app.Authors = []*Author{}
app.Authors = []*mail.Address{}

// When
res, err := app.ToMarkdown()
Expand Down
7 changes: 4 additions & 3 deletions fish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"bytes"
"net/mail"
"os"
"testing"
)
Expand Down Expand Up @@ -127,9 +128,9 @@ Should be a part of the same code block
app.UsageText = "app [first_arg] [second_arg]"
app.Description = `Description of the application.`
app.Usage = "Some app"
app.Authors = []*Author{
{Name: "Harrison", Email: "harrison@lolwut.com"},
{Name: "Oliver Allen", Email: "oliver@toyshop.com"},
app.Authors = []*mail.Address{
{Name: "Harrison", Address: "harrison@lolwut.com"},
{Name: "Oliver Allen", Address: "oliver@toyshop.com"},
}
return app
}
Expand Down
12 changes: 1 addition & 11 deletions godoc-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ type App struct {
// Execute this function when an invalid flag is accessed from the context
InvalidFlagAccessHandler InvalidFlagAccessFunc
// List of all authors who contributed
Authors []*Author
Authors []*mail.Address
// Copyright of the binary if any
Copyright string
// Reader reader to write input to (useful for tests)
Expand Down Expand Up @@ -399,16 +399,6 @@ type Args interface {
Slice() []string
}

type Author struct {
Name string // The Authors name
Email string // The Authors email
}
Author represents someone who has contributed to a cli project.

func (a *Author) String() string
String makes Author comply to the Stringer interface, to allow an easy print
in the templating process

type BeforeFunc func(*Context) error
BeforeFunc is an action to execute before any subcommands are run, but after
the context is ready if a non-nil error is returned, no subcommands are run
Expand Down
12 changes: 1 addition & 11 deletions testdata/godoc-v3.x.txt
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ type App struct {
// Execute this function when an invalid flag is accessed from the context
InvalidFlagAccessHandler InvalidFlagAccessFunc
// List of all authors who contributed
Authors []*Author
Authors []*mail.Address
// Copyright of the binary if any
Copyright string
// Reader reader to write input to (useful for tests)
Expand Down Expand Up @@ -399,16 +399,6 @@ type Args interface {
Slice() []string
}

type Author struct {
Name string // The Authors name
Email string // The Authors email
}
Author represents someone who has contributed to a cli project.

func (a *Author) String() string
String makes Author comply to the Stringer interface, to allow an easy print
in the templating process

type BeforeFunc func(*Context) error
BeforeFunc is an action to execute before any subcommands are run, but after
the context is ready if a non-nil error is returned, no subcommands are run
Expand Down