Skip to content

Commit 7a69328

Browse files
lex00claude
andcommitted
feat(cli): --version flag and --help anywhere in argv
--help/-h now prints usage from any position (so 'reconcile --help' works), and --version/-v prints the version inlined from package.json at build time. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RErsihpfppjyZ37vQuRwKb
1 parent aad8a64 commit 7a69328

3 files changed

Lines changed: 64 additions & 3 deletions

File tree

CLI.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ with live GitHub state.
1010
| `audit` | Run chant's posture-audit engine over every repo declared in the config. | Never. |
1111
| `report` | Run cycles in dry-run, optionally add audit and identity passes, print a compliance snapshot, optionally write a JSON artifact. | Never. |
1212

13-
Run `github-warden` with no arguments (or `--help`) for the built-in usage text.
13+
Run `github-warden` with no arguments (or `--help`, anywhere in the argument
14+
list) for the built-in usage text; `github-warden --version` prints the version
15+
(inlined from package.json at build time).
1416

1517
## Config file parsing
1618

action/index.mjs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232794,6 +232794,53 @@ var init_discover3 = __esm({
232794232794
import { readFileSync as readFileSync6, writeFileSync as writeFileSync3 } from "node:fs";
232795232795
import { pathToFileURL } from "node:url";
232796232796

232797+
// package.json
232798+
var package_default = {
232799+
name: "@intentius/github-warden",
232800+
version: "0.3.1",
232801+
type: "module",
232802+
description: "Keep your GitHub org and repos in declared state \u2014 reconcile, guardrails, drift correction",
232803+
license: "Apache-2.0",
232804+
repository: {
232805+
type: "git",
232806+
url: "git+https://github.com/INTENTIUS/github-warden.git"
232807+
},
232808+
homepage: "https://github.com/INTENTIUS/github-warden#readme",
232809+
bugs: {
232810+
url: "https://github.com/INTENTIUS/github-warden/issues"
232811+
},
232812+
publishConfig: {
232813+
access: "public"
232814+
},
232815+
bin: {
232816+
"github-warden": "bin/github-warden.js"
232817+
},
232818+
files: [
232819+
"bin",
232820+
"dist"
232821+
],
232822+
scripts: {
232823+
tsc: "tsc --noEmit",
232824+
test: "vitest run",
232825+
"test:e2e": "vitest run --config vitest.e2e.config.ts",
232826+
build: "esbuild src/cli.ts --bundle --platform=node --format=esm --outfile=dist/cli.js && chmod +x dist/cli.js",
232827+
"build:action": `esbuild src/action.ts --bundle --platform=node --format=esm --define:process.env.GITHUB_WARDEN_IS_ACTION='"1"' --outfile=action/index.mjs`,
232828+
prepublishOnly: "npm run build"
232829+
},
232830+
dependencies: {
232831+
"@intentius/chant": "^0.44.1",
232832+
"@intentius/chant-lexicon-github": "^0.44.1"
232833+
},
232834+
devDependencies: {
232835+
"@types/libsodium-wrappers": "^0.7.14",
232836+
"@types/node": "^22.0.0",
232837+
esbuild: "^0.28.0",
232838+
"libsodium-wrappers": "^0.8.4",
232839+
typescript: "^5.9.3",
232840+
vitest: "^4.1.9"
232841+
}
232842+
};
232843+
232797232844
// src/config/load.ts
232798232845
var GovernanceConfigError = class extends Error {
232799232846
field;
@@ -237573,10 +237620,15 @@ function buildClient(args) {
237573237620
}
237574237621
async function main(argv = process.argv.slice(2)) {
237575237622
const subcommand = argv[0];
237576-
if (!subcommand || subcommand === "--help" || subcommand === "-h") {
237623+
if (!subcommand || argv.includes("--help") || argv.includes("-h")) {
237577237624
printUsage();
237578237625
process.exit(0);
237579237626
}
237627+
if (subcommand === "--version" || subcommand === "-v") {
237628+
process.stdout.write(`${package_default.version}
237629+
`);
237630+
process.exit(0);
237631+
}
237580237632
if (subcommand === "audit") {
237581237633
await runAudit(argv.slice(1));
237582237634
return;

src/cli.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import { readFileSync, writeFileSync } from "node:fs";
3939
import { pathToFileURL } from "node:url";
40+
import pkg from "../package.json" with { type: "json" };
4041
import { loadGovernanceConfig } from "./config/load.js";
4142
import { createAppClient } from "./auth/app-client.js";
4243
import { runReconcile } from "./reconcile/runner.js";
@@ -517,11 +518,17 @@ async function main(argv: string[] = process.argv.slice(2)) {
517518

518519
// Top-level subcommand dispatch.
519520
const subcommand = argv[0];
520-
if (!subcommand || subcommand === "--help" || subcommand === "-h") {
521+
if (!subcommand || argv.includes("--help") || argv.includes("-h")) {
521522
printUsage();
522523
process.exit(0);
523524
}
524525

526+
if (subcommand === "--version" || subcommand === "-v") {
527+
// Inlined from package.json at build time — always matches the published version.
528+
process.stdout.write(`${pkg.version}\n`);
529+
process.exit(0);
530+
}
531+
525532
if (subcommand === "audit") {
526533
await runAudit(argv.slice(1));
527534
return;

0 commit comments

Comments
 (0)