Skip to content

Commit

Permalink
doc: add documentation generator (#1181)
Browse files Browse the repository at this point in the history
Co-authored-by: Rémy Léone <rleone@scaleway.com>
  • Loading branch information
jerome-quere and remyleone authored Jul 10, 2020
1 parent 5150184 commit 841acb9
Show file tree
Hide file tree
Showing 31 changed files with 5,921 additions and 80 deletions.
17 changes: 17 additions & 0 deletions cmd/pouet/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"fmt"

"github.com/scaleway/scaleway-cli/internal/namespaces"
)

// This command is used to generate markdown documentation for each commands (custom or generated) of the CLI
func main() {
commands := namespaces.GetCommands()
for _, c := range commands.GetAll() {
if c.Namespace == "instance" {
fmt.Printf("%s %s %s | %s\n", c.Namespace, c.Resource, c.Verb, c.Short)
}
}
}
32 changes: 32 additions & 0 deletions cmd/scw-doc-gen/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"flag"
"fmt"
"os"

"github.com/scaleway/scaleway-cli/internal/docgen"
"github.com/scaleway/scaleway-cli/internal/namespaces"
)

// This command is used to generate markdown documentation for each commands (custom or generated) of the CLI
func main() {
commands := namespaces.GetCommands()

outDir := flag.String("outdir", "./docs/commands", "Directory where markdown will be created")
flag.Parse()

stats, err := os.Stat(*outDir)
if err != nil {
panic(err)
}

if !stats.IsDir() {
panic(fmt.Errorf("outdir %s must be a valid directory", *outDir))
}

err = docgen.GenerateDocs(commands, *outDir)
if err != nil {
panic(err)
}
}
4 changes: 3 additions & 1 deletion cmd/scw/main_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"strings"
"testing"

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

for _, cmd := range namespaces.GetCommands().GetAll() {
commandLine := cmd.GetCommandLine()
commandLine := cmd.GetCommandLine("scw")
commandLine = strings.TrimPrefix(commandLine, "scw ")
if _, exists := excludedCommands[commandLine]; exists || cmd.Hidden {
continue
}
Expand Down
21 changes: 21 additions & 0 deletions cmd/scw/testdata/test-all-usage-autocomplete-usage.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟥🟥🟥 STDERR️️ 🟥🟥🟥️
Autocomplete related commands

USAGE:
scw autocomplete <command>

AVAILABLE COMMANDS:
install Install autocomplete script
script Show autocomplete script for current shell

FLAGS:
-h, --help help for autocomplete

GLOBAL FLAGS:
-c, --config string The path to the config file
-D, --debug Enable debug mode
-o, --output string Output format: json or human, see 'scw help output' for more info (default "human")
-p, --profile string The config profile to use

Use "scw autocomplete [command] --help" for more information about a command.
1 change: 1 addition & 0 deletions cmd/scw/testdata/test-main-usage-usage.golden
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ USAGE:

AVAILABLE COMMANDS:
account Account API
autocomplete Autocomplete related commands
baremetal Baremetal API
config Config file management
feedback Send feedback to the Scaleway CLI Team!
Expand Down
152 changes: 152 additions & 0 deletions docs/commands/account.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<!-- DO NOT EDIT: this file is automatically generated using scw-doc-gen -->
# Documentation for `scw account`
Account API

- [SSH keys management commands](#ssh-keys-management-commands)
- [Add a SSH key to your organization](#add-a-ssh-key-to-your-organization)
- [Get a SSH key from your organization](#get-a-ssh-key-from-your-organization)
- [Initialize SSH key](#initialize-ssh-key)
- [List all SSH keys of your organization](#list-all-ssh-keys-of-your-organization)
- [Remove a SSH key from your organization](#remove-a-ssh-key-from-your-organization)
- [Update a SSH key on your organization](#update-a-ssh-key-on-your-organization)


## SSH keys management commands

SSH keys management commands.


### Add a SSH key to your organization

Add a SSH key to your organization.

**Usage:**

```
scw account ssh-key add [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| name | | The name of the SSH key |
| public-key | Required | SSH public key. Currently ssh-rsa, ssh-dss (DSA), ssh-ed25519 and ecdsa keys with NIST curves are supported |
| project-id | | Project owning the resource |
| organization-id | | Organization ID to use. If none is passed will use default organization ID from the config |


**Examples:**


Add a given ssh key
```
scw account ssh-key add name=foobar public_key="$(cat <path/to/your/public/key>)"
```




### Get a SSH key from your organization

Get a SSH key from your organization.

**Usage:**

```
scw account ssh-key get <ssh-key-id ...> [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| ssh-key-id | Required | The ID of the SSH key |



### Initialize SSH key

Initialize SSH key.

**Usage:**

```
scw account ssh-key init
```



### List all SSH keys of your organization

List all SSH keys of your organization.

**Usage:**

```
scw account ssh-key list [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| order-by | One of: `created_at_asc`, `created_at_desc`, `updated_at_asc`, `updated_at_desc`, `name_asc`, `name_desc` | |
| name | | |
| project-id | | |
| organization-id | | |



### Remove a SSH key from your organization

Remove a SSH key from your organization.

**Usage:**

```
scw account ssh-key remove <ssh-key-id ...> [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| ssh-key-id | Required | |


**Examples:**


Remove a given SSH key
```
scw account ssh-key remove 11111111-1111-1111-1111-111111111111
```




### Update a SSH key on your organization

Update a SSH key on your organization.

**Usage:**

```
scw account ssh-key update <ssh-key-id ...> [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| ssh-key-id | Required | |
| name | | |



50 changes: 50 additions & 0 deletions docs/commands/autocomplete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!-- DO NOT EDIT: this file is automatically generated using scw-doc-gen -->
# Documentation for `scw autocomplete`
Autocomplete related commands

- [Install autocomplete script](#install-autocomplete-script)
- [Show autocomplete script for current shell](#show-autocomplete-script-for-current-shell)


## Install autocomplete script

Install autocomplete script for a given shell and OS.

Install autocomplete script for a given shell and OS.

**Usage:**

```
scw autocomplete install [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| shell | | |



## Show autocomplete script for current shell

Show autocomplete script for current shell.

Show autocomplete script for current shell.

**Usage:**

```
scw autocomplete script [arg=value ...]
```


**Args:**

| Name | | Description |
|------|---|-------------|
| shell | Default: `/bin/zsh` | |



Loading

0 comments on commit 841acb9

Please sign in to comment.