From 739ce442889c94953fdb5b133418b51104068248 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 20 Mar 2026 19:49:36 +0000 Subject: [PATCH] add generate-readme task add generate_help.go update pre-commit hook --- .pre-commit-config.yaml | 4 ++-- README.md | 4 ++-- Taskfile.yml | 5 +++++ tools/generate_help.go | 31 ++++++++++++++++++++++++++++++ x32-help.md => tools/x32-help.md | 1 + xair-help.md => tools/xair-help.md | 1 + 6 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 tools/generate_help.go rename x32-help.md => tools/x32-help.md (99%) rename xair-help.md => tools/xair-help.md (99%) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 940b55e..dc5e7e8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/README.md b/README.md index 6c6e2ae..8488ff7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Taskfile.yml b/Taskfile.yml index 07fdece..0518c67 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -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 diff --git a/tools/generate_help.go b/tools/generate_help.go new file mode 100644 index 0000000..78c20bd --- /dev/null +++ b/tools/generate_help.go @@ -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) + } +} diff --git a/x32-help.md b/tools/x32-help.md similarity index 99% rename from x32-help.md rename to tools/x32-help.md index e065faa..c131322 100644 --- a/x32-help.md +++ b/tools/x32-help.md @@ -195,4 +195,5 @@ DCA dca name Get or set the name of the DCA group. Run "x32-cli --help" for more information on a command. + ``` diff --git a/xair-help.md b/tools/xair-help.md similarity index 99% rename from xair-help.md rename to tools/xair-help.md index 523dc65..5ebcd14 100644 --- a/xair-help.md +++ b/tools/xair-help.md @@ -127,4 +127,5 @@ DCA dca name Get or set the name of the DCA group. Run "xair-cli --help" for more information on a command. + ```