cdk-real-drift 0.2.54 → 0.2.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -243,6 +243,44 @@ const BOOLEAN_FLAGS = new Set([
243
243
  "--strict",
244
244
  "--all"
245
245
  ]);
246
+ const CANONICAL_FLAG = {
247
+ "-y": "--yes",
248
+ "-v": "--verbose",
249
+ "-a": "--app",
250
+ "-c": "--context"
251
+ };
252
+ const canonicalFlag = (flag) => CANONICAL_FLAG[flag] ?? flag;
253
+ const GLOBAL_FLAGS = [
254
+ "--region",
255
+ "--profile",
256
+ "--app",
257
+ "--context",
258
+ "--all",
259
+ "--json",
260
+ "--yes"
261
+ ];
262
+ const ALLOWED_FLAGS_BY_VERB = {
263
+ check: new Set([
264
+ ...GLOBAL_FLAGS,
265
+ "--fail",
266
+ "--strict",
267
+ "--show-all",
268
+ "--pre-deploy",
269
+ "--undeclared-only",
270
+ "--declared-only",
271
+ "--verbose",
272
+ "--remove-unrecorded"
273
+ ]),
274
+ record: new Set([...GLOBAL_FLAGS, "--verbose"]),
275
+ ignore: new Set(GLOBAL_FLAGS),
276
+ revert: new Set([
277
+ ...GLOBAL_FLAGS,
278
+ "--verbose",
279
+ "--remove-unrecorded",
280
+ "--dry-run",
281
+ "--wait"
282
+ ])
283
+ };
246
284
  /**
247
285
  * Whether prompts may be shown: only in a real TTY. Non-interactive now simply means
248
286
  * non-TTY (real CI/cron/pipes). The single source of truth — command code threads this
@@ -252,7 +290,7 @@ const BOOLEAN_FLAGS = new Set([
252
290
  function isInteractive() {
253
291
  return Boolean(process.stdin.isTTY);
254
292
  }
255
- function parseCommonArgs(args) {
293
+ function parseCommonArgs(args, verb) {
256
294
  const values = {};
257
295
  const found = /* @__PURE__ */ new Set();
258
296
  const stackNames = [];
@@ -297,6 +335,11 @@ function parseCommonArgs(args) {
297
335
  }
298
336
  throw new Error(`unknown option "${a}" — see cdkrd --help`);
299
337
  }
338
+ if (verb !== void 0) {
339
+ const allowed = ALLOWED_FLAGS_BY_VERB[verb];
340
+ for (const flag of found) if (!allowed.has(canonicalFlag(flag))) throw new Error(`option "${flag}" is not valid for the \`${verb}\` command — see cdkrd --help`);
341
+ if (waitMs !== void 0 && !allowed.has("--wait")) throw new Error(`option "--wait" is not valid for the \`${verb}\` command — see cdkrd --help`);
342
+ }
300
343
  const has = (flag) => found.has(flag);
301
344
  const scopes = [
302
345
  "--pre-deploy",
@@ -12426,7 +12469,7 @@ function availableActions(findings, baseline, schemas, removeUnrecorded) {
12426
12469
  //#endregion
12427
12470
  //#region src/commands/record.ts
12428
12471
  async function runRecord(args) {
12429
- const a = parseCommonArgs(args);
12472
+ const a = parseCommonArgs(args, "record");
12430
12473
  if (a.profile) process.env.AWS_PROFILE = a.profile;
12431
12474
  let config;
12432
12475
  try {
@@ -12447,6 +12490,7 @@ async function runRecord(args) {
12447
12490
  return 0;
12448
12491
  }
12449
12492
  let worst = 0;
12493
+ let wroteAny = false;
12450
12494
  const showProgress = !a.json && isInteractive();
12451
12495
  for (const [idx, { stackName, region, template }] of stacks.entries()) {
12452
12496
  if (!region) {
@@ -12456,7 +12500,7 @@ async function runRecord(args) {
12456
12500
  }
12457
12501
  try {
12458
12502
  const { desired, findings } = await gatherWithProgress(showProgress, progressLabel(idx, stacks.length, stackName, region), () => gatherFindings(stackName, region, void 0, template));
12459
- if ((await recordStack({
12503
+ const result = await recordStack({
12460
12504
  stackName,
12461
12505
  region,
12462
12506
  desired,
@@ -12468,7 +12512,9 @@ async function runRecord(args) {
12468
12512
  yes: a.yes,
12469
12513
  interactive: isInteractive(),
12470
12514
  expandNested: a.verbose
12471
- })).refused) worst = Math.max(worst, 2);
12515
+ });
12516
+ if (result.refused) worst = Math.max(worst, 2);
12517
+ if (result.wrote) wroteAny = true;
12472
12518
  } catch (e) {
12473
12519
  if (isStackNotDeployed(e)) {
12474
12520
  console.error(`note: ${stackName}: not deployed yet — nothing to record`);
@@ -12482,14 +12528,14 @@ async function runRecord(args) {
12482
12528
  worst = Math.max(worst, 2);
12483
12529
  }
12484
12530
  }
12485
- if (worst === 0) console.log("commit the baseline file(s) so drift is detected against them going forward.");
12531
+ if (worst === 0 && wroteAny) console.log("commit the baseline file(s) so drift is detected against them going forward.");
12486
12532
  return worst;
12487
12533
  }
12488
12534
 
12489
12535
  //#endregion
12490
12536
  //#region src/commands/ignore.ts
12491
12537
  async function runIgnore(args) {
12492
- const a = parseCommonArgs(args);
12538
+ const a = parseCommonArgs(args, "ignore");
12493
12539
  if (a.profile) process.env.AWS_PROFILE = a.profile;
12494
12540
  let config;
12495
12541
  try {
@@ -13395,7 +13441,7 @@ function finalCheckExit(code, fail) {
13395
13441
  return fail || code !== 1 ? code : 0;
13396
13442
  }
13397
13443
  async function runCheck(args) {
13398
- const a = parseCommonArgs(args);
13444
+ const a = parseCommonArgs(args, "check");
13399
13445
  if (a.profile) process.env.AWS_PROFILE = a.profile;
13400
13446
  let config;
13401
13447
  try {
@@ -13578,7 +13624,7 @@ async function runCheck(args) {
13578
13624
  //#endregion
13579
13625
  //#region src/commands/revert.ts
13580
13626
  async function runRevert(args) {
13581
- const a = parseCommonArgs(args);
13627
+ const a = parseCommonArgs(args, "revert");
13582
13628
  if (a.profile) process.env.AWS_PROFILE = a.profile;
13583
13629
  const dryRun = args.includes("--dry-run");
13584
13630
  let config;