fix(gates): the shim reads a bare --gates and closed as on, and never swallows the next flag
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
8f9b0abfad
commit
e2fcf4060c
2 changed files with 68 additions and 5 deletions
|
|
@ -16,7 +16,9 @@
|
|||
// finish — pipeline reached its end
|
||||
//
|
||||
// CLI shim:
|
||||
// node lib/util/autonomy-gate.mjs --state X --event Y [--gates true|false]
|
||||
// node lib/util/autonomy-gate.mjs --state X --event Y [--gates [true|false|closed|open]]
|
||||
// (bare --gates = on; true|closed = on, false|open = off; any other value
|
||||
// is a usage error, exit 1; case-sensitive)
|
||||
// → JSON: { ok: true, next_state: "..." } (success)
|
||||
// → JSON: { ok: false, error: "..." } (invalid transition; exit 1)
|
||||
//
|
||||
|
|
@ -109,8 +111,22 @@ function parseArgs(argv) {
|
|||
if (a === '--state') out.state = argv[++i];
|
||||
else if (a === '--event') out.event = argv[++i];
|
||||
else if (a === '--gates') {
|
||||
const v = argv[++i];
|
||||
out.gates = v === 'true';
|
||||
// Bare `--gates` (last, or followed by another flag) means on and
|
||||
// consumes nothing. A value is case-sensitive: true|closed = on,
|
||||
// false|open = off; anything else is a usage error.
|
||||
const v = argv[i + 1];
|
||||
if (v === undefined || v.startsWith('--')) {
|
||||
out.gates = true;
|
||||
} else if (v === 'true' || v === 'closed') {
|
||||
out.gates = true;
|
||||
i++;
|
||||
} else if (v === 'false' || v === 'open') {
|
||||
out.gates = false;
|
||||
i++;
|
||||
} else {
|
||||
out.error = 'usage: --gates takes true, false, closed or open';
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
|
|
@ -118,10 +134,11 @@ function parseArgs(argv) {
|
|||
|
||||
if (isMain(import.meta.url)) {
|
||||
const args = parseArgs(process.argv.slice(2));
|
||||
if (!args.state || !args.event) {
|
||||
if (args.error || !args.state || !args.event) {
|
||||
process.stdout.write(JSON.stringify({
|
||||
ok: false,
|
||||
error: 'usage: autonomy-gate.mjs --state <state> --event <event> [--gates true|false]',
|
||||
error: args.error
|
||||
|| 'usage: autonomy-gate.mjs --state <state> --event <event> [--gates [true|false|closed|open]]',
|
||||
}) + '\n');
|
||||
process.exit(1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue