Skip to content

Commit 841acb9

Browse files
doc: add documentation generator (#1181)
Co-authored-by: Rémy Léone <[email protected]>
1 parent 5150184 commit 841acb9

31 files changed

+5921
-80
lines changed

cmd/pouet/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/scaleway/scaleway-cli/internal/namespaces"
7+
)
8+
9+
// This command is used to generate markdown documentation for each commands (custom or generated) of the CLI
10+
func main() {
11+
commands := namespaces.GetCommands()
12+
for _, c := range commands.GetAll() {
13+
if c.Namespace == "instance" {
14+
fmt.Printf("%s %s %s | %s\n", c.Namespace, c.Resource, c.Verb, c.Short)
15+
}
16+
}
17+
}

cmd/scw-doc-gen/main.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"os"
7+
8+
"github.com/scaleway/scaleway-cli/internal/docgen"
9+
"github.com/scaleway/scaleway-cli/internal/namespaces"
10+
)
11+
12+
// This command is used to generate markdown documentation for each commands (custom or generated) of the CLI
13+
func main() {
14+
commands := namespaces.GetCommands()
15+
16+
outDir := flag.String("outdir", "./docs/commands", "Directory where markdown will be created")
17+
flag.Parse()
18+
19+
stats, err := os.Stat(*outDir)
20+
if err != nil {
21+
panic(err)
22+
}
23+
24+
if !stats.IsDir() {
25+
panic(fmt.Errorf("outdir %s must be a valid directory", *outDir))
26+
}
27+
28+
err = docgen.GenerateDocs(commands, *outDir)
29+
if err != nil {
30+
panic(err)
31+
}
32+
}

cmd/scw/main_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"strings"
45
"testing"
56

67
"github.com/scaleway/scaleway-cli/internal/core"
@@ -27,7 +28,8 @@ func Test_AllUsage(t *testing.T) {
2728
}
2829

