Skip to content

Commit 96e9277

Browse files
docs: Add Cobra docs generator and CI to ensure they remain up to date (#2336)
Co-authored-by: Jack Wotherspoon <jackwoth@google.com>
1 parent 9cb444c commit 96e9277

12 files changed

Lines changed: 671 additions & 1 deletion

.github/workflows/docs.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: docs
16+
on:
17+
pull_request:
18+
19+
# Declare default permissions as read only.
20+
permissions: read-all
21+
22+
jobs:
23+
docs:
24+
name: Check docs are up to date
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Setup Go
28+
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
29+
with:
30+
go-version: "1.23"
31+
- name: Checkout code
32+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
33+
- name: Generate docs and fail if there are differences
34+
run: |
35+
go install ./cmd/gendocs
36+
gendocs
37+
git diff --exit-code

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ debug = true
371371
debug-logs = true
372372
```
373373

374-
Run `./cloud-sql-proxy --help` for more details.
374+
Run `./cloud-sql-proxy --help` for more details. See the full documentation
375+
in [docs/cmd](docs/cmd).
375376

376377
### Config environment variables
377378

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"fmt"
19+
"os"
20+
"path/filepath"
21+
22+
"github.com/GoogleCloudPlatform/cloud-sql-proxy/v2/cmd"
23+
"github.com/spf13/cobra/doc"
24+
)
25+
26+
func main() {
27+
if len(os.Args) > 2 {
28+
fmt.Fprintf(os.Stderr, "usage: %s [output directory]\n", os.Args[0])
29+
os.Exit(1)
30+
}
31+
32+
path := "docs/cmd"
33+
if len(os.Args) == 2 {
34+
path = os.Args[1]
35+
}
36+
37+
outDir, err := filepath.Abs(path)
38+
if err != nil {
39+
fmt.Fprintf(os.Stderr, "failed to get output directory: %v\n", err)
40+
os.Exit(1)
41+
}
42+
43+
// Set environment variables used so the output is consistent,
44+
// regardless of where we run.
45+
os.Setenv("TMPDIR", "/tmp")
46+
47+
cloudSQLProxy := cmd.NewCommand()
48+
cloudSQLProxy.Execute()
49+
cloudSQLProxy.Command.DisableAutoGenTag = true
50+
doc.GenMarkdownTree(cloudSQLProxy.Command, outDir)
51+
}

docs/cmd/cloud-sql-proxy.md

Lines changed: 299 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## cloud-sql-proxy completion
2+
3+
Generate the autocompletion script for the specified shell
4+
5+
### Synopsis
6+
7+
Generate the autocompletion script for cloud-sql-proxy for the specified shell.
8+
See each sub-command's help for details on how to use the generated script.
9+
10+
11+
### Options
12+
13+
```
14+
-h, --help help for completion
15+
```
16+
17+
### Options inherited from parent commands
18+
19+
```
20+
--http-address string Address for Prometheus and health check server (default "localhost")
21+
--http-port string Port for Prometheus and health check server (default "9090")
22+
```
23+
24+
### SEE ALSO
25+
26+
* [cloud-sql-proxy](cloud-sql-proxy.md) - cloud-sql-proxy authorizes and encrypts connections to Cloud SQL.
27+
* [cloud-sql-proxy completion bash](cloud-sql-proxy_completion_bash.md) - Generate the autocompletion script for bash
28+
* [cloud-sql-proxy completion fish](cloud-sql-proxy_completion_fish.md) - Generate the autocompletion script for fish
29+
* [cloud-sql-proxy completion powershell](cloud-sql-proxy_completion_powershell.md) - Generate the autocompletion script for powershell
30+
* [cloud-sql-proxy completion zsh](cloud-sql-proxy_completion_zsh.md) - Generate the autocompletion script for zsh
31+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
## cloud-sql-proxy completion bash
2+
3+
Generate the autocompletion script for bash
4+
5+
### Synopsis
6+
7+
Generate the autocompletion script for the bash shell.
8+
9+
This script depends on the 'bash-completion' package.
10+
If it is not installed already, you can install it via your OS's package manager.
11+
12+
To load completions in your current shell session:
13+
14+
source <(cloud-sql-proxy completion bash)
15+
16+
To load completions for every new session, execute once:
17+
18+
#### Linux:
19+
20+
cloud-sql-proxy completion bash > /etc/bash_completion.d/cloud-sql-proxy
21+
22+
#### macOS:
23+
24+
cloud-sql-proxy completion bash > $(brew --prefix)/etc/bash_completion.d/cloud-sql-proxy
25+
26+
You will need to start a new shell for this setup to take effect.
27+
28+
29+
```
30+
cloud-sql-proxy completion bash
31+
```
32+
33+
### Options
34+
35+
```
36+
-h, --help help for bash
37+
--no-descriptions disable completion descriptions
38+
```
39+
40+
### Options inherited from parent commands
41+
42+
```
43+
--http-address string Address for Prometheus and health check server (default "localhost")
44+
--http-port string Port for Prometheus and health check server (default "9090")
45+
```
46+
47+
### SEE ALSO
48+
49+
* [cloud-sql-proxy completion](cloud-sql-proxy_completion.md) - Generate the autocompletion script for the specified shell
50+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
## cloud-sql-proxy completion fish
2+
3+
Generate the autocompletion script for fish
4+
5+
### Synopsis
6+
7+
Generate the autocompletion script for the fish shell.
8+
9+
To load completions in your current shell session:
10+
11+
cloud-sql-proxy completion fish | source
12+
13+
To load completions for every new session, execute once:
14+
15+
cloud-sql-proxy completion fish > ~/.config/fish/completions/cloud-sql-proxy.fish
16+
17+
You will need to start a new shell for this setup to take effect.
18+
19+
20+
```
21+
cloud-sql-proxy completion fish [flags]
22+
```
23+
24+
### Options
25+
26+
```
27+
-h, --help help for fish
28+
--no-descriptions disable completion descriptions
29+
```
30+
31+
### Options inherited from parent commands
32+
33+
```
34+
--http-address string Address for Prometheus and health check server (default "localhost")
35+
--http-port string Port for Prometheus and health check server (default "9090")
36+
```
37+
38+
### SEE ALSO
39+
40+
* [cloud-sql-proxy completion](cloud-sql-proxy_completion.md) - Generate the autocompletion script for the specified shell
41+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## cloud-sql-proxy completion powershell
2+
3+
Generate the autocompletion script for powershell
4+
5+
### Synopsis
6+
7+
Generate the autocompletion script for powershell.
8+
9+
To load completions in your current shell session:
10+
11+
cloud-sql-proxy completion powershell | Out-String | Invoke-Expression
12+
13+
To load completions for every new session, add the output of the above command
14+
to your powershell profile.
15+
16+
17+
```
18+
cloud-sql-proxy completion powershell [flags]
19+
```
20+
21+
### Options
22+
23+
```
24+
-h, --help help for powershell
25+
--no-descriptions disable completion descriptions
26+
```
27+
28+
### Options inherited from parent commands
29+
30+
```
31+
--http-address string Address for Prometheus and health check server (default "localhost")
32+
--http-port string Port for Prometheus and health check server (default "9090")
33+
```
34+
35+
### SEE ALSO
36+
37+
* [cloud-sql-proxy completion](cloud-sql-proxy_completion.md) - Generate the autocompletion script for the specified shell
38+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
## cloud-sql-proxy completion zsh
2+
3+
Generate the autocompletion script for zsh
4+
5+
### Synopsis
6+
7+
Generate the autocompletion script for the zsh shell.
8+
9+
If shell completion is not already enabled in your environment you will need
10+
to enable it. You can execute the following once:
11+
12+
echo "autoload -U compinit; compinit" >> ~/.zshrc
13+
14+
To load completions in your current shell session:
15+
16+
source <(cloud-sql-proxy completion zsh)
17+
18+
To load completions for every new session, execute once:
19+
20+
#### Linux:
21+
22+
cloud-sql-proxy completion zsh > "${fpath[1]}/_cloud-sql-proxy"
23+
24+
#### macOS:
25+
26+
cloud-sql-proxy completion zsh > $(brew --prefix)/share/zsh/site-functions/_cloud-sql-proxy
27+
28+
You will need to start a new shell for this setup to take effect.
29+
30+
31+
```
32+
cloud-sql-proxy completion zsh [flags]
33+
```
34+
35+
### Options
36+
37+
```
38+
-h, --help help for zsh
39+
--no-descriptions disable completion descriptions
40+
```
41+
42+
### Options inherited from parent commands
43+
44+
```
45+
--http-address string Address for Prometheus and health check server (default "localhost")
46+
--http-port string Port for Prometheus and health check server (default "9090")
47+
```
48+
49+
### SEE ALSO
50+
51+
* [cloud-sql-proxy completion](cloud-sql-proxy_completion.md) - Generate the autocompletion script for the specified shell
52+

docs/cmd/cloud-sql-proxy_wait.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## cloud-sql-proxy wait
2+
3+
Wait for another Proxy process to start
4+
5+
### Synopsis
6+
7+
8+
Waiting for Proxy Startup
9+
10+
Sometimes it is necessary to wait for the Proxy to start.
11+
12+
To help ensure the Proxy is up and ready, the Proxy includes a wait
13+
subcommand with an optional --max flag to set the maximum time to wait.
14+
The wait command uses a separate Proxy's startup endpoint to determine
15+
if the other Proxy process is ready.
16+
17+
Invoke the wait command, like this:
18+
19+
# waits for another Proxy process' startup endpoint to respond
20+
./cloud-sql-proxy wait
21+
22+
Configuration
23+
24+
By default, the Proxy will wait up to the maximum time for the startup
25+
endpoint to respond. The wait command requires that the Proxy be started in
26+
another process with the HTTP health check enabled. If an alternate health
27+
check port or address is used, as in:
28+
29+
./cloud-sql-proxy <INSTANCE_CONNECTION_NAME> \
30+
--http-address 0.0.0.0 \
31+
--http-port 9191
32+
33+
Then the wait command must also be told to use the same custom values:
34+
35+
./cloud-sql-proxy wait \
36+
--http-address 0.0.0.0 \
37+
--http-port 9191
38+
39+
By default the wait command will wait 30 seconds. To alter this value,
40+
use:
41+
42+
./cloud-sql-proxy wait --max 10s
43+
44+
45+
```
46+
cloud-sql-proxy wait [flags]
47+
```
48+
49+
### Options
50+
51+
```
52+
-h, --help help for wait
53+
-m, --max duration maximum amount of time to wait for startup (default 30s)
54+
```
55+
56+
### Options inherited from parent commands
57+
58+
```
59+
--http-address string Address for Prometheus and health check server (default "localhost")
60+
--http-port string Port for Prometheus and health check server (default "9090")
61+
```
62+
63+
### SEE ALSO
64+
65+
* [cloud-sql-proxy](cloud-sql-proxy.md) - cloud-sql-proxy authorizes and encrypts connections to Cloud SQL.
66+

0 commit comments

Comments
 (0)