Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 0e031d9

Browse files
committed
Add gendocs ci step
1 parent b9ebf97 commit 0e031d9

26 files changed

+157
-38
lines changed

.github/workflows/test.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,17 @@ jobs:
4444
uses: ./ci/image
4545
with:
4646
args: go test ./internal/... ./cmd/...
47+
gendocs:
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v1
51+
- uses: actions/cache@v1
52+
with:
53+
path: ~/go/pkg/mod
54+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
55+
restore-keys: |
56+
${{ runner.os }}-go-
57+
- name: generate-docs
58+
uses: ./ci/image
59+
with:
60+
args: ./ci/steps/gendocs.sh

ci/steps/fmt.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#!/bin/bash
2+
3+
set -euo pipefail
4+
25
echo "Formatting..."
36

47
go mod tidy
58
gofmt -w -s .
69
goimports -w "-local=$$(go list -m)" .
710

8-
if [ "$CI" != "" ]; then
9-
if [[ $(git ls-files --other --modified --exclude-standard) != "" ]]; then
11+
if [[ ${CI-} && $(git ls-files --other --modified --exclude-standard) ]]; then
1012
echo "Files need generation or are formatted incorrectly:"
1113
git -c color.ui=always status | grep --color=no '\e\[31m'
1214
echo "Please run the following locally:"
1315
echo " ./ci/steps/fmt.sh"
1416
exit 1
1517
fi
16-
fi

