Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2cb62f5

Browse filesBrowse files
committed
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 <sgrunert@suse.com>
1 parent 0587424 commit 2cb62f5
Copy full SHA for 2cb62f5

8 files changed

+97-14Lines changed: 97 additions & 14 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.gitignore‎

Copy file name to clipboard
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
*.coverprofile
2+
*.orig
23
node_modules/
3-
vendor
4+
vendor
Collapse file

‎docs_test.go‎

Copy file name to clipboardExpand all lines: docs_test.go
+17-1Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ func testApp() *App {
6464
}}
6565
app.UsageText = "app [first_arg] [second_arg]"
6666
app.Usage = "Some app"
67-
app.Authors = []*Author{{Name: "Harrison", Email: "harrison@lolwut.com"}}
67+
app.Authors = []*Author{
68+
{Name: "Harrison", Email: "harrison@lolwut.com"},
69+
{Name: "Oliver Allen", Email: "oliver@toyshop.com"},
70+
}
6871
return app
6972
}
7073

@@ -112,6 +115,19 @@ func TestToMarkdownNoCommands(t *testing.T) {
112115
expectFileContent(t, "testdata/expected-doc-no-commands.md", res)
113116
}
114117

118+
func TestToMarkdownNoAuthors(t *testing.T) {
119+
// Given
120+
app := testApp()
121+
app.Authors = []*Author{}
122+
123+
// When
124+
res, err := app.ToMarkdown()
125+
126+
// Then
127+
expect(t, err, nil)
128+
expectFileContent(t, "testdata/expected-doc-no-authors.md", res)
129+
}
130+
115131
func TestToMan(t *testing.T) {
116132
// Given
117133
app := testApp()
Collapse file

‎template.go‎

Copy file name to clipboardExpand all lines: template.go
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,9 @@ OPTIONS:
7171
{{end}}{{end}}
7272
`
7373

74-
var MarkdownDocTemplate = `% {{ .App.Name }}(8) {{ .App.Description }}
75-
{{ range $Author := .App.Authors}}
76-
% {{ $Author.Name }}
77-
{{- end}}
74+
var MarkdownDocTemplate = `% {{ .App.Name }}(8){{ if .App.Description }} {{ .App.Description }}{{ end }}
75+
{{ range $a := .App.Authors }}
76+
% {{ $a }}{{ end }}
7877
7978
# NAME
8079
Collapse file

‎testdata/expected-doc-full.man‎

Copy file name to clipboardExpand all lines: testdata/expected-doc-full.man
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
.nh
2-
.TH greet(8)
2+
.TH greet(8)
33

4-
.SH Harrison
4+
.SH Harrison harrison@lolwut.com
5+
\[la]mailto:harrison@lolwut.com\[ra]
6+
Oliver Allen oliver@toyshop.com
7+
\[la]mailto:oliver@toyshop.com\[ra]
58

69
.SH NAME
710
.PP
Collapse file

‎testdata/expected-doc-full.md‎

Copy file name to clipboardExpand all lines: testdata/expected-doc-full.md
+3-2Lines changed: 3 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
% greet(8)
1+
% greet(8)
22

3-
% Harrison
3+
% Harrison <harrison@lolwut.com>
4+
% Oliver Allen <oliver@toyshop.com>
45

56
# NAME
67

Collapse file
+61Lines changed: 61 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
% greet(8)
2+
3+
4+
# NAME
5+
6+
greet - Some app
7+
8+
# SYNOPSIS
9+
10+
greet
11+
12+
```
13+
[--another-flag|-b]
14+
[--flag|--fl|-f]=[value]
15+
[--socket|-s]=[value]
16+
```
17+
18+
# DESCRIPTION
19+
20+
app [first_arg] [second_arg]
21+
22+
**Usage**:
23+
24+
```
25+
greet [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
26+
```
27+
28+
# GLOBAL OPTIONS
29+
30+
**--another-flag, -b**: another usage text
31+
32+
**--flag, --fl, -f**="":
33+
34+
**--socket, -s**="": some 'usage' text (default: value)
35+
36+
37+
# COMMANDS
38+
39+
## config, c
40+
41+
another usage test
42+
43+
**--another-flag, -b**: another usage text
44+
45+
**--flag, --fl, -f**="":
46+
47+
### sub-config, s, ss
48+
49+
another usage test
50+
51+
**--sub-command-flag, -s**: some usage text
52+
53+
**--sub-flag, --sub-fl, -s**="":
54+
55+
## info, i, in
56+
57+
retrieve generic information
58+
59+
## some-command
60+
61+
Collapse file

‎testdata/expected-doc-no-commands.md‎

Copy file name to clipboardExpand all lines: testdata/expected-doc-no-commands.md
+3-2Lines changed: 3 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
% greet(8)
1+
% greet(8)
22

3-
% Harrison
3+
% Harrison <harrison@lolwut.com>
4+
% Oliver Allen <oliver@toyshop.com>
45

56
# NAME
67

Collapse file

‎testdata/expected-doc-no-flags.md‎

Copy file name to clipboardExpand all lines: testdata/expected-doc-no-flags.md
+3-2Lines changed: 3 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
% greet(8)
1+
% greet(8)
22

3-
% Harrison
3+
% Harrison <harrison@lolwut.com>
4+
% Oliver Allen <oliver@toyshop.com>
45

56
# NAME
67

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.