Skip to content

Commit 7063066

Browse files
committed
feat: cli output shortcode
1 parent 1df7c66 commit 7063066

File tree

4 files changed

+43
-70
lines changed

4 files changed

+43
-70
lines changed

docs/content/docs/configuration/cli.md

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ title: Command-Line
33
weight: 1
44
---
55

6-
```console
7-
$ golangci-lint -h
8-
{.CmdRootHelpText}
9-
```
6+
{{% cli-output %}}
107

118
## `run`
129

@@ -16,10 +13,7 @@ $ golangci-lint -h
1613
{{< card link="/docs/linters/configuration/" title="Linter Settings" icon="adjustments" >}}
1714
{{< /cards >}}
1815

19-
```console
20-
$ golangci-lint run -h
21-
{.CmdRunHelpText}
22-
```
16+
{{% cli-output cmd="run" %}}
2317

2418
When the `--cpu-profile-path` or `--mem-profile-path` arguments are specified,
2519
golangci-lint writes runtime profiling data in the format expected by the [pprof](https://github.com/google/pprof) visualization tool.
@@ -35,38 +29,23 @@ the `go tool trace` command and visualization tool.
3529
{{< card link="/docs/formatters/configuration/" title="Formatter Settings" icon="adjustments" >}}
3630
{{< /cards >}}
3731

38-
```console
39-
$ golangci-lint fmt -h
40-
{.CmdFmtHelpText}
41-
```
32+
{{% cli-output cmd="fmt" %}}
4233

4334
## `migrate`
4435

45-
```console
46-
$ golangci-lint migrate -h
47-
{.CmdMigrateHelpText}
48-
```
36+
{{% cli-output cmd="migrate" %}}
4937

5038
## `formatters`
5139

52-
```console
53-
$ golangci-lint formatters -h
54-
{.CmdFormattersHelpText}
55-
```
40+
{{% cli-output cmd="formatters" %}}
5641

5742
## `help`
5843

59-
```console
60-
$ golangci-lint help -h
61-
{.CmdHelpText}
62-
```
44+
{{% cli-output cmd="help" %}}
6345

6446
## `linters`
6547

66-
```console
67-
$ golangci-lint linters -h
68-
{.CmdLintersHelpText}
69-
```
48+
{{% cli-output cmd="linters" %}}
7049

7150
## `cache`
7251

@@ -76,35 +55,20 @@ You can override the default cache directory with the environment variable `GOLA
7655

7756
The cache is only used by `golangci-lint run` (linters).
7857

79-
```console
80-
$ golangci-lint cache -h
81-
{.CmdCacheHelpText}
82-
```
58+
{{% cli-output cmd="cache" %}}
8359

8460
## `config`
8561

86-
```console
87-
$ golangci-lint config -h
88-
{.CmdConfigHelpText}
89-
```
62+
{{% cli-output cmd="config" %}}
9063

9164
## `custom`
9265

93-
```console
94-
$ golangci-lint custom -h
95-
{.CmdCustomHelpText}
96-
```
66+
{{% cli-output cmd="custom" %}}
9767

9868
## `version`
9969

100-
```console
101-
$ golangci-lint version -h
102-
{.CmdVersionHelpText}
103-
```
70+
{{% cli-output cmd="version" %}}
10471

10572
## `completion`
10673

107-
```console
108-
$ golangci-lint completion -h
109-
{.CmdCompletionHelpText}
110-
```
74+
{{% cli-output cmd="completion" %}}

docs/content/docs/product/migration-guide.md

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,7 @@ Other fields explicitly defined in the configuration file are migrated even if t
4646

4747
The `migrate` command automatically migrates `linters.presets` in individual linters to `linters.enable`.
4848

49-
```txt
50-
Migrate configuration file from v1 to v2
51-
52-
Usage:
53-
golangci-lint migrate [flags]
54-
55-
Flags:
56-
-c, --config PATH Read config from file path PATH
57-
--no-config Don't read config file
58-
--format string Output file format.
59-
By default, the format of the input configuration file is used.
60-
It can be 'yml', 'yaml', 'toml', or 'json'.
61-
--skip-validation Skip validation of the configuration file against the JSON Schema for v1.
62-
63-
Global Flags:
64-
-h, --help Help for a command
65-
66-
```
49+
{{% cli-output cmd="migrate" %}}
6750

6851
## Changes
6952

docs/content/docs/welcome/quick-start.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ It's not possible to mix files and packages/directories, and files must come fro
3030

3131
Golangci-lint can be used with zero configuration. By default, the following linters are enabled:
3232

33-
```console
34-
$ golangci-lint help linters
35-
{.LintersCommandOutputEnabledOnly}
36-
```
33+
{{% cli-output section="defaultEnabledLinters" cmd="help linters" %}}
3734

3835
Pass `-E/--enable` to enable linter and `-D/--disable` to disable:
3936

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{{- /*
2+
Creates a code block with the output of the CLI.
3+
4+
@param {string} cmd The name of the command.
5+
@param {string} section The name of the section inside the data file.
6+
7+
@example {{% cli-output %}}
8+
@example {{% cli-output cmd="foo" %}}
9+
@example {{% cli-output section="sectionName" cmd="foo bar" %}}
10+
*/ -}}
11+
12+
{{- $cmdName := .Get "cmd" -}}
13+
{{- $section := .Get "section" -}}
14+
15+
{{- $cliData := index $.Site.Data.cli_help -}}
16+
17+
```console
18+
{{ if $section -}}
19+
20+
$ golangci-lint {{ $cmdName }}
21+
22+
{{- else -}}
23+
{{- $section = print (or $cmdName "root") "Output" -}}
24+
25+
$ golangci-lint{{ if $cmdName }} {{ $cmdName }}{{ end }} -h
26+
27+
{{- end }}
28+
{{ index $cliData $section | safeHTML }}
29+
```

0 commit comments

Comments
 (0)