From 2cb62f5091a7a7e304003b4a9134c66bb016fc08 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Thu, 19 Sep 2019 14:29:06 +0200 Subject: [PATCH 1/5] Improve docs generation for cli.Authors This allows specifying multiple authors, whereas no available authors will be formatted correctly now. Signed-off-by: Sascha Grunert --- .gitignore | 3 +- docs_test.go | 18 +++++++- template.go | 7 ++-- testdata/expected-doc-full.man | 7 +++- testdata/expected-doc-full.md | 5 ++- testdata/expected-doc-no-authors.md | 61 ++++++++++++++++++++++++++++ testdata/expected-doc-no-commands.md | 5 ++- testdata/expected-doc-no-flags.md | 5 ++- 8 files changed, 97 insertions(+), 14 deletions(-) create mode 100644 testdata/expected-doc-no-authors.md diff --git a/.gitignore b/.gitignore index 7a7e2d9ef0..501b8e88ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.coverprofile +*.orig node_modules/ -vendor \ No newline at end of file +vendor diff --git a/docs_test.go b/docs_test.go index e685f90950..e52cf8bd31 100644 --- a/docs_test.go +++ b/docs_test.go @@ -64,7 +64,10 @@ func testApp() *App { }} app.UsageText = "app [first_arg] [second_arg]" 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 } @@ -112,6 +115,19 @@ func TestToMarkdownNoCommands(t *testing.T) { 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) { // Given app := testApp() diff --git a/template.go b/template.go index 78e182f5c4..1cc4bd624b 100644 --- a/template.go +++ b/template.go @@ -71,10 +71,9 @@ OPTIONS: {{end}}{{end}} ` -var MarkdownDocTemplate = `% {{ .App.Name }}(8) {{ .App.Description }} -{{ range $Author := .App.Authors}} -% {{ $Author.Name }} -{{- end}} +var MarkdownDocTemplate = `% {{ .App.Name }}(8){{ if .App.Description }} {{ .App.Description }}{{ end }} +{{ range $a := .App.Authors }} +% {{ $a }}{{ end }} # NAME diff --git a/testdata/expected-doc-full.man b/testdata/expected-doc-full.man index 5190698fa3..f28f4c78b3 100644 --- a/testdata/expected-doc-full.man +++ b/testdata/expected-doc-full.man @@ -1,7 +1,10 @@ .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 .PP diff --git a/testdata/expected-doc-full.md b/testdata/expected-doc-full.md index 23d7c23745..5bfb01ed46 100644 --- a/testdata/expected-doc-full.md +++ b/testdata/expected-doc-full.md @@ -1,6 +1,7 @@ -% greet(8) +% greet(8) -% Harrison +% Harrison +% Oliver Allen # NAME diff --git a/testdata/expected-doc-no-authors.md b/testdata/expected-doc-no-authors.md new file mode 100644 index 0000000000..a49481a4f8 --- /dev/null +++ b/testdata/expected-doc-no-authors.md @@ -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 + + diff --git a/testdata/expected-doc-no-commands.md b/testdata/expected-doc-no-commands.md index 18d8e357e8..f82f642a0b 100644 --- a/testdata/expected-doc-no-commands.md +++ b/testdata/expected-doc-no-commands.md @@ -1,6 +1,7 @@ -% greet(8) +% greet(8) -% Harrison +% Harrison +% Oliver Allen # NAME diff --git a/testdata/expected-doc-no-flags.md b/testdata/expected-doc-no-flags.md index 8ce60fd7ad..c32a9fccee 100644 --- a/testdata/expected-doc-no-flags.md +++ b/testdata/expected-doc-no-flags.md @@ -1,6 +1,7 @@ -% greet(8) +% greet(8) -% Harrison +% Harrison +% Oliver Allen # NAME From 5dafdb1de66163e0149529468e66fe127dcd5866 Mon Sep 17 00:00:00 2001 From: Jim Powers Date: Wed, 2 May 2018 08:55:01 -0400 Subject: [PATCH 2/5] Exposed the `value` accessor in `Context` --- context.go | 2 +- flag_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/context.go b/context.go index 535c38818a..b88b703824 100644 --- a/context.go +++ b/context.go @@ -115,7 +115,7 @@ func (c *Context) Lineage() []*Context { } // 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() } diff --git a/flag_test.go b/flag_test.go index 5d0ecaea94..769f7bf687 100644 --- a/flag_test.go +++ b/flag_test.go @@ -121,8 +121,8 @@ func TestFlagsFromEnv(t *testing.T) { a := App{ Flags: []Flag{test.flag}, Action: func(ctx *Context) error { - 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])) + 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])) } return nil }, From 615e70ef221c7319679fbcafe151f34a75e26513 Mon Sep 17 00:00:00 2001 From: Jim Powers Date: Mon, 18 Nov 2019 07:38:48 -0500 Subject: [PATCH 3/5] Rebased upstream - Fixed NPE --- context.go | 2 +- context_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/context.go b/context.go index b88b703824..13fb52358d 100644 --- a/context.go +++ b/context.go @@ -114,7 +114,7 @@ func (c *Context) Lineage() []*Context { 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{} { return c.flagSet.Lookup(name).Value.(flag.Getter).Get() } diff --git a/context_test.go b/context_test.go index 081a8c43b9..3cefcca02f 100644 --- a/context_test.go +++ b/context_test.go @@ -3,8 +3,8 @@ package cli import ( "context" "flag" - "sort" "os" + "sort" "strings" "testing" "time" @@ -328,7 +328,7 @@ func TestContextPropagation(t *testing.T) { parent := NewContext(nil, nil, nil) parent.Context = context.WithValue(context.Background(), "key", "val") ctx := NewContext(nil, nil, parent) - val := ctx.Value("key") + val := ctx.Context.Value("key") if val == nil { t.Fatal("expected a parent context to be inherited but got nil") } From 7123798a43b6e1bd0e174a4671aade1b3bd7f5f4 Mon Sep 17 00:00:00 2001 From: CallanTaylor Date: Tue, 19 Nov 2019 11:48:45 +1300 Subject: [PATCH 4/5] Close file' --- build.go | 1 + 1 file changed, 1 insertion(+) diff --git a/build.go b/build.go index 398a00e56a..325552cd0f 100644 --- a/build.go +++ b/build.go @@ -137,6 +137,7 @@ func GfmrunActionFunc(c *cli.Context) error { if err != nil { return err } + defer file.Close() var counter int scanner := bufio.NewScanner(file) From e4fc68c63ecdd2c732eb6024a39b73f9f19cdffa Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 19 Nov 2019 10:36:13 +0300 Subject: [PATCH 5/5] Fix wrong url for v2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Repo not found for `github.com/urfave/cli.v2` ``` → go get github.com/urfave/cli.v2 go get github.com/urfave/cli.v2: git ls-remote -q origin in $GOPATH/pkg/mod/cache/vcs/f2d73ffea2d87a2720e81700b9dcf7285d8c2e5750a4b4c55dff989e537a7c8e: exit status 128: remote: Repository not found. fatal: repository 'https://github.com/urfave/cli.v2/' not found ``` Correct path `github.com/urfave/cli/v2` ``` → go get github.com/urfave/cli/v2 go: finding github.com/urfave/cli/v2 v2.0.0-alpha.2 go: downloading github.com/urfave/cli/v2 v2.0.0-alpha.2 go: extracting github.com/urfave/cli/v2 v2.0.0-alpha.2 ``` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ffb9e2e6e6..3a944f5ee7 100644 --- a/README.md +++ b/README.md @@ -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. ``` -$ go get github.com/urfave/cli.v2 +$ go get github.com/urfave/cli/v2 ``` ```go