Merge branch 'master' into v1v2release

This commit is contained in:
lynn [they] 2019-11-20 21:00:15 -08:00 committed by GitHub
commit 2a060236ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 105 additions and 21 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.coverprofile *.coverprofile
*.orig
node_modules/ node_modules/
vendor vendor

View File

@ -25,7 +25,7 @@ Usage documentation exists for each major version. Don't know what version you'r
**Warning**: `v2` is in a beta state. **Warning**: `v2` is in a beta state.
``` ```
$ go get github.com/urfave/cli.v2 $ go get github.com/urfave/cli/v2
``` ```
```go ```go

View File

@ -137,6 +137,7 @@ func GfmrunActionFunc(c *cli.Context) error {
if err != nil { if err != nil {
return err return err
} }
defer file.Close()
var counter int var counter int
scanner := bufio.NewScanner(file) scanner := bufio.NewScanner(file)

View File

@ -114,8 +114,8 @@ func (c *Context) Lineage() []*Context {
return lineage return lineage
} }
// value returns the value of the flag corresponding to `name` // Value returns the value of the flag corresponding to `name`
func (c *Context) value(name string) interface{} { func (c *Context) Value(name string) interface{} {
return c.flagSet.Lookup(name).Value.(flag.Getter).Get() return c.flagSet.Lookup(name).Value.(flag.Getter).Get()
} }

View File

@ -3,8 +3,8 @@ package cli
import ( import (
"context" "context"
"flag" "flag"
"sort"
"os" "os"
"sort"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -328,7 +328,7 @@ func TestContextPropagation(t *testing.T) {
parent := NewContext(nil, nil, nil) parent := NewContext(nil, nil, nil)
parent.Context = context.WithValue(context.Background(), "key", "val") parent.Context = context.WithValue(context.Background(), "key", "val")
ctx := NewContext(nil, nil, parent) ctx := NewContext(nil, nil, parent)
val := ctx.Value("key") val := ctx.Context.Value("key")
if val == nil { if val == nil {
t.Fatal("expected a parent context to be inherited but got nil") t.Fatal("expected a parent context to be inherited but got nil")
} }

View File

@ -64,7 +64,10 @@ func testApp() *App {
}} }}
app.UsageText = "app [first_arg] [second_arg]" app.UsageText = "app [first_arg] [second_arg]"
app.Usage = "Some app" app.Usage = "Some app"
app.Authors = []*Author{{Name: "Harrison", Email: "harrison@lolwut.com"}} app.Authors = []*Author{
{Name: "Harrison", Email: "harrison@lolwut.com"},
{Name: "Oliver Allen", Email: "oliver@toyshop.com"},
}
return app return app
} }
@ -112,6 +115,19 @@ func TestToMarkdownNoCommands(t *testing.T) {
expectFileContent(t, "testdata/expected-doc-no-commands.md", res) expectFileContent(t, "testdata/expected-doc-no-commands.md", res)
} }
func TestToMarkdownNoAuthors(t *testing.T) {
// Given
app := testApp()
app.Authors = []*Author{}
// When
res, err := app.ToMarkdown()
// Then
expect(t, err, nil)
expectFileContent(t, "testdata/expected-doc-no-authors.md", res)
}
func TestToMan(t *testing.T) { func TestToMan(t *testing.T) {
// Given // Given
app := testApp() app := testApp()

View File

@ -121,8 +121,8 @@ func TestFlagsFromEnv(t *testing.T) {
a := App{ a := App{
Flags: []Flag{test.flag}, Flags: []Flag{test.flag},
Action: func(ctx *Context) error { Action: func(ctx *Context) error {
if !reflect.DeepEqual(ctx.value(test.flag.Names()[0]), test.output) { if !reflect.DeepEqual(ctx.Value(test.flag.Names()[0]), test.output) {
t.Errorf("ex:%01d expected %q to be parsed as %#v, instead was %#v", i, test.input, test.output, ctx.value(test.flag.Names()[0])) t.Errorf("ex:%01d expected %q to be parsed as %#v, instead was %#v", i, test.input, test.output, ctx.Value(test.flag.Names()[0]))
} }
return nil return nil
}, },

View File

@ -71,10 +71,9 @@ OPTIONS:
{{end}}{{end}} {{end}}{{end}}
` `
var MarkdownDocTemplate = `% {{ .App.Name }}(8) {{ .App.Description }} var MarkdownDocTemplate = `% {{ .App.Name }}(8){{ if .App.Description }} {{ .App.Description }}{{ end }}
{{ range $Author := .App.Authors}} {{ range $a := .App.Authors }}
% {{ $Author.Name }} % {{ $a }}{{ end }}
{{- end}}
# NAME # NAME

View File

@ -1,7 +1,10 @@
.nh .nh
.TH greet(8) .TH greet(8)
.SH Harrison .SH Harrison harrison@lolwut.com
\[la]mailto:harrison@lolwut.com\[ra]
Oliver Allen oliver@toyshop.com
\[la]mailto:oliver@toyshop.com\[ra]
.SH NAME .SH NAME
.PP .PP

View File

@ -1,6 +1,7 @@
% greet(8) % greet(8)
% Harrison % Harrison <harrison@lolwut.com>
% Oliver Allen <oliver@toyshop.com>
# NAME # NAME

61
testdata/expected-doc-no-authors.md vendored Normal file
View File

@ -0,0 +1,61 @@
% greet(8)
# NAME
greet - Some app
# SYNOPSIS
greet
```
[--another-flag|-b]
[--flag|--fl|-f]=[value]
[--socket|-s]=[value]
```
# DESCRIPTION
app [first_arg] [second_arg]
**Usage**:
```
greet [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
```
# GLOBAL OPTIONS
**--another-flag, -b**: another usage text
**--flag, --fl, -f**="":
**--socket, -s**="": some 'usage' text (default: value)
# COMMANDS
## config, c
another usage test
**--another-flag, -b**: another usage text
**--flag, --fl, -f**="":
### sub-config, s, ss
another usage test
**--sub-command-flag, -s**: some usage text
**--sub-flag, --sub-fl, -s**="":
## info, i, in
retrieve generic information
## some-command

View File

@ -1,6 +1,7 @@
% greet(8) % greet(8)
% Harrison % Harrison <harrison@lolwut.com>
% Oliver Allen <oliver@toyshop.com>
# NAME # NAME

View File

@ -1,6 +1,7 @@
% greet(8) % greet(8)
% Harrison % Harrison <harrison@lolwut.com>
% Oliver Allen <oliver@toyshop.com>
# NAME # NAME