add generate-readme task

add generate_help.go

update pre-commit hook
This commit is contained in:
2026-03-20 19:49:36 +00:00
parent 1b9cc1f66a
commit 739ce44288
6 changed files with 42 additions and 4 deletions

View File

@@ -3,6 +3,6 @@ repos:
hooks:
- id: update-readme
name: update-readme
entry: python update_readme.py
language: python
entry: go generate ./tools
language: system
pass_filenames: false

View File

@@ -60,8 +60,8 @@ export X32_CLI_LOGLEVEL=warn
For each command/subcommand in the tree there exists a `--help` flag, use it to print usage information.
- [xair-cli](./xair-help.md)
- [x32-cli](./x32-help.md)
- [xair-cli](./tools/xair-help.md)
- [x32-cli](./tools/x32-help.md)
### Examples

View File

@@ -62,3 +62,8 @@ tasks:
desc: Clean the build artifacts
cmds:
- '{{.SHELL}} rm -r {{.BIN_DIR}}'
update-readme:
desc: Update the README.md file with the latest help output from the commands
cmds:
- go generate ./tools

31
tools/generate_help.go Normal file
View File

@@ -0,0 +1,31 @@
//go:generate go run generate_help.go
package main
import (
"os"
"os/exec"
)
func main() {
clis := []struct {
cmd string
out string
}{
{"../cmd/xair-cli/", "xair-help.md"},
{"../cmd/x32-cli/", "x32-help.md"},
}
for _, cli := range clis {
helpCmd := exec.Command("go", "run", cli.cmd, "--help")
out, err := helpCmd.Output()
if err != nil {
panic(err)
}
// Wrap output in markdown console code block
wrapped := append([]byte("```console\n"), out...)
wrapped = append(wrapped, []byte("\n```\n")...)
os.WriteFile(cli.out, wrapped, 0o644)
}
}

View File

@@ -195,4 +195,5 @@ DCA
dca <index> name Get or set the name of the DCA group.
Run "x32-cli <command> --help" for more information on a command.
```

View File

@@ -127,4 +127,5 @@ DCA
dca <index> name Get or set the name of the DCA group.
Run "xair-cli <command> --help" for more information on a command.
```