ci/steps/gendocs.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo "Generating docs..."
6+
7+
cd "$(dirname "$0")"
8+
cd ../../
9+
10+
go run ./cmd/coder gen-docs ./docs
11+
12+
# remove cobra footer from each file
13+
for filename in ./docs/*.md; do
14+
trimmed=$(head -n -1 "$filename")
15+
echo "$trimmed" > $filename
16+
done
17+
18+
19+
if [[ ${CI-} && $(git ls-files --other --modified --exclude-standard) ]]; then
20+
echo "Documentation needs generation:"
21+
git -c color.ui=always status | grep --color=no '\e\[31m'
22+
echo "Please run the following locally:"
23+
echo " ./ci/steps/gendocs.sh"
24+
exit 1
25+
fi

ci/steps/lint.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22

3+
set -euo pipefail
4+
35
echo "Linting..."
46

57
go vet ./...
6-
golint -set_exit_status ./...
8+
golint -set_exit_status ./...

docs/coder.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ coder provides a CLI for working with an existing Coder Enterprise installation
1414

1515
### SEE ALSO
1616

17+
* [coder completion](coder_completion.md) - Generate completion script
1718
* [coder config-ssh](coder_config-ssh.md) - Configure SSH to access Coder environments
1819
* [coder envs](coder_envs.md) - Interact with Coder environments
1920
* [coder login](coder_login.md) - Authenticate this client for future operations
@@ -23,4 +24,3 @@ coder provides a CLI for working with an existing Coder Enterprise installation
2324
* [coder sync](coder_sync.md) - Establish a one way directory sync to a Coder environment
2425
* [coder urls](coder_urls.md) - Interact with environment DevURLs
2526
* [coder users](coder_users.md) - Interact with Coder user accounts
26-

docs/coder_completion.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
## coder completion
2+
3+
Generate completion script
4+
5+
### Synopsis
6+
7+
To load completions:
8+
9+
Bash:
10+
11+
$ source <(coder completion bash)
12+
13+
To load completions for each session, execute once:
14+
Linux:
15+
$ coder completion bash > /etc/bash_completion.d/coder
16+
MacOS:
17+
$ coder completion bash > /usr/local/etc/bash_completion.d/coder
18+
19+
Zsh:
20+
21+
If shell completion is not already enabled in your environment you will need
22+
to enable it. You can execute the following once:
23+
24+
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
25+
26+
To load completions for each session, execute once:
27+
$ coder completion zsh > "${fpath[1]}/_coder"
28+
29+
You will need to start a new shell for this setup to take effect.
30+
31+
Fish:
32+
33+
$ coder completion fish | source
34+
35+
To load completions for each session, execute once:
36+
$ coder completion fish > ~/.config/fish/completions/coder.fish
37+
38+
39+
```
40+
coder completion [bash|zsh|fish|powershell]
41+
```
42+
43+
### Examples
44+
45+
```
46+
coder completion fish > ~/.config/fish/completions/coder.fish
47+
coder completion zsh > "${fpath[1]}/_coder"
48+
49+
Linux:
50+
$ coder completion bash > /etc/bash_completion.d/coder
51+
MacOS:
52+
$ coder completion bash > /usr/local/etc/bash_completion.d/coder
53+
```
54+
55+
### Options
56+
57+
```
58+
-h, --help help for completion
59+
```
60+
61+
### SEE ALSO
62+
63+
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

docs/coder_config-ssh.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ coder config-ssh [flags]
2121
### SEE ALSO
2222

2323
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
24-

docs/coder_envs.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,3 @@ Perform operations on the Coder environments owned by the active user.
1717

1818
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
1919
* [coder envs ls](coder_envs_ls.md) - list all environments owned by the active user
20-

docs/coder_envs_ls.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,3 @@ coder envs ls [flags]
2626
### SEE ALSO
2727

2828
* [coder envs](coder_envs.md) - Interact with Coder environments
29-

docs/coder_login.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ coder login [Coder Enterprise URL eg. http://my.coder.domain/] [flags]
1919
### SEE ALSO
2020

2121
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
22-

docs/coder_logout.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ coder logout [flags]
1919
### SEE ALSO
2020

2121
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
22-

docs/coder_secrets.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ Interact with secrets objects owned by the active user.
2020
* [coder secrets ls](coder_secrets_ls.md) - List all secrets owned by the active user
2121
* [coder secrets rm](coder_secrets_rm.md) - Remove one or more secrets by name
2222
* [coder secrets view](coder_secrets_view.md) - View a secret by name
23-

docs/coder_secrets_create.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,3 @@ coder secrets create aws-credentials --from-file ./credentials.json
3737
### SEE ALSO
3838

3939
* [coder secrets](coder_secrets.md) - Interact with Coder Secrets
40-

docs/coder_secrets_ls.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,3 @@ coder secrets ls [flags]
2525
### SEE ALSO
2626

2727
* [coder secrets](coder_secrets.md) - Interact with Coder Secrets
28-

docs/coder_secrets_rm.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@ coder secrets rm mysql-password mysql-user
3131
### SEE ALSO
3232

3333
* [coder secrets](coder_secrets.md) - Interact with Coder Secrets
34-

docs/coder_secrets_view.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,3 @@ coder secrets view mysql-password
3131
### SEE ALSO
3232

3333
* [coder secrets](coder_secrets.md) - Interact with Coder Secrets
34-

docs/coder_sh.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,3 @@ coder sh backend-env
2525
### SEE ALSO
2626

2727
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
28-

docs/coder_sync.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ coder sync [local directory] [<env name>:<remote directory>] [flags]
2020
### SEE ALSO
2121

2222
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
23-

docs/coder_urls.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ Interact with environment DevURLs
1818
* [coder urls create](coder_urls_create.md) - Create a new devurl for an environment
1919
* [coder urls ls](coder_urls_ls.md) - List all DevURLs for an environment
2020
* [coder urls rm](coder_urls_rm.md) - Remove a dev url
21-

docs/coder_urls_create.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,3 @@ coder urls create [env_name] [port] [--access <level>] [--name <name>] [flags]
2121
### SEE ALSO
2222

2323
* [coder urls](coder_urls.md) - Interact with environment DevURLs
24-

docs/coder_urls_ls.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,3 @@ coder urls ls [environment_name] [flags]
2020
### SEE ALSO
2121

2222
* [coder urls](coder_urls.md) - Interact with environment DevURLs
23-

docs/coder_urls_rm.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ coder urls rm [environment_name] [port] [flags]
1919
### SEE ALSO
2020

2121
* [coder urls](coder_urls.md) - Interact with environment DevURLs
22-

docs/coder_users.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,3 @@ Interact with Coder user accounts
1616

1717
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
1818
* [coder users ls](coder_users_ls.md) - list all user accounts
19-

docs/coder_users_ls.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,3 @@ coder users ls -o json | jq .[] | jq -r .email
2727
### SEE ALSO
2828

2929
* [coder users](coder_users.md) - Interact with Coder user accounts
30-

internal/cmd/cmd.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"os"
55

66
"github.com/spf13/cobra"
7+
"github.com/spf13/cobra/doc"
78
)
89

910
// Make constructs the "coder" root command
@@ -24,43 +25,65 @@ func Make() *cobra.Command {
2425
makeSyncCmd(),
2526
makeURLCmd(),
2627
completionCmd,
28+
genDocs(app),
2729
)
2830
return app
2931
}
3032

33+
func genDocs(rootCmd *cobra.Command) *cobra.Command {
34+
cmd := &cobra.Command{
35+
Use: "gen-docs [dir_path]",
36+
Short: "Generate a markdown documentation tree for the root command.",
37+
Example: "coder gen-docs ./docs",
38+
Args: cobra.ExactArgs(1),
39+
Hidden: true,
40+
RunE: func(_ *cobra.Command, args []string) error {
41+
return doc.GenMarkdownTree(rootCmd, args[0])
42+
},
43+
}
44+
return cmd
45+
}
46+
3147
// reference: https://github.com/spf13/cobra/blob/master/shell_completions.md
3248
var completionCmd = &cobra.Command{
3349
Use: "completion [bash|zsh|fish|powershell]",
3450
Short: "Generate completion script",
51+
Example: `coder completion fish > ~/.config/fish/completions/coder.fish
52+
coder completion zsh > "${fpath[1]}/_coder"
53+
54+
Linux:
55+
$ coder completion bash > /etc/bash_completion.d/coder
56+
MacOS:
57+
$ coder completion bash > /usr/local/etc/bash_completion.d/coder`,
3558
Long: `To load completions:
3659
3760
Bash:
3861
3962
$ source <(coder completion bash)
4063
41-
# To load completions for each session, execute once:
64+
To load completions for each session, execute once:
4265
Linux:
4366
$ coder completion bash > /etc/bash_completion.d/coder
4467
MacOS:
4568
$ coder completion bash > /usr/local/etc/bash_completion.d/coder
4669
4770
Zsh:
4871
49-
# If shell completion is not already enabled in your environment you will need
50-
# to enable it. You can execute the following once:
72+
If shell completion is not already enabled in your environment you will need
73+
to enable it. You can execute the following once:
5174
5275
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
5376
54-
# To load completions for each session, execute once:
77+
To load completions for each session, execute once:
5578
$ coder completion zsh > "${fpath[1]}/_coder"
5679
57-
# You will need to start a new shell for this setup to take effect.
80+
You will need to start a new shell for this setup to take effect.
5881
5982
Fish:
6083
6184
$ coder completion fish | source
6285
63-
# To load completions for each session, execute once:
86+
To load completions for each session, execute once:
6487
$ coder completion fish > ~/.config/fish/completions/coder.fish
6588
`,
6689
DisableFlagsInUseLine: true,

0 commit comments

Comments
 (0)