feat: add --version flag to cli - #543
Conversation
Greptile SummaryThe PR adds a root-level
Confidence Score: 4/5The PR appears safe to merge, with one non-blocking documentation correction needed for The version behavior and test align, but the new documentation inaccurately says all global flags must precede a subcommand even though Files Needing Attention: docs/cli/global.mdx Important Files Changed
Reviews (1): Last reviewed commit: "feat: add --version flag to cli (#542)" | Re-trigger Greptile |
|
|
||
| ## Notes | ||
|
|
||
| - Global flags must come before the subcommand name: `pgschema --version` (not `pgschema dump --version`). |
There was a problem hiding this comment.
Distinguish persistent flag placement
The blanket statement that global flags must precede the subcommand is inaccurate for --debug: it is registered through RootCmd.PersistentFlags() and is also accepted after a subcommand, such as pgschema plan --debug. Distinguishing this from the root-only --version flag would accurately document the supported CLI syntax.
| - Global flags must come before the subcommand name: `pgschema --version` (not `pgschema dump --version`). | |
| - The root-only `--version` flag must come before the subcommand name: `pgschema --version` (not `pgschema dump --version`). The persistent `--debug` flag can appear before or after a subcommand. |
Knowledge Base Used: CLI Entrypoints
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Pull request overview
Adds a root-level --version flag to the pgschema CLI (via Cobra) so scripts and agentic tools can reliably detect the installed semantic version, and documents the new global flag.
Changes:
- Set the root Cobra command’s
Versionand customize the version output template to print only the semantic version. - Add a CLI test asserting
pgschema --versionprintsversion.App()followed by\n. - Add documentation for root/global options and link it in the docs navigation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
cmd/root.go |
Enables Cobra’s --version flag on the root command and sets a minimal version output template. |
cmd/root_test.go |
Adds a test verifying --version output matches version.App() exactly. |
docs/cli/global.mdx |
Documents root/global CLI flags including --version. |
docs/docs.json |
Adds the new global options page to the CLI Reference navigation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| // Reset flags that earlier tests may have set on the shared global RootCmd. | ||
| // pflag does not reset flag values between Parse calls, and cobra checks | ||
| // the help flag before the version flag. | ||
| if err := RootCmd.Flags().Set("help", "false"); err != nil { | ||
| t.Fatalf("failed to reset help flag: %v", err) | ||
| } |
07a2e01 to
cf2be9a
Compare
cf2be9a to
8e77152
Compare
What
Closes #542 — adds a
--versionflag to the pgschema CLI.Output is a single, machine-parseable line containing only the semantic version, so agentic tools and scripts can detect behavioral changes between releases.
Changes
cmd/root.go: Set cobra'sVersionfield (adds the--versionflag to the root command) and a custom version template that prints just the version string.cmd/root_test.go: New test assertingpgschema --versionoutput equalsversion.App() + "\n". Includes a flag reset since tests share the globalRootCmd(pflag doesn't reset flag values betweenParsecalls, and cobra checks help before version).Notes
--versionis a root-command flag:pgschema --versionworks,pgschema dump --versionerrors (standard cobra behavior).internal/version/VERSION(1.12.3);pgschema --helpstill shows the fullerVersion: 1.12.3@<commit> <os/arch> <date>line.Tests
go test ./cmd/ -run TestRoot -v— all passgo vet ./cmd/— cleanpgschema --version→1.12.3;pgschema --debug --version→1.12.3;pgschema dump --version→unknown flag: --version