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

feat(docs): Include Description and UsageText in docs output #1287

Merged
merged 1 commit into from Jul 7, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions docs_test.go
Expand Up @@ -110,6 +110,7 @@ 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"},
Expand Down Expand Up @@ -178,6 +179,19 @@ func TestToMarkdownNoAuthors(t *testing.T) {
expectFileContent(t, "testdata/expected-doc-no-authors.md", res)
}

func TestToMarkdownNoUsageText(t *testing.T) {
// Given
app := testApp()
app.UsageText = ""

// When
res, err := app.ToMarkdown()

// Then
expect(t, err, nil)
expectFileContent(t, "testdata/expected-doc-no-usagetext.md", res)
}

func TestToMan(t *testing.T) {
// Given
app := testApp()
Expand Down
10 changes: 6 additions & 4 deletions template.go
Expand Up @@ -86,16 +86,18 @@ var MarkdownDocTemplate = `% {{ .App.Name }} {{ .SectionNum }}
{{ if .SynopsisArgs }}
` + "```" + `
{{ range $v := .SynopsisArgs }}{{ $v }}{{ end }}` + "```" + `
{{ end }}{{ if .App.UsageText }}
{{ end }}{{ if .App.Description }}
# DESCRIPTION

{{ .App.UsageText }}
{{ .App.Description }}
{{ end }}
**Usage**:

` + "```" + `
` + "```" + `{{ if .App.UsageText }}
{{ .App.UsageText }}
{{ else }}
{{ .App.Name }} [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
` + "```" + `
{{ end }}` + "```" + `
{{ if .GlobalArgs }}
# GLOBAL OPTIONS
{{ range $v := .GlobalArgs }}
Expand Down
4 changes: 2 additions & 2 deletions testdata/expected-doc-full.man
Expand Up @@ -24,7 +24,7 @@ greet

.SH DESCRIPTION
.PP
app [first\_arg] [second\_arg]
Description of the application.

.PP
\fBUsage\fP:
Expand All @@ -33,7 +33,7 @@ app [first\_arg] [second\_arg]
.RS

.nf
greet [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
app [first\_arg] [second\_arg]

.fi
.RE
Expand Down
4 changes: 2 additions & 2 deletions testdata/expected-doc-full.md
Expand Up @@ -16,12 +16,12 @@ greet

# DESCRIPTION

app [first_arg] [second_arg]
Description of the application.

**Usage**:

```
greet [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
app [first_arg] [second_arg]
```

# GLOBAL OPTIONS
Expand Down
4 changes: 2 additions & 2 deletions testdata/expected-doc-no-authors.md
Expand Up @@ -16,12 +16,12 @@ greet

# DESCRIPTION

app [first_arg] [second_arg]
Description of the application.

**Usage**:

```
greet [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
app [first_arg] [second_arg]
```

# GLOBAL OPTIONS
Expand Down
4 changes: 2 additions & 2 deletions testdata/expected-doc-no-commands.md
Expand Up @@ -16,12 +16,12 @@ greet

# DESCRIPTION

app [first_arg] [second_arg]
Description of the application.

**Usage**:

```
greet [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
app [first_arg] [second_arg]
```

# GLOBAL OPTIONS
Expand Down
4 changes: 2 additions & 2 deletions testdata/expected-doc-no-flags.md
Expand Up @@ -10,12 +10,12 @@ greet

# DESCRIPTION

app [first_arg] [second_arg]
Description of the application.

**Usage**:

```
greet [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
app [first_arg] [second_arg]
```

# COMMANDS
Expand Down
86 changes: 86 additions & 0 deletions testdata/expected-doc-no-usagetext.md
@@ -0,0 +1,86 @@
% greet 8

# NAME

greet - Some app

# SYNOPSIS

greet

```
[--another-flag|-b]
[--flag|--fl|-f]=[value]
[--socket|-s]=[value]
```

# DESCRIPTION

Description of the application.

**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


## usage, u

standard usage text

Usage for the usage text
- formatted: Based on the specified ConfigMap and summon secrets.yml
- list: Inspect the environment for a specific process running on a Pod
- for_effect: Compare 'namespace' environment with 'local'

```
func() { ... }
```

Should be a part of the same code block

**--another-flag, -b**: another usage text

**--flag, --fl, -f**="":

### sub-usage, su

standard usage text

>Single line of UsageText

**--sub-command-flag, -s**: some usage text