Skip to content

Commit 6dfbc85

Browse files
committed
📖 Add generated README
1 parent 4845de3 commit 6dfbc85

6 files changed

Lines changed: 194 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ jobs:
3434
go mod tidy
3535
git diff --exit-code -- go.mod go.sum
3636
37+
- name: Verify generated README
38+
run: |
39+
go generate ./...
40+
git diff --exit-code -- README.md
41+
3742
- name: Verify formatting
3843
run: test -z "$(gofmt -l .)"
3944

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode/
2+
caphcli

README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# caphcli
2+
3+
`caphcli` is a standalone CLI for CAPH bare-metal provisioning checks.
4+
5+
It currently exposes the `check-bm-servers` command that was extracted from CAPH PR `#1873` and moved into this repository.
6+
7+
## Build
8+
9+
```bash
10+
go build .
11+
```
12+
13+
## Required Environment Variables
14+
15+
- `HETZNER_ROBOT_USER` and `HETZNER_ROBOT_PASSWORD` for Hetzner Robot API access.
16+
- `SSH_KEY_NAME` for the Robot SSH key name to use or create.
17+
- One of `HETZNER_SSH_PUB_PATH` or `HETZNER_SSH_PUB` for the SSH public key.
18+
- One of `HETZNER_SSH_PRIV_PATH` or `HETZNER_SSH_PRIV` for the SSH private key.
19+
20+
## Keeping This README Up To Date
21+
22+
The official Cobra helper for generated command docs is `github.com/spf13/cobra/doc`.
23+
This repo keeps the help blocks below in sync with the actual command tree via:
24+
25+
```bash
26+
go generate ./...
27+
```
28+
29+
That runs `go run ./internal/tools/readmegen`, which rebuilds this README from the live Cobra commands.
30+
31+
## CLI Help
32+
33+
### `caphcli --help`
34+
35+
```text
36+
CAPH developer and operations CLI
37+
38+
Usage:
39+
caphcli [command]
40+
41+
Available Commands:
42+
check-bm-servers Validate rescue and provisioning reliability for one bare-metal server
43+
completion Generate the autocompletion script for the specified shell
44+
help Help about any command
45+
46+
Flags:
47+
-h, --help help for caphcli
48+
49+
Use "caphcli [command] --help" for more information about a command.
50+
```
51+
52+
### `caphcli check-bm-servers --help`
53+
54+
```text
55+
Validate rescue and provisioning reliability for one HetznerBareMetalHost from a local YAML file.
56+
57+
The command does not talk to Kubernetes. It reads one local YAML file containing
58+
HetznerBareMetalHost objects and then talks directly to Hetzner Robot plus the
59+
target server.
60+
61+
Usage:
62+
caphcli check-bm-servers [flags]
63+
64+
Examples:
65+
caphcli check-bm-servers \
66+
--file test/e2e/data/infrastructure-hetzner/v1beta1/bases/hetznerbaremetalhosts.yaml \
67+
--name bm-e2e-1731561
68+
69+
Flags:
70+
--file string Path to a local YAML file containing HetznerBareMetalHost objects (required)
71+
--force Skip the destructive-action confirmation prompt
72+
-h, --help help for check-bm-servers
73+
--image-path string Installimage IMAGE path for operating system inside the Hetzner rescue system (default "/root/.oldroot/nfs/images/Ubuntu-2404-noble-amd64-base.tar.gz")
74+
--name string HetznerBareMetalHost metadata.name. Optional if YAML contains exactly one host
75+
--poll-interval duration Polling interval for wait steps (default 10s)
76+
--timeout-activate-rescue duration Timeout for activating rescue boot (default 45s)
77+
--timeout-check-disk-rescue duration Timeout for checking target disks in rescue (default 1m0s)
78+
--timeout-ensure-ssh-key duration Timeout for ensuring SSH key in Robot (default 1m0s)
79+
--timeout-fetch-server duration Timeout for fetching server details from Robot (default 30s)
80+
--timeout-install duration Timeout for one Ubuntu install step (default 9m0s)
81+
--timeout-load-input duration Timeout for input parsing + env loading (default 30s)
82+
--timeout-reboot-os duration Timeout for rebooting into installed OS (default 45s)
83+
--timeout-reboot-rescue duration Timeout for requesting reboot to rescue (default 45s)
84+
--timeout-wait-os duration Timeout for waiting until installed OS is reachable (default 6m0s)
85+
--timeout-wait-rescue duration Timeout for waiting until rescue SSH is reachable (default 6m0s)
86+
```