2930
for _, cmd := range namespaces.GetCommands().GetAll() {
30-
commandLine := cmd.GetCommandLine()
31+
commandLine := cmd.GetCommandLine("scw")
32+
commandLine = strings.TrimPrefix(commandLine, "scw ")
3133
if _, exists := excludedCommands[commandLine]; exists || cmd.Hidden {
3234
continue
3335
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
2+
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
3+
Autocomplete related commands
4+
5+
USAGE:
6+
scw autocomplete <command>
7+
8+
AVAILABLE COMMANDS:
9+
install Install autocomplete script
10+
script Show autocomplete script for current shell
11+
12+
FLAGS:
13+
-h, --help help for autocomplete
14+
15+
GLOBAL FLAGS:
16+
-c, --config string The path to the config file
17+
-D, --debug Enable debug mode
18+
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
19+
-p, --profile string The config profile to use
20+
21+
Use "scw autocomplete [command] --help" for more information about a command.

cmd/scw/testdata/test-main-usage-usage.golden

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ USAGE:
55

66
AVAILABLE COMMANDS:
77
account Account API
8+
autocomplete Autocomplete related commands
89
baremetal Baremetal API
910
config Config file management
1011
feedback Send feedback to the Scaleway CLI Team!

docs/commands/account.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
<!-- DO NOT EDIT: this file is automatically generated using scw-doc-gen -->
2+
# Documentation for `scw account`
3+
Account API
4+
5+
- [SSH keys management commands](#ssh-keys-management-commands)
6+
- [Add a SSH key to your organization](#add-a-ssh-key-to-your-organization)
7+
- [Get a SSH key from your organization](#get-a-ssh-key-from-your-organization)
8+
- [Initialize SSH key](#initialize-ssh-key)
9+
- [List all SSH keys of your organization](#list-all-ssh-keys-of-your-organization)
10+
- [Remove a SSH key from your organization](#remove-a-ssh-key-from-your-organization)
11+
- [Update a SSH key on your organization](#update-a-ssh-key-on-your-organization)
12+
13+
14+
## SSH keys management commands
15+
16+
SSH keys management commands.
17+
18+
19+
### Add a SSH key to your organization
20+
21+
Add a SSH key to your organization.
22+
23+
**Usage:**
24+
25+
```
26+
scw account ssh-key add [arg=value ...]
27+
```
28+
29+
30+
**Args:**
31+
32+
| Name | | Description |
33+
|------|---|-------------|
34+
| name | | The name of the SSH key |
35+
| public-key | Required | SSH public key. Currently ssh-rsa, ssh-dss (DSA), ssh-ed25519 and ecdsa keys with NIST curves are supported |
36+
| project-id | | Project owning the resource |
37+
| organization-id | | Organization ID to use. If none is passed will use default organization ID from the config |
38+
39+
40+
**Examples:**
41+
42+
43+
Add a given ssh key
44+
```
45+
scw account ssh-key add name=foobar public_key="$(cat <path/to/your/public/key>)"
46+
```
47+
48+
49+
50+
51+
### Get a SSH key from your organization
52+
53+
Get a SSH key from your organization.
54+
55+
**Usage:**
56+
57+
```
58+
scw account ssh-key get <ssh-key-id ...> [arg=value ...]
59+
```
60+
61+
62+
**Args:**
63+
64+
| Name | | Description |
65+
|------|---|-------------|
66+
| ssh-key-id | Required | The ID of the SSH key |
67+
68+
69+
70+
### Initialize SSH key
71+
72+
Initialize SSH key.
73+
74+
**Usage:**
75+
76+
```
77+
scw account ssh-key init
78+
```
79+
80+
81+
82+
### List all SSH keys of your organization
83+
84+
List all SSH keys of your organization.
85+
86+
**Usage:**
87+
88+
```
89+
scw account ssh-key list [arg=value ...]
90+
```
91+
92+
93+
**Args:**
94+
95+
| Name | | Description |
96+
|------|---|-------------|
97+
| order-by | One of: `created_at_asc`, `created_at_desc`, `updated_at_asc`, `updated_at_desc`, `name_asc`, `name_desc` | |
98+
| name | | |
99+
| project-id | | |
100+
| organization-id | | |
101+
102+
103+
104+
### Remove a SSH key from your organization
105+
106+
Remove a SSH key from your organization.
107+
108+
**Usage:**
109+
110+
```
111+
scw account ssh-key remove <ssh-key-id ...> [arg=value ...]
112+
```
113+
114+
115+
**Args:**
116+
117+
| Name | | Description |
118+
|------|---|-------------|
119+
| ssh-key-id | Required | |
120+
121+
122+
**Examples:**
123+
124+
125+
Remove a given SSH key
126+
```
127+
scw account ssh-key remove 11111111-1111-1111-1111-111111111111
128+
```
129+
130+
131+
132+
133+
### Update a SSH key on your organization
134+
135+
Update a SSH key on your organization.
136+
137+
**Usage:**
138+
139+
```
140+
scw account ssh-key update <ssh-key-id ...> [arg=value ...]
141+
```
142+
143+
144+
**Args:**
145+
146+
| Name | | Description |
147+
|------|---|-------------|
148+
| ssh-key-id | Required | |
149+
| name | | |
150+
151+
152+

docs/commands/autocomplete.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!-- DO NOT EDIT: this file is automatically generated using scw-doc-gen -->
2+
# Documentation for `scw autocomplete`
3+
Autocomplete related commands
4+
5+
- [Install autocomplete script](#install-autocomplete-script)
6+
- [Show autocomplete script for current shell](#show-autocomplete-script-for-current-shell)
7+
8+
9+
## Install autocomplete script
10+
11+
Install autocomplete script for a given shell and OS.
12+
13+
Install autocomplete script for a given shell and OS.
14+
15+
**Usage:**
16+
17+
```
18+
scw autocomplete install [arg=value ...]
19+
```
20+
21+
22+
**Args:**
23+
24+
| Name | | Description |
25+
|------|---|-------------|
26+
| shell | | |
27+
28+
29+
30+
## Show autocomplete script for current shell
31+
32+
Show autocomplete script for current shell.
33+
34+
Show autocomplete script for current shell.
35+
36+
**Usage:**
37+
38+
```
39+
scw autocomplete script [arg=value ...]
40+
```
41+
42+
43+
**Args:**
44+
45+
| Name | | Description |
46+
|------|---|-------------|
47+
| shell | Default: `/bin/zsh` | |
48+
49+
50+

0 commit comments

Comments
 (0)