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

Improve docs generation for cli.Authors #900

Merged
merged 4 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.coverprofile
*.orig
node_modules/
vendor
vendor
18 changes: 17 additions & 1 deletion docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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()
Expand Down
7 changes: 3 additions & 4 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whst if authors is not set just author, that would be confusing as it would not work.

Copy link
Member Author

@saschagrunert saschagrunert Oct 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this will catch it, doesn't it?

cli/app.go

Lines 142 to 144 in 63cd2e3

if a.Author != "" || a.Email != "" {
a.Authors = append(a.Authors, Author{Name: a.Author, Email: a.Email})
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes.


# NAME

Expand Down
7 changes: 5 additions & 2 deletions testdata/expected-doc-full.man
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 3 additions & 2 deletions testdata/expected-doc-full.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
% greet(8)
% greet(8)

% Harrison
% Harrison <harrison@lolwut.com>
% Oliver Allen <oliver@toyshop.com>

# NAME

Expand Down
61 changes: 61 additions & 0 deletions testdata/expected-doc-no-authors.md
Original file line number Diff line number Diff line change
@@ -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


5 changes: 3 additions & 2 deletions testdata/expected-doc-no-commands.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
% greet(8)
% greet(8)

% Harrison
% Harrison <harrison@lolwut.com>
% Oliver Allen <oliver@toyshop.com>

# NAME

Expand Down
5 changes: 3 additions & 2 deletions testdata/expected-doc-no-flags.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
% greet(8)
% greet(8)

% Harrison
% Harrison <harrison@lolwut.com>
% Oliver Allen <oliver@toyshop.com>

# NAME

Expand Down