grada-run 0.40.15 → 0.40.17

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.
Files changed (43) hide show
  1. package/bin/cli.js +22 -18
  2. package/package.json +1 -1
  3. package/src/commands/add.js +70 -3
  4. package/src/commands/alerts.js +6 -3
  5. package/src/commands/apply.js +6 -3
  6. package/src/commands/db/backup.js +5 -2
  7. package/src/commands/db/connect.js +6 -3
  8. package/src/commands/db/enable-vector.js +5 -2
  9. package/src/commands/db/import.js +5 -2
  10. package/src/commands/db/migrate.js +38 -30
  11. package/src/commands/db/restore.js +5 -2
  12. package/src/commands/destroy.js +6 -3
  13. package/src/commands/doctor.js +5 -1
  14. package/src/commands/domain.js +5 -2
  15. package/src/commands/drift.js +6 -3
  16. package/src/commands/eject.js +5 -2
  17. package/src/commands/exec.js +6 -2
  18. package/src/commands/gc.js +6 -3
  19. package/src/commands/init.js +6 -3
  20. package/src/commands/logs.js +6 -2
  21. package/src/commands/mcp.js +5 -2
  22. package/src/commands/rollback.js +6 -3
  23. package/src/commands/sleep.js +5 -2
  24. package/src/commands/status.js +6 -2
  25. package/src/commands/wake.js +6 -3
  26. package/src/core/parser.js +16 -5
  27. package/src/utils/args.js +11 -5
  28. package/src/utils/aws.js +11 -4
  29. package/src/utils/command.js +20 -0
  30. package/src/utils/hcl.js +22 -0
  31. package/templates/github/deploy-lambda.yml +7 -0
  32. package/templates/github/deploy-static.yml +7 -0
  33. package/templates/github/deploy.yml +7 -0
  34. package/templates/github/drift.yml +4 -1
  35. package/templates/github/preview-lambda.yml +8 -1
  36. package/templates/github/preview.yml +12 -4
  37. package/templates/github/teardown.yml +16 -1
  38. package/templates/terraform/addons/redis.tf +2 -2
  39. package/templates/terraform/database-aurora-postgresql.tf +2 -12
  40. package/templates/terraform/database-mysql.tf +2 -12
  41. package/templates/terraform/database.tf +2 -12
  42. package/templates/terraform/main.tf +1 -1
  43. package/templates/terraform/network.tf +30 -6
@@ -6,6 +6,7 @@ import { S3Client, ListObjectsV2Command, GetObjectCommand } from '@aws-sdk/clien
6
6
  import { checkDependency } from '../utils/system.js';
7
7
  import { checkAwsCredentials, TROUBLESHOOTING_URL } from '../utils/aws.js';
8
8
  import { readLastRunMarker, isInterruptedMarker } from '../utils/terraform.js';
9
+ import { refuseUnknownFlags } from '../utils/command.js';
9
10
  import { readTerraformOidcTrust } from '../utils/resolvers.js';
10
11
  import { parseStateBucketBackend } from '../utils/terraform-metadata.js';
11
12
  import { normalizeOptions, parseFlags, normalizeArgv } from '../utils/args.js';