generate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package main
2+
3+
//go:generate go run ./internal/tools/readmegen

internal/cmd/root.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ func NewRootCommand() *cobra.Command {
1313
data.RegisterEmbeddedInstallImageTGZ()
1414

1515
rootCmd := &cobra.Command{
16-
Use: "caphcli",
17-
Short: "CAPH developer and operations CLI",
18-
SilenceUsage: true,
19-
SilenceErrors: false,
16+
Use: "caphcli",
17+
Short: "CAPH developer and operations CLI",
18+
DisableAutoGenTag: true,
19+
SilenceUsage: true,
20+
SilenceErrors: false,
2021
}
2122

2223
rootCmd.AddCommand(newCheckBMServersCommand())

internal/tools/readmegen/main.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"fmt"
6+
"os"
7+
"strings"
8+
9+
caphcmd "github.com/syself/caphcli/internal/cmd"
10+
)
11+
12+
const readmeTemplate = `# caphcli
13+
14+
` + "`caphcli`" + ` is a standalone CLI for CAPH bare-metal provisioning checks.
15+
16+
It currently exposes the ` + "`check-bm-servers`" + ` command that was extracted from CAPH PR ` + "`#1873`" + ` and moved into this repository.
17+
18+
## Build
19+
20+
` + "```bash" + `
21+
go build .
22+
` + "```" + `
23+
24+
## Required Environment Variables
25+
26+
- ` + "`HETZNER_ROBOT_USER`" + ` and ` + "`HETZNER_ROBOT_PASSWORD`" + ` for Hetzner Robot API access.
27+
- ` + "`SSH_KEY_NAME`" + ` for the Robot SSH key name to use or create.
28+
- One of ` + "`HETZNER_SSH_PUB_PATH`" + ` or ` + "`HETZNER_SSH_PUB`" + ` for the SSH public key.
29+
- One of ` + "`HETZNER_SSH_PRIV_PATH`" + ` or ` + "`HETZNER_SSH_PRIV`" + ` for the SSH private key.
30+
31+
## Keeping This README Up To Date
32+
33+
The official Cobra helper for generated command docs is ` + "`github.com/spf13/cobra/doc`" + `.
34+
This repo keeps the help blocks below in sync with the actual command tree via:
35+
36+
` + "```bash" + `
37+
go generate ./...
38+
` + "```" + `
39+
40+
That runs ` + "`go run ./internal/tools/readmegen`" + `, which rebuilds this README from the live Cobra commands.
41+
42+
## CLI Help
43+
44+
### ` + "`caphcli --help`" + `
45+
46+
` + "```text" + `
47+
{{ROOT_HELP}}
48+
` + "```" + `
49+
50+
### ` + "`caphcli check-bm-servers --help`" + `
51+
52+
` + "```text" + `
53+
{{CHECK_HELP}}
54+
` + "```" + `
55+
`
56+
57+
func main() {
58+
rootHelp, err := renderHelp()
59+
if err != nil {
60+
fail(err)
61+
}
62+
63+
checkHelp, err := renderHelp("check-bm-servers")
64+
if err != nil {
65+
fail(err)
66+
}
67+
68+
readme := strings.ReplaceAll(readmeTemplate, "{{ROOT_HELP}}", strings.TrimSpace(rootHelp))
69+
readme = strings.ReplaceAll(readme, "{{CHECK_HELP}}", strings.TrimSpace(checkHelp))
70+
71+
if err := os.WriteFile("README.md", []byte(readme), 0o644); err != nil {
72+
fail(fmt.Errorf("write README.md: %w", err))
73+
}
74+
}
75+
76+
func renderHelp(args ...string) (string, error) {
77+
rootCmd := caphcmd.NewRootCommand()
78+
buf := &bytes.Buffer{}
79+
rootCmd.SetOut(buf)
80+
rootCmd.SetErr(buf)
81+
rootCmd.SetArgs(append(args, "--help"))
82+
83+
if err := rootCmd.Execute(); err != nil {
84+
return "", fmt.Errorf("render help for %q: %w", strings.Join(args, " "), err)
85+
}
86+
87+
return buf.String(), nil
88+
}
89+
90+
func fail(err error) {
91+
_, _ = fmt.Fprintf(os.Stderr, "readmegen: %v\n", err)
92+
os.Exit(1)
93+
}

0 commit comments

Comments
 (0)