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. + ```