@@ -221,7 +222,8 @@ function checkInterruptedRun({ cwd }) {
221
222
  export function parseDoctorArgs(argv = []) {
222
223
  const args = normalizeArgv(argv);
223
224
  if (args[0] === 'doctor') args.shift();
224
- const { options } = parseFlags(args, { boolean: ['deep'] });
225
+ const { options, unknown } = parseFlags(args, { boolean: ['deep', 'headless'] });
226
+ if (unknown.length > 0) options.unknownFlags = unknown;
225
227
  return { deep: false, ...options };
226
228
  }
227
229
 
@@ -278,6 +280,8 @@ export async function runDoctor(input = {}) {
278
280
 
279
281
  async function runDoctorMain(input = {}) {
280
282
  const options = normalizeOptions(input);
283
+ const unknownRefusal = await refuseUnknownFlags(options, { command: 'doctor', event: 'doctor_run' });
284
+ if (unknownRefusal) return unknownRefusal;
281
285
  const cwd = options.cwd ? path.resolve(String(options.cwd)) : process.cwd();
282
286
  const deep = options.deep === true || options.deep === 'true';
283
287
  const ctx = { cwd, s3Client: options.s3Client ?? null, deep };
@@ -6,7 +6,7 @@ import { intro, outro, confirm, cancel, isCancel } from '@clack/prompts';
6
6
  import { trackSuccess, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
7
7
  import { resolveProjectName, resolveHeadless, resolveCwd } from '../utils/resolvers.js';
8
8
  import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
9
- import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseIfNonInteractive } from '../utils/command.js';
9
+ import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseIfNonInteractive, refuseUnknownFlags } from '../utils/command.js';
10
10
  import { getTerraformOutputs } from '../utils/terraform.js';
11
11
  import {
12
12
  findResourceBlock,
@@ -319,7 +319,7 @@ export function isCloudFrontWired(cloudfrontTfContent, domain) {
319
319
  export function parseDomainArgs(argv = []) {
320
320
  const args = normalizeArgv(argv);
321
321
  if (args[0] === 'domain') args.shift();
322
- const { options: parsed, rest } = parseFlags(args, {
322
+ const { options: parsed, rest, unknown } = parseFlags(args, {
323
323
  string: ['zone-id'],
324
324
  boolean: ['force', 'activate', 'yes', { name: 'headless', key: 'isHeadless' }],
325
325
  });
@@ -332,6 +332,7 @@ export function parseDomainArgs(argv = []) {
332
332
  force: parsed.force === true,
333
333
  yes: parsed.yes === true,
334
334
  isHeadless: parsed.isHeadless === true,
335
+ ...(unknown.length > 0 ? { unknownFlags: unknown } : {}),
335
336
  };
336
337
  }
337
338
 
@@ -377,6 +378,8 @@ export async function runDomain(input = {}) {
377
378
 
378
379
  async function runDomainMain(input = {}) {
379
380
  const options = normalizeOptions(input);
381
+ const unknownRefusal = await refuseUnknownFlags(options, { command: 'domain', event: 'domain_run' });
382
+ if (unknownRefusal) return unknownRefusal;
380
383
  const noExit = isProgrammaticCall(options);
381
384
  const subcommand = typeof options.subcommand === 'string' ? options.subcommand.trim().toLowerCase() : undefined;
382
385
 
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'url';
5
5
  import color from 'picocolors';
6
6
  import { intro, outro, spinner } from '@clack/prompts';
7
7
  import { trackSuccess, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
8
- import { failCommand, failAwsError, failProjectNotInitialized, isProgrammaticCall } from '../utils/command.js';
8
+ import { failCommand, failAwsError, failProjectNotInitialized, isProgrammaticCall, refuseUnknownFlags } from '../utils/command.js';
9
9
  import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
10
10
  import { resolveRegion, resolveProjectName, resolveCwd, readFileSafe } from '../utils/resolvers.js';
11
11
 
@@ -20,15 +20,16 @@ export const MAX_SUMMARY_LINES = 60;
20
20
  export function parseDriftArgs(argv = []) {
21
21
  const args = normalizeArgv(argv);
22
22
  if (args[0] === 'drift') args.shift();
23
- const { options, rest } = parseFlags(args, {
23
+ const { options, rest, unknown } = parseFlags(args, {
24
24
  string: ['region', 'project-name'],
25
- boolean: ['setup', 'force'],
25
+ boolean: ['setup', 'force', 'headless'],
26
26
  });
27
27
  const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
28
28
  // `drift init` is an alias for `drift --setup`.
29
29
  if (positionals.includes('init') || positionals.includes('setup')) options.setup = true;
30
30
  const others = positionals.filter((positional) => positional !== 'init' && positional !== 'setup');
31
31
  if (others.length > 0) options.unexpectedPositionals = others;
32
+ if (unknown.length > 0) options.unknownFlags = unknown;
32
33
  return options;
33
34
  }
34
35
 
@@ -84,6 +85,8 @@ export async function runDrift(input = {}) {
84
85
 
85
86
  async function runDriftMain(input = {}) {
86
87
  const options = normalizeOptions(input);
88
+ const unknownRefusal = await refuseUnknownFlags(options, { command: 'drift', event: 'drift_run' });
89
+ if (unknownRefusal) return unknownRefusal;
87
90
  const noExit = isProgrammaticCall(options);
88
91
  let cwd;
89
92
  let region;
@@ -3,7 +3,7 @@ import path from 'path';
3
3
  import { intro, outro, confirm, spinner, cancel } from '@clack/prompts';
4
4
  import color from 'picocolors';
5
5
  import { trackEvent, flushTelemetry, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
6
- import { failCommand, refuseIfNonInteractive, shouldAutoApprove } from '../utils/command.js';
6
+ import { failCommand, refuseIfNonInteractive, refuseUnknownFlags, shouldAutoApprove } from '../utils/command.js';
7
7
  import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
8
8
  import {
9
9
  stripTerraformMetadata,
@@ -21,7 +21,8 @@ import { runWake } from './wake.js';
21
21
  export function parseEjectArgs(argv = []) {
22
22
  const args = normalizeArgv(argv);
23
23
  if (args[0] === 'eject') args.shift();
24
- const { options } = parseFlags(args, { boolean: ['force'] });
24
+ const { options, unknown } = parseFlags(args, { boolean: ['force', 'headless', 'yes'] });
25
+ if (unknown.length > 0) options.unknownFlags = unknown;
25
26
  return { force: false, ...options };
26
27
  }
27
28
 
@@ -57,6 +58,8 @@ export async function ejectStack(input = {}) {
57
58
 
58
59
  async function ejectStackMain(input = {}) {
59
60
  const options = normalizeOptions(input);
61
+ const unknownRefusal = await refuseUnknownFlags(options, { command: 'eject', event: 'project_ejected' });
62
+ if (unknownRefusal) return unknownRefusal;
60
63
  intro(color.bgRed(color.white(' grada eject ⏏️ ')));
61
64
 
62
65
  console.log(color.yellow('This will permanently decouple your infrastructure from the grada CLI.'));
@@ -4,7 +4,7 @@ import color from 'picocolors';
4
4
  import { intro, outro, spinner } from '@clack/prompts';
5
5
  import { trackEvent, flushTelemetry, trackSuccess, trackFailure, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
6
6
  import { hasAwsCli, AWS_CLI_INSTALL_URL, isAuthError, handleAuthErrorBranch, resolveClient } from '../utils/aws.js';
7
- import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized, isProgrammaticCall } from '../utils/command.js';
7
+ import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized, isProgrammaticCall, refuseUnknownFlags } from '../utils/command.js';
8
8
  import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
9
9
  import { resolveRegion, resolveProjectName, resolveCluster, resolveService, resolveCwd, guardComputeTarget } from '../utils/resolvers.js';
10
10
  import {
@@ -34,12 +34,14 @@ export function resolveShellCommand(options = {}) {
34
34
  export function parseExecArgs(argv = []) {
35
35
  const args = normalizeArgv(argv);
36
36
  if (args[0] === 'exec') args.shift();
37
- const { options, rest } = parseFlags(args, {
37
+ const { options, rest, unknown } = parseFlags(args, {
38
38
  string: ['cluster', 'service', 'container', 'command', 'region'],
39
+ boolean: ['headless'],
39
40
  });
40
41
  const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
41
42
  if (positionals.length > 0 && !options.service) options.service = positionals[0];
42
43
  if (positionals.length > 1) options.unexpectedPositionals = positionals.slice(1);
44
+ if (unknown.length > 0) options.unknownFlags = unknown;
43
45
  return options;
44
46
  }
45
47
 
@@ -94,6 +96,8 @@ export async function runExec(input = {}) {
94
96
 
95
97
  async function runExecMain(input = {}) {
96
98
  const options = normalizeOptions(input);
99
+ const unknownRefusal = await refuseUnknownFlags(options, { command: 'exec', event: 'exec_run' });
100
+ if (unknownRefusal) return unknownRefusal;
97
101
  const noExit = isProgrammaticCall(options);
98
102
  let cwd;
99
103
  let region;
@@ -12,7 +12,7 @@ import { trackEvent, flushTelemetry, trackSuccess, trackFailure, setActiveComman
12
12
  import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
13
13
  import { resolveRegion, resolveProjectName, resolveCluster, resolveCwd, isComputeTarget, readResourceSuffix } from '../utils/resolvers.js';
14
14
  import { resolveClient } from '../utils/aws.js';
15
- import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseIfNonInteractive, shouldAutoApprove } from '../utils/command.js';
15
+ import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseIfNonInteractive, refuseUnknownFlags, shouldAutoApprove } from '../utils/command.js';
16
16
  import { parseStateBucketBackend } from '../utils/terraform-metadata.js';
17
17
 
18
18
  export const CONFIRM_MESSAGE = 'Are you sure you want to permanently delete these orphaned resources? (y/N)';
@@ -22,10 +22,11 @@ export function parseGcArgs(argv = []) {
22
22
  if (args[0] === 'gc') args.shift();
23
23
  // --yes auto-confirms the delete prompt (explicit opt-in; the default
24
24
  // path still prompts). --deep adds the report-only deep scan.
25
- const { options } = parseFlags(args, {
25
+ const { options, unknown } = parseFlags(args, {
26
26
  string: ['region', 'project-name'],
27
- boolean: ['deep', 'yes'],
27
+ boolean: ['deep', 'yes', 'headless'],
28
28
  });
29
+ if (unknown.length > 0) options.unknownFlags = unknown;
29
30
  return options;
30
31
  }
31
32
 
@@ -459,6 +460,8 @@ export async function runGc(input = {}) {
459
460
 
460
461
  async function runGcMain(input = {}) {
461
462
  const options = normalizeOptions(input);
463
+ const unknownRefusal = await refuseUnknownFlags(options, { command: 'gc', event: 'gc_run' });
464
+ if (unknownRefusal) return unknownRefusal;
462
465
  let cwd;
463
466
  let region;
464
467
  let projectName;
@@ -28,7 +28,7 @@ import { scaffoldDriftWorkflow } from './drift.js';
28
28
  import { trackEvent, flushTelemetry, getCliVersion, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
29
29
  import { failCommand } from '../utils/command.js';
30
30
  import { getFrameworkWarning } from '../utils/warnings.js';
31
- import { provisionStateBucket, formatStateBucketName } from '../utils/aws.js';
31
+ import { provisionStateBucket, formatStateBucketName, isAuthError, printAwsAuthGuidance } from '../utils/aws.js';
32
32
  import { generateTemplates } from '../utils/generator.js';
33
33
  import { planExistingFiles, executeBackup, preserveManagedFiles, restoreManagedFiles, refusalResultForPlan, writeInitManifest } from '../utils/backup.js';
34
34
  import { checkStateAdoption } from '../utils/state-adoption.js';
@@ -746,6 +746,9 @@ async function mainStackMain(input = {}) {
746
746
  projectName: dirConfig.actualProjectName,
747
747
  plan: existingFilesPlan.decision,
748
748
  });
749
+ // Auth failures print the shared credential-recovery guidance;
750
+ // init keeps its own telemetry + exit path through failCommand.
751
+ if (isAuthError(error)) printAwsAuthGuidance(initOptions);
749
752
  return failCommand({
750
753
  message: `AWS Error: ${error.message}`,
751
754
  useErrorStream: true,
@@ -809,7 +812,7 @@ async function mainStackMain(input = {}) {
809
812
  if (migrationGateEnabled && migrationCmd) {
810
813
  const deployYmlPath = path.join(dirConfig.targetDir, '.github', 'workflows', 'deploy.yml');
811
814
  const workflowContent = readFileSafe(deployYmlPath);
812
- const gated = workflowContent ? injectMigrationGate(workflowContent, { cmd: migrationCmd }) : null;
815
+ const gated = workflowContent ? injectMigrationGate(workflowContent, { cmd: migrationCmd, cliVersion: CLI_VERSION }) : null;
813
816
  if (gated) {
814
817
  atomicWriteFileSync(deployYmlPath, gated);
815
818
  console.log(color.green('✅ Wired the pre-deploy database migration gate into .github/workflows/deploy.yml'));
@@ -820,7 +823,7 @@ async function mainStackMain(input = {}) {
820
823
  const previewYmlPath = path.join(dirConfig.targetDir, '.github', 'workflows', 'preview.yml');
821
824
  const previewContent = readFileSafe(previewYmlPath);
822
825
  if (previewContent) {
823
- const previewGated = injectPreviewMigrationGate(previewContent, { cmd: migrationCmd });
826
+ const previewGated = injectPreviewMigrationGate(previewContent, { cmd: migrationCmd, cliVersion: CLI_VERSION });
824
827
  if (previewGated) {
825
828
  atomicWriteFileSync(previewYmlPath, previewGated);
826
829
  console.log(color.green('✅ Wired the preview database migration gate into .github/workflows/preview.yml'));
@@ -4,7 +4,7 @@ import { trackEvent, flushTelemetry, trackSuccess, trackFailure, setActiveComman
4
4
  import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
5
5
  import { isAuthError, handleAuthErrorBranch, resolveClient } from '../utils/aws.js';
6
6
  import { resolveRegion, resolveProjectName, resolveLogGroup, resolveCwd, isComputeTarget } from '../utils/resolvers.js';
7
- import { failCommand, failProjectNotInitialized, isProgrammaticCall } from '../utils/command.js';
7
+ import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseUnknownFlags } from '../utils/command.js';
8
8
  import { sleep } from '../utils/system.js';
9
9
 
10
10
  export const DEFAULT_TAIL_LINES = 50;
@@ -85,14 +85,16 @@ export const formatLogEvent = formatLogLine;
85
85
  export function parseLogsArgs(argv = []) {
86
86
  const args = normalizeArgv(argv);
87
87
  if (args[0] === 'logs') args.shift();
88
- const { options, rest } = parseFlags(args, {
88
+ const { options, rest, unknown } = parseFlags(args, {
89
89
  string: ['since', 'region'],
90
90
  number: ['tail'],
91
+ boolean: ['headless'],
91
92
  bareBoolean: ['follow', 'error'],
92
93
  alias: { f: 'follow' },
93
94
  });
94
95
  const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
95
96
  if (positionals.length > 0) options.service = positionals[0];
97
+ if (unknown.length > 0) options.unknownFlags = unknown;
96
98
  return options;
97
99
  }
98
100
 
@@ -134,6 +136,8 @@ export async function runLogs(input = {}) {
134
136
 
135
137
  async function runLogsMain(input = {}) {
136
138
  const options = normalizeOptions(input);
139
+ const unknownRefusal = await refuseUnknownFlags(options, { command: 'logs', event: 'logs_streamed' });
140
+ if (unknownRefusal) return unknownRefusal;
137
141
  let cwd;
138
142
  let region;
139
143
  let service;
@@ -10,7 +10,7 @@ import { z } from 'zod';
10
10
  import { getCliVersion, trackSuccess, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
11
11
  import { safeHomedir } from '../core/homedir.js';
12
12
  import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
13
- import { failCommand } from '../utils/command.js';
13
+ import { failCommand, refuseUnknownFlags } from '../utils/command.js';
14
14
  import { runStatus } from './status.js';
15
15
  import { runLogs } from './logs.js';
16
16
  import { auditSecrets } from './secrets.js';
@@ -386,7 +386,8 @@ export function createMcpServer() {
386
386
  export function parseMcpArgs(argv = []) {
387
387
  const args = normalizeArgv(argv);
388
388
  if (args[0] === 'mcp') args.shift();
389
- const { options } = parseFlags(args, { string: ['install', 'transport', 'host'], number: ['port'] });
389
+ const { options, unknown } = parseFlags(args, { string: ['install', 'transport', 'host'], number: ['port'], boolean: ['headless'] });
390
+ if (unknown.length > 0) options.unknownFlags = unknown;
390
391
  if (options.install === undefined) {
391
392
  // parseFlags drops a trailing valueless `--install`; detect the
392
393
  // flag's presence so runMcp reports usage instead of starting
@@ -651,6 +652,8 @@ export function installMcpConfig(editor, { homeDir = safeHomedir(), platform = o
651
652
  // until the client disconnects or receives SIGINT/SIGTERM.
652
653
  export async function runMcp(input = {}) {
653
654
  const options = normalizeOptions(input);
655
+ const unknownRefusal = await refuseUnknownFlags(options, { command: 'mcp', event: 'mcp_install' });
656
+ if (unknownRefusal) return unknownRefusal;
654
657
  if (options.install !== undefined) {
655
658
  const installed = installMcpConfig(options.install, { homeDir: options.homeDir, platform: options.platform });
656
659
  if (!installed.ok) {
@@ -8,7 +8,7 @@ import {
8
8
  import color from 'picocolors';
9
9
  import { intro, outro, spinner, select, isCancel } from '@clack/prompts';
10
10
  import { trackEvent, flushTelemetry, trackSuccess, trackFailure, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
11
- import { failCommand, failAwsError, failProjectNotInitialized, refuseIfNonInteractive } from '../utils/command.js';
11
+ import { failCommand, failAwsError, failProjectNotInitialized, refuseIfNonInteractive, refuseUnknownFlags } from '../utils/command.js';
12
12
  import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
13
13
  import { isAuthError, handleAwsAuthError, resolveClient } from '../utils/aws.js';
14
14
  import { resolveRegion, resolveProjectName, resolveCluster, resolveService, readFileSafe, resolveWorkspaceSuffix, resolveCwd, guardComputeTarget, readResourceSuffix } from '../utils/resolvers.js';
@@ -28,11 +28,12 @@ export const DEFAULT_TIMEOUT_MS = 300000;
28
28
  export function parseRollbackArgs(argv = []) {
29
29
  const args = normalizeArgv(argv);
30
30
  if (args[0] === 'rollback') args.shift();
31
- const { options: parsed, rest } = parseFlags(args, {
31
+ const { options: parsed, rest, unknown } = parseFlags(args, {
32
32
  string: ['cluster', 'service', 'region', 'workspace'],
33
- boolean: ['skip-wait'],
33
+ boolean: ['skip-wait', 'headless'],
34
34
  });
35
35
  const options = { skipWait: false, ...parsed };
36
+ if (unknown.length > 0) options.unknownFlags = unknown;
36
37
  for (const arg of rest) {
37
38
  if (typeof arg === 'string' && !arg.startsWith('-') && options.revision === undefined) {
38
39
  options.revision = arg;
@@ -73,6 +74,8 @@ export async function runRollback(input = {}) {
73
74
 
74
75
  async function runRollbackMain(input = {}) {
75
76
  const options = normalizeOptions(input);
77
+ const unknownRefusal = await refuseUnknownFlags(options, { command: 'rollback', event: 'rollback_run' });
78
+ if (unknownRefusal) return unknownRefusal;
76
79
  let cwd;
77
80
  let region;
78
81
  let projectName;
@@ -5,7 +5,7 @@ import { RDSClient, StopDBInstanceCommand, StopDBClusterCommand } from '@aws-sdk
5
5
  import color from 'picocolors';
6
6
  import { intro, outro, spinner, confirm, cancel } from '@clack/prompts';
7
7
  import { trackEvent, trackSuccess, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
8
- import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized, refuseIfNonInteractive, shouldAutoApprove } from '../utils/command.js';
8
+ import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized, refuseIfNonInteractive, refuseUnknownFlags, shouldAutoApprove } from '../utils/command.js';
9
9
  import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
10
10
  import { isAuthError, handleAuthErrorBranch, resolveClient } from '../utils/aws.js';
11
11
  import { resolveRegion, resolveProjectName, resolveCwd, readTerraformComputeTarget } from '../utils/resolvers.js';
@@ -41,13 +41,14 @@ export const SLEEP_CONFIRM_MESSAGE = "Put environment to sleep? This will take t
41
41
  export function parseSleepArgs(argv = []) {
42
42
  const args = normalizeArgv(argv);
43
43
  if (args[0] === 'sleep') args.shift();
44
- const { options, rest } = parseFlags(args, {
44
+ const { options, rest, unknown } = parseFlags(args, {
45
45
  string: ['project-name', 'cluster', 'service', 'db-identifier', 'region', 'workspace'],
46
46
  boolean: ['skip-db', 'wait', 'no-wait', 'yes', 'force', 'headless', 'strict'],
47
47
  });
48
48
  const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
49
49
  if (positionals.length > 0) options.env = positionals[0];
50
50
  if (positionals.length > 1) options.unexpectedPositionals = positionals.slice(1);
51
+ if (unknown.length > 0) options.unknownFlags = unknown;
51
52
  return options;
52
53
  }
53
54
 
@@ -68,6 +69,8 @@ export async function runSleep(input = {}) {
68
69
 
69
70
  async function runSleepMain(input = {}) {
70
71
  const options = normalizeOptions(input);
72
+ const unknownRefusal = await refuseUnknownFlags(options, { command: 'sleep', event: 'sleep_run' });
73
+ if (unknownRefusal) return unknownRefusal;
71
74
  let cwd;
72
75
  let region;
73
76
  let projectName;
@@ -5,7 +5,7 @@ import { CloudFrontClient, ListDistributionsCommand } from '@aws-sdk/client-clou
5
5
  import color from 'picocolors';
6
6
  import { intro, outro, spinner } from '@clack/prompts';
7
7
  import { trackEvent, flushTelemetry, trackSuccess, trackFailure, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
8
- import { failCommand, failProjectNotInitialized, isProgrammaticCall } from '../utils/command.js';
8
+ import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseUnknownFlags } from '../utils/command.js';
9
9
  import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
10
10
  import { handleAuthErrorBranch, resolveClient } from '../utils/aws.js';
11
11
  import { resolveRegion, resolveProjectName, resolveCwd, readTerraformComputeTarget, readResourceSuffix } from '../utils/resolvers.js';
@@ -37,10 +37,12 @@ export async function runStatusWatch(input = {}) {
37
37
  export function parseStatusArgs(argv = []) {
38
38
  const args = normalizeArgv(argv);
39
39
  if (args[0] === 'status') args.shift();
40
- const { options } = parseFlags(args, {
40
+ const { options, unknown } = parseFlags(args, {
41
41
  string: ['region'],
42
+ boolean: ['headless'],
42
43
  bareBoolean: ['json', 'watch'],
43
44
  });
45
+ if (unknown.length > 0) options.unknownFlags = unknown;
44
46
  return options;
45
47
  }
46
48
 
@@ -424,6 +426,8 @@ export async function runStatus(input = {}) {
424
426
 
425
427
  async function runStatusMain(input = {}) {
426
428
  const options = normalizeOptions(input);
429
+ const unknownRefusal = await refuseUnknownFlags(options, { command: 'status', event: 'status_run' });
430
+ if (unknownRefusal) return unknownRefusal;
427
431
  const noExit = isProgrammaticCall(options);
428
432
  const asJson = Boolean(options.json);
429
433
  let cwd;
@@ -5,7 +5,7 @@ import { RDSClient, DescribeDBInstancesCommand, DescribeDBClustersCommand, Start
5
5
  import color from 'picocolors';
6
6
  import { intro, outro, spinner } from '@clack/prompts';
7
7
  import { trackSuccess, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
8
- import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized } from '../utils/command.js';
8
+ import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized, refuseUnknownFlags } from '../utils/command.js';
9
9
  import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
10
10
  import { isAuthError, handleAuthErrorBranch, resolveClient } from '../utils/aws.js';
11
11
  import { resolveRegion, resolveProjectName, resolveCwd, readTerraformComputeTarget } from '../utils/resolvers.js';
@@ -36,13 +36,14 @@ export const DEFAULT_WAKE_POLL_INTERVAL_MS = 5000;
36
36
  export function parseWakeArgs(argv = []) {
37
37
  const args = normalizeArgv(argv);
38
38
  if (args[0] === 'wake') args.shift();
39
- const { options, rest } = parseFlags(args, {
39
+ const { options, rest, unknown } = parseFlags(args, {
40
40
  string: ['project-name', 'cluster', 'service', 'db-identifier', 'region', 'workspace'],
41
- boolean: ['skip-db', 'wait', 'no-wait', 'strict'],
41
+ boolean: ['skip-db', 'wait', 'no-wait', 'strict', 'headless'],
42
42
  });
43
43
  const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
44
44
  if (positionals.length > 0) options.env = positionals[0];
45
45
  if (positionals.length > 1) options.unexpectedPositionals = positionals.slice(1);
46
+ if (unknown.length > 0) options.unknownFlags = unknown;
46
47
  return options;
47
48
  }
48
49
 
@@ -59,6 +60,8 @@ export async function runWake(input = {}) {
59
60
 
60
61
  async function runWakeMain(input = {}) {
61
62
  const options = normalizeOptions(input);
63
+ const unknownRefusal = await refuseUnknownFlags(options, { command: 'wake', event: 'wake_run' });
64
+ if (unknownRefusal) return unknownRefusal;
62
65
  let cwd;
63
66
  let region;
64
67
  let projectName;
@@ -69,10 +69,11 @@ export function parseCliArgs(processArgs) {
69
69
  return false;
70
70
  };
71
71
 
72
- // 4. Parse execution flags
73
- const isHeadless = args.includes('--headless');
74
- const isDryRun = args.includes('--dry-run');
75
- const isPreconfigured = args.includes('--preconfigured');
72
+ // 4. Parse execution flags (getBoolFlag like their neighbors: bare and
73
+ // =true both set, =false and absent both clear)
74
+ const isHeadless = getBoolFlag('headless') === true;
75
+ const isDryRun = getBoolFlag('dry-run') === true;
76
+ const isPreconfigured = getBoolFlag('preconfigured') === true;
76
77
 
77
78
  // Headless values are always parsed (so consumption marking is
78
79
  // mode-independent) but only exposed in headless mode.
@@ -132,7 +133,7 @@ export function parseCliArgs(processArgs) {
132
133
  projectName: getValueFlag('project-name'),
133
134
  githubRepo: getValueFlag('github-repo'),
134
135
  setupCiMigrate: getBoolOrValueFlag('setup-ci-migrate'),
135
- setupCiDrift: args.includes('--setup-ci-drift'),
136
+ setupCiDrift: getBoolFlag('setup-ci-drift') === true,
136
137
  };
137
138
 
138
139
  // 5. Isolate positional commands (non-string elements are positionals;
@@ -153,4 +154,14 @@ export function parseCliArgs(processArgs) {
153
154
  headlessOptions,
154
155
  initOptions
155
156
  };
157
+ }
158
+
159
+ // Args for per-command parsers: --no-telemetry is honored globally via
160
+ // DO_NOT_TRACK (see parseCliArgs), so it must not reach parseFlags —
161
+ // otherwise the unknown-flag gate would reject a documented global
162
+ // option on every command. Every other token passes through untouched.
163
+ export function stripGlobalOnlyFlags(processArgs) {
164
+ return normalizeArgv(processArgs).filter(
165
+ (arg) => arg !== '--no-telemetry' && !(typeof arg === 'string' && arg.startsWith('--no-telemetry='))
166
+ );
156
167
  }
package/src/utils/args.js CHANGED
@@ -42,11 +42,14 @@ export function normalizeArgv(argv) {
42
42
  // - `alias`: single-dash shorthands (`{ f: 'follow' }` makes `-f` act as
43
43
  // the bare long flag).
44
44
  //
45
- // Unknown `--flags` are dropped and everything else is returned in `rest`
46
- // so each command can apply its own positional rules.
45
+ // Space-form values never consume a `--like` token (a following flag stays
46
+ // a flag). Unknown `--flags` are collected in `unknown` (never silently
47
+ // dropped) so commands can reject them loud; everything else is returned
48
+ // in `rest` so each command can apply its own positional rules.
47
49
  export function parseFlags(args, { string = [], number = [], boolean = [], bareBoolean = [], alias = {} } = {}) {
48
50
  const options = {};
49
51
  const rest = [];
52
+ const unknown = [];
50
53
  const strings = normalizeEntries(string);
51
54
  const numbers = normalizeEntries(number);
52
55
  const booleans = normalizeEntries(boolean);
@@ -70,12 +73,12 @@ export function parseFlags(args, { string = [], number = [], boolean = [], bareB
70
73
  const value = eq === -1 ? undefined : arg.slice(eq + 1);
71
74
  if (strings.has(name)) {
72
75
  if (value !== undefined) options[strings.get(name)] = value;
73
- else if (i + 1 < list.length) options[strings.get(name)] = list[++i];
76
+ else if (i + 1 < list.length && !String(list[i + 1]).startsWith('--')) options[strings.get(name)] = list[++i];
74
77
  continue;
75
78
  }
76
79
  if (numbers.has(name)) {
77
80
  if (value !== undefined) options[numbers.get(name)] = Number(value);
78
- else if (i + 1 < list.length) options[numbers.get(name)] = Number(list[++i]);
81
+ else if (i + 1 < list.length && !String(list[i + 1]).startsWith('--')) options[numbers.get(name)] = Number(list[++i]);
79
82
  continue;
80
83
  }
81
84
  if (booleans.has(name)) {
@@ -86,6 +89,9 @@ export function parseFlags(args, { string = [], number = [], boolean = [], bareB
86
89
  if (value === undefined) options[bares.get(name)] = true;
87
90
  continue;
88
91
  }
92
+ // Unknown --flags are collected, never silently dropped: commands
93
+ // reject them loud via refuseUnknownFlags.
94
+ unknown.push(arg);
89
95
  }
90
- return { options, rest };
96
+ return { options, rest, unknown };
91
97
  }
package/src/utils/aws.js CHANGED
@@ -70,10 +70,10 @@ export function resolveClient(injected, ClientClass, clientOptions = {}) {
70
70
  return new ClientClass(clientOptions);
71
71
  }
72
72
 
73
- export function handleAwsAuthError(error, clackSpinner = null, options = {}) {
74
- if (clackSpinner) {
75
- clackSpinner.stop(color.red('❌ AWS session expired or invalid credentials.'));
76
- }
73
+ // Print-only half of the auth-failure branch: the credential-recovery
74
+ // guidance without the exit, for callers (init) that own their own
75
+ // telemetry and exit path through failCommand.
76
+ export function printAwsAuthGuidance(options = {}) {
77
77
  if (!hasAwsCli(options)) {
78
78
  console.log(color.red('\n✖ AWS CLI not found.'));
79
79
  console.log(` Install the AWS CLI: ${color.blue(color.underline(AWS_CLI_INSTALL_URL))}`);
@@ -83,6 +83,13 @@ export function handleAwsAuthError(error, clackSpinner = null, options = {}) {
83
83
  console.log(`Run ${color.cyan('aws sso login')} or ${color.cyan('aws configure')} to refresh your credentials.`);
84
84
  }
85
85
  console.log(color.blue(`\n📘 Troubleshooting Guide: ${color.underline(TROUBLESHOOTING_URL)}\n`));
86
+ }
87
+
88
+ export function handleAwsAuthError(error, clackSpinner = null, options = {}) {
89
+ if (clackSpinner) {
90
+ clackSpinner.stop(color.red('❌ AWS session expired or invalid credentials.'));
91
+ }
92
+ printAwsAuthGuidance(options);
86
93
  process.exit(1);
87
94
  return;
88
95
  }
@@ -52,6 +52,26 @@ export async function refuseIfNonInteractive(options = {}, spec = {}) {
52
52
  });
53
53
  }
54
54
 
55
+ // Unknown flags fail loud at the gate: a typo like --skp-db must never
56
+ // silently widen a command. Parse functions surface parseFlags' unknown
57
+ // list as options.unknownFlags; run functions call this first.
58
+ export async function refuseUnknownFlags(options = {}, spec = {}) {
59
+ const opts = normalizeOptions(options);
60
+ const unknown = Array.isArray(opts.unknownFlags) ? opts.unknownFlags.filter((f) => typeof f === 'string' && f !== '') : [];
61
+ if (unknown.length === 0) return null;
62
+ const { command, event, telemetry } = spec;
63
+ return failCommand({
64
+ noExit: isProgrammaticCall(opts),
65
+ message: `\n✖ Unknown flag "${unknown[0]}" for ${command}.\n`,
66
+ hint: ' Check the spelling or run "grada --help" for usage.\n',
67
+ event,
68
+ telemetry,
69
+ errorCode: 'UNKNOWN_FLAG',
70
+ reason: 'unknown-flag',
71
+ exitCode: 1,
72
+ });
73
+ }
74
+
55
75
  function paint(tone, fallback) {
56
76
  return typeof color[tone] === 'function' ? color[tone] : fallback;
57
77
  }
package/src/utils/hcl.js CHANGED
@@ -108,6 +108,28 @@ export function findResourceBlock(content, resourceType, resourceName) {
108
108
  return { headerIdx, openIdx, closeIdx: bounds.closeIdx };
109
109
  }
110
110
 
111
+ // Removes the `resource "type" "name" { ... }` block plus comment lines
112
+ // directly attached above it (walking up over blanks, stopping at the
113
+ // first line of code). Returns the content unchanged when absent. Callers
114
+ // should normalize blank lines afterwards.
115
+ export function removeResourceBlock(content, resourceType, resourceName) {
116
+ const text = String(content ?? '');
117
+ const found = findResourceBlock(text, resourceType, resourceName);
118
+ if (!found) return text;
119
+ const lines = text.slice(0, found.headerIdx).split('\n');
120
+ let firstKept = lines.length;
121
+ for (let i = lines.length - 1; i >= 0; i--) {
122
+ const line = lines[i];
123
+ if (line.trim() === '' || /^\s*#/.test(line)) {
124
+ firstKept = i;
125
+ continue;
126
+ }
127
+ break;
128
+ }
129
+ const start = firstKept === 0 ? 0 : lines.slice(0, firstKept).join('\n').length + 1;
130
+ return text.slice(0, start) + text.slice(found.closeIdx + 1);
131
+ }
132
+
111
133
  // Locates a nested `blockName { ... }` (with optional quoted labels)
112
134
  // at the top level of a block slice. Returns
113
135
  // `{ startIdx, openIdx, closeIdx }` (startIdx is the keyword) or null.
@@ -5,6 +5,13 @@ on:
5
5
  branches:
6
6
  - {{DEPLOY_BRANCH}}
7
7
 
8
+ # Overlapping deploys race: each run publishes its own image and calls
9
+ # update-function-code, so a stale run finishing last would silently
10
+ # regress production. Superseded runs cancel instead — newest always wins.
11
+ concurrency:
12
+ group: deploy-${{ github.ref }}
13
+ cancel-in-progress: true
14
+
8
15
  env:
9
16
  AWS_REGION: {{REGION}}
10
17
  ECR_REPOSITORY: {{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-repo
@@ -5,6 +5,13 @@ on:
5
5
  branches:
6
6
  - {{DEPLOY_BRANCH}}
7
7
 
8
+ # Overlapping deploys race: each run syncs its own build with --delete, so
9
+ # interleaved runs would publish a mixed old/new file set. Superseded runs
10
+ # cancel instead — newest always wins.
11
+ concurrency:
12
+ group: deploy-${{ github.ref }}
13
+ cancel-in-progress: true
14
+
8
15
  env:
9
16
  AWS_REGION: {{REGION}}
10
17
  S3_BUCKET: {{PROJECT_NAME}}{{RESOURCE_SUFFIX}}-site-{{AWS_ACCOUNT_ID}}