@grada-run/grada 0.40.16 → 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.
- package/bin/cli.js +22 -18
- package/package.json +1 -1
- package/src/commands/add.js +24 -8
- package/src/commands/alerts.js +6 -3
- package/src/commands/apply.js +6 -3
- package/src/commands/db/backup.js +5 -2
- package/src/commands/db/connect.js +6 -3
- package/src/commands/db/enable-vector.js +5 -2
- package/src/commands/db/import.js +5 -2
- package/src/commands/db/migrate.js +5 -2
- package/src/commands/db/restore.js +5 -2
- package/src/commands/destroy.js +6 -3
- package/src/commands/doctor.js +5 -1
- package/src/commands/domain.js +5 -2
- package/src/commands/drift.js +6 -3
- package/src/commands/eject.js +5 -2
- package/src/commands/exec.js +6 -2
- package/src/commands/gc.js +6 -3
- package/src/commands/init.js +4 -1
- package/src/commands/logs.js +6 -2
- package/src/commands/mcp.js +5 -2
- package/src/commands/rollback.js +6 -3
- package/src/commands/sleep.js +5 -2
- package/src/commands/status.js +6 -2
- package/src/commands/wake.js +6 -3
- package/src/core/parser.js +16 -5
- package/src/utils/args.js +11 -5
- package/src/utils/aws.js +11 -4
- package/src/utils/command.js +20 -0
- package/src/utils/hcl.js +22 -0
- package/templates/github/preview.yml +4 -3
- package/templates/github/teardown.yml +5 -2
package/bin/cli.js
CHANGED
|
@@ -23,7 +23,7 @@ import { runDrift, parseDriftArgs } from '../src/commands/drift.js';
|
|
|
23
23
|
import { runAlerts, parseAlertsArgs } from '../src/commands/alerts.js';
|
|
24
24
|
import { runMcp, parseMcpArgs } from '../src/commands/mcp.js';
|
|
25
25
|
import { runTelemetry } from '../src/commands/telemetry.js';
|
|
26
|
-
import { parseCliArgs } from '../src/core/parser.js';
|
|
26
|
+
import { parseCliArgs, stripGlobalOnlyFlags } from '../src/core/parser.js';
|
|
27
27
|
import { getCliVersion } from '../src/core/telemetry.js';
|
|
28
28
|
|
|
29
29
|
const HELP_TEXT = [
|
|
@@ -77,6 +77,10 @@ const HELP_TEXT = [
|
|
|
77
77
|
|
|
78
78
|
const rawArgs = process.argv.slice(2);
|
|
79
79
|
const parsed = parseCliArgs(rawArgs);
|
|
80
|
+
// Per-command parsers see everything except globally-honored flags:
|
|
81
|
+
// --no-telemetry already took effect via DO_NOT_TRACK, and the
|
|
82
|
+
// unknown-flag gate would otherwise reject it on every command.
|
|
83
|
+
const commandArgs = stripGlobalOnlyFlags(rawArgs);
|
|
80
84
|
|
|
81
85
|
if (parsed.hasNoTelemetry) {
|
|
82
86
|
process.env.DO_NOT_TRACK = '1';
|
|
@@ -138,43 +142,43 @@ if (wantsVersion) {
|
|
|
138
142
|
const projectName = path.basename(process.cwd());
|
|
139
143
|
runCommand(auditSecrets(envFile, projectName, { region: parseRegionFlag(rawArgs) }));
|
|
140
144
|
} else if (dispatchCommand === 'apply') {
|
|
141
|
-
runCommand(applyStack({ ...parseApplyArgs(
|
|
145
|
+
runCommand(applyStack({ ...parseApplyArgs(commandArgs), isDryRun, ...(autoApprove ? { autoApprove: true } : {}), ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
142
146
|
} else if (positionalArgs[0] === 'doctor') {
|
|
143
|
-
runCommand(runDoctor({ ...parseDoctorArgs(
|
|
147
|
+
runCommand(runDoctor({ ...parseDoctorArgs(commandArgs), ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
144
148
|
} else if (positionalArgs[0] === 'destroy') {
|
|
145
|
-
runCommand(destroyStack({ ...parseDestroyArgs(
|
|
149
|
+
runCommand(destroyStack({ ...parseDestroyArgs(commandArgs), ...(confirmYes ? { yes: true } : {}), ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
146
150
|
} else if (positionalArgs[0] === 'eject') {
|
|
147
|
-
runCommand(ejectStack({ ...parseEjectArgs(
|
|
151
|
+
runCommand(ejectStack({ ...parseEjectArgs(commandArgs), ...(confirmYes ? { yes: true } : {}), ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
148
152
|
} else if (positionalArgs[0] === 'sync-ai') {
|
|
149
153
|
runCommand(syncAi());
|
|
150
154
|
} else if (positionalArgs[0] === 'diagnose' || positionalArgs[0] === 'wtf') {
|
|
151
155
|
runCommand(runDiagnose(headlessOptions));
|
|
152
156
|
} else if (positionalArgs[0] === 'logs') {
|
|
153
|
-
runCommand(runLogs(parseLogsArgs(
|
|
157
|
+
runCommand(runLogs({ ...parseLogsArgs(commandArgs), ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
154
158
|
} else if (positionalArgs[0] === 'status') {
|
|
155
|
-
runCommand(runStatus(parseStatusArgs(
|
|
159
|
+
runCommand(runStatus({ ...parseStatusArgs(commandArgs), ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
156
160
|
} else if (positionalArgs[0] === 'rollback') {
|
|
157
|
-
runCommand(runRollback({ ...parseRollbackArgs(
|
|
161
|
+
runCommand(runRollback({ ...parseRollbackArgs(commandArgs), ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
158
162
|
} else if (positionalArgs[0] === 'exec') {
|
|
159
|
-
runCommand(runExec(parseExecArgs(
|
|
163
|
+
runCommand(runExec({ ...parseExecArgs(commandArgs), ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
160
164
|
} else if (positionalArgs[0] === 'db') {
|
|
161
|
-
runCommand(runDb(
|
|
165
|
+
runCommand(runDb(commandArgs, { ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
162
166
|
} else if (positionalArgs[0] === 'gc') {
|
|
163
|
-
runCommand(runGc(parseGcArgs(
|
|
167
|
+
runCommand(runGc({ ...parseGcArgs(commandArgs), ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
164
168
|
} else if (positionalArgs[0] === 'add') {
|
|
165
|
-
runCommand(runAdd(parseAddArgs(
|
|
169
|
+
runCommand(runAdd(parseAddArgs(commandArgs)));
|
|
166
170
|
} else if (positionalArgs[0] === 'domain') {
|
|
167
|
-
runCommand(runDomain(parseDomainArgs(
|
|
171
|
+
runCommand(runDomain(parseDomainArgs(commandArgs)));
|
|
168
172
|
} else if (positionalArgs[0] === 'sleep') {
|
|
169
|
-
runCommand(runSleep({ ...parseSleepArgs(
|
|
173
|
+
runCommand(runSleep({ ...parseSleepArgs(commandArgs), ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
170
174
|
} else if (positionalArgs[0] === 'wake') {
|
|
171
|
-
runCommand(runWake({ ...parseWakeArgs(
|
|
175
|
+
runCommand(runWake({ ...parseWakeArgs(commandArgs), ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
172
176
|
} else if (positionalArgs[0] === 'drift') {
|
|
173
|
-
runCommand(runDrift({ ...parseDriftArgs(
|
|
177
|
+
runCommand(runDrift({ ...parseDriftArgs(commandArgs), ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
174
178
|
} else if (positionalArgs[0] === 'alerts') {
|
|
175
|
-
runCommand(runAlerts({ ...parseAlertsArgs(
|
|
179
|
+
runCommand(runAlerts({ ...parseAlertsArgs(commandArgs), ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
176
180
|
} else if (positionalArgs[0] === 'mcp') {
|
|
177
|
-
runCommand(runMcp(parseMcpArgs(
|
|
181
|
+
runCommand(runMcp({ ...parseMcpArgs(commandArgs), ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
178
182
|
} else if (positionalArgs[0] === 'telemetry') {
|
|
179
183
|
runCommand(runTelemetry({ subcommand: positionalArgs[1], ...(isHeadless ? { isHeadless: true } : {}) }));
|
|
180
184
|
} else if (positionalArgs[0] === undefined || positionalArgs[0] === 'init') {
|
package/package.json
CHANGED
package/src/commands/add.js
CHANGED
|
@@ -11,8 +11,8 @@ import { ADDON_REGISTRY, ADDON_UPSERT_KEYS, resolveAddonEnvVars, addonTargetDisp
|
|
|
11
11
|
import { stripTerraformMetadata, readEjectedMarker } from '../utils/terraform-metadata.js';
|
|
12
12
|
import { normalizeDomain, isValidDomain, normalizeZoneId, isValidFromEmail, parseDomainTf } from '../utils/domains.js';
|
|
13
13
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
14
|
-
import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseIfNonInteractive } from '../utils/command.js';
|
|
15
|
-
import { findArrayBounds, findMapBounds, findNestedBlock, findResourceBlock, enclosingBraceBounds, normalizeBlankLines, realignAssignmentRuns } from '../utils/hcl.js';
|
|
14
|
+
import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseIfNonInteractive, refuseUnknownFlags } from '../utils/command.js';
|
|
15
|
+
import { findArrayBounds, findMapBounds, findNestedBlock, findResourceBlock, removeResourceBlock, enclosingBraceBounds, normalizeBlankLines, realignAssignmentRuns } from '../utils/hcl.js';
|
|
16
16
|
import { syncDocCostEstimate } from '../utils/visualizer.js';
|
|
17
17
|
import { withProjectLock } from '../utils/file-lock.js';
|
|
18
18
|
import { guardSleepingEnv, resolveSleepTarget } from '../utils/sleep-state.js';
|
|
@@ -76,7 +76,7 @@ export const DB_ADD_ENGINES = {
|
|
|
76
76
|
export function parseAddArgs(argv = []) {
|
|
77
77
|
const args = normalizeArgv(argv);
|
|
78
78
|
if (args[0] === 'add') args.shift();
|
|
79
|
-
const { options: parsed, rest } = parseFlags(args, {
|
|
79
|
+
const { options: parsed, rest, unknown } = parseFlags(args, {
|
|
80
80
|
string: ['region', 'project-name', 'partition-key', 'model', 'domain', 'from-email', 'zone-id', 'schedule', { name: 'cmd', key: 'cronCommand' }, { name: 'cron-command', key: 'cronCommand' }, 'name', 'timezone'],
|
|
81
81
|
boolean: ['force', { name: 'headless', key: 'isHeadless' }],
|
|
82
82
|
bareBoolean: ['list-models', 'refresh'],
|
|
@@ -92,6 +92,7 @@ export function parseAddArgs(argv = []) {
|
|
|
92
92
|
...parsed,
|
|
93
93
|
};
|
|
94
94
|
if (parsed.model !== undefined) options.modelProvided = true;
|
|
95
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
95
96
|
for (const arg of rest) {
|
|
96
97
|
if (typeof arg === 'string' && !arg.startsWith('-') && options.capability === undefined) {
|
|
97
98
|
options.capability = arg;
|
|
@@ -478,21 +479,34 @@ resource "aws_subnet" "db_isolated" {
|
|
|
478
479
|
}`;
|
|
479
480
|
|
|
480
481
|
// Idempotently appends the isolated-subnet block to network.tf content.
|
|
481
|
-
// Returns the content unchanged when the block already exists.
|
|
482
|
+
// Returns the content unchanged when the block already exists. Uses the
|
|
483
|
+
// HCL-aware lookup so a comment quoting the header never false-positives.
|
|
482
484
|
export function ensureIsolatedSubnets(networkTfContent) {
|
|
483
485
|
const content = String(networkTfContent ?? '');
|
|
484
|
-
if (content
|
|
486
|
+
if (findResourceBlock(content, 'aws_subnet', 'db_isolated')) return content;
|
|
485
487
|
const prefix = content.endsWith('\n') ? content : `${content}\n`;
|
|
486
488
|
return `${prefix}\n${ISOLATED_SUBNETS_BLOCK}\n`;
|
|
487
489
|
}
|
|
488
490
|
|
|
489
491
|
// Backfills the isolated-subnet block into a tree whose network.tf predates
|
|
490
|
-
// it.
|
|
491
|
-
//
|
|
492
|
+
// it. Legacy trees carry the block in database.tf instead: it is migrated
|
|
493
|
+
// (same state address — no state move needed), never duplicated. No-op
|
|
494
|
+
// when network.tf is missing (static), already has the block, or an
|
|
495
|
+
// unexpected file declares it. Returns true when network.tf was written.
|
|
492
496
|
async function backfillIsolatedSubnets(projectDir) {
|
|
493
|
-
const
|
|
497
|
+
const tfDir = path.join(projectDir, 'terraform');
|
|
498
|
+
const networkTfPath = path.join(tfDir, 'network.tf');
|
|
494
499
|
if (!fsSync.existsSync(networkTfPath)) return false;
|
|
495
500
|
const before = await fs.readFile(networkTfPath, 'utf-8');
|
|
501
|
+
if (findResourceBlock(before, 'aws_subnet', 'db_isolated')) return false;
|
|
502
|
+
for (const file of fsSync.readdirSync(tfDir).filter((f) => f.endsWith('.tf'))) {
|
|
503
|
+
if (file === 'network.tf') continue;
|
|
504
|
+
const filePath = path.join(tfDir, file);
|
|
505
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
506
|
+
if (!findResourceBlock(content, 'aws_subnet', 'db_isolated')) continue;
|
|
507
|
+
if (file !== 'database.tf') return false;
|
|
508
|
+
await atomicWriteFile(filePath, normalizeBlankLines(removeResourceBlock(content, 'aws_subnet', 'db_isolated')));
|
|
509
|
+
}
|
|
496
510
|
const after = ensureIsolatedSubnets(before);
|
|
497
511
|
if (after === before) return false;
|
|
498
512
|
await atomicWriteFile(networkTfPath, normalizeBlankLines(after));
|
|
@@ -1244,6 +1258,8 @@ export async function runAdd(input = {}) {
|
|
|
1244
1258
|
|
|
1245
1259
|
async function runAddMain(input = {}) {
|
|
1246
1260
|
const options = normalizeOptions(input);
|
|
1261
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'add', event: 'add_run' });
|
|
1262
|
+
if (unknownRefusal) return unknownRefusal;
|
|
1247
1263
|
const noExit = isProgrammaticCall(options);
|
|
1248
1264
|
let cwd;
|
|
1249
1265
|
let projectName;
|
package/src/commands/alerts.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import color from 'picocolors';
|
|
4
4
|
import { intro, outro, select, text, cancel, isCancel } from '@clack/prompts';
|
|
5
5
|
import { trackSuccess, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
6
|
-
import { failCommand, failProjectNotInitialized, refuseIfNonInteractive } from '../utils/command.js';
|
|
6
|
+
import { failCommand, failProjectNotInitialized, refuseIfNonInteractive, refuseUnknownFlags } from '../utils/command.js';
|
|
7
7
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
8
8
|
import { resolveRegion, resolveProjectName, resolveCwd, resolveHeadless, readFileSafe, readTerraformComputeTarget } from '../utils/resolvers.js';
|
|
9
9
|
import { findNestedBlock } from '../utils/hcl.js';
|
|
@@ -33,12 +33,13 @@ const TARGET_ANCHORS = {
|
|
|
33
33
|
export function parseAlertsArgs(argv = []) {
|
|
34
34
|
const args = normalizeArgv(argv);
|
|
35
35
|
if (args[0] === 'alerts') args.shift();
|
|
36
|
-
const { options, rest } = parseFlags(args, {
|
|
36
|
+
const { options, rest, unknown } = parseFlags(args, {
|
|
37
37
|
string: ['region', 'project-name', 'email', 'webhook', 'threshold'],
|
|
38
|
-
boolean: ['force'],
|
|
38
|
+
boolean: ['force', 'headless'],
|
|
39
39
|
});
|
|
40
40
|
const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
|
|
41
41
|
if (positionals.length > 0) options.unexpectedPositionals = positionals;
|
|
42
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
42
43
|
return options;
|
|
43
44
|
}
|
|
44
45
|
|
|
@@ -396,6 +397,8 @@ export async function runAlerts(input = {}) {
|
|
|
396
397
|
|
|
397
398
|
async function runAlertsMain(input = {}) {
|
|
398
399
|
const options = normalizeOptions(input);
|
|
400
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'alerts', event: 'alerts_run' });
|
|
401
|
+
if (unknownRefusal) return unknownRefusal;
|
|
399
402
|
let cwd;
|
|
400
403
|
let region;
|
|
401
404
|
let projectName;
|
package/src/commands/apply.js
CHANGED
|
@@ -5,7 +5,7 @@ import color from 'picocolors';
|
|
|
5
5
|
import { renderDryRunPreview, parseTerraformConfig, buildCostTelemetryProps } from '../utils/visualizer.js';
|
|
6
6
|
import { detectFramework } from '../utils/detector.js';
|
|
7
7
|
import { trackEvent, flushTelemetry, trackSuccess, trackFailure, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
8
|
-
import { failCommand, shouldAutoApprove, refuseIfNonInteractive } from '../utils/command.js';
|
|
8
|
+
import { failCommand, shouldAutoApprove, refuseIfNonInteractive, refuseUnknownFlags } from '../utils/command.js';
|
|
9
9
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
10
10
|
import { spawnSync } from 'child_process';
|
|
11
11
|
import { runTerraformCommand, getTerraformOutputs, readLastRunMarker, isInterruptedMarker, ensureTerraformInit, checkOutputsContract, DEFAULT_TERRAFORM_PHASE_TIMEOUT_MS } from '../utils/terraform.js';
|
|
@@ -22,10 +22,11 @@ import { runWake } from './wake.js';
|
|
|
22
22
|
export function parseApplyArgs(argv = []) {
|
|
23
23
|
const args = normalizeArgv(argv);
|
|
24
24
|
if (args[0] === 'apply' || args[0] === 'deploy') args.shift();
|
|
25
|
-
const { options } = parseFlags(args, {
|
|
26
|
-
boolean: ['force', 'destroy-previous-target', 'force-resume', 'allow-partial-outputs'],
|
|
25
|
+
const { options, unknown } = parseFlags(args, {
|
|
26
|
+
boolean: ['force', 'destroy-previous-target', 'force-resume', 'allow-partial-outputs', 'headless', 'auto-approve', 'dry-run'],
|
|
27
27
|
string: ['force-unlock'],
|
|
28
28
|
});
|
|
29
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
29
30
|
return { force: false, ...options };
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -188,6 +189,8 @@ export async function applyStack(input = {}) {
|
|
|
188
189
|
|
|
189
190
|
async function applyStackMain(input = {}) {
|
|
190
191
|
const options = normalizeOptions(input);
|
|
192
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'apply', event: 'infrastructure_applied' });
|
|
193
|
+
if (unknownRefusal) return unknownRefusal;
|
|
191
194
|
intro(color.bgCyan(color.black(' grada apply ☁️ ')));
|
|
192
195
|
|
|
193
196
|
const targetDir = process.cwd();
|
|
@@ -2,7 +2,7 @@ import { RDSClient, CreateDBSnapshotCommand, DescribeDBSnapshotsCommand, CreateD
|
|
|
2
2
|
import color from 'picocolors';
|
|
3
3
|
import { intro, outro, spinner } from '@clack/prompts';
|
|
4
4
|
import { trackSuccess, setActiveCommandName, resetActiveCommandName } from '../../core/telemetry.js';
|
|
5
|
-
import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized } from '../../utils/command.js';
|
|
5
|
+
import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized, refuseUnknownFlags } from '../../utils/command.js';
|
|
6
6
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../../utils/args.js';
|
|
7
7
|
import { isAuthError, handleAuthErrorBranch, resolveClient } from '../../utils/aws.js';
|
|
8
8
|
import { resolveRegion, resolveProjectName, resolveAppName, resolveCwd } from '../../utils/resolvers.js';
|
|
@@ -22,7 +22,7 @@ export function parseDbBackupArgs(argv = []) {
|
|
|
22
22
|
const args = normalizeArgv(argv);
|
|
23
23
|
if (args[0] === 'db') args.shift();
|
|
24
24
|
if (args[0] === 'backup') args.shift();
|
|
25
|
-
const { options, rest } = parseFlags(args, {
|
|
25
|
+
const { options, rest, unknown } = parseFlags(args, {
|
|
26
26
|
string: [
|
|
27
27
|
{ name: 'id', key: 'snapshotId' },
|
|
28
28
|
{ name: 'timeout', key: 'timeout' },
|
|
@@ -35,6 +35,7 @@ export function parseDbBackupArgs(argv = []) {
|
|
|
35
35
|
});
|
|
36
36
|
const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
|
|
37
37
|
if (positionals.length > 0) options.unexpectedPositionals = positionals;
|
|
38
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
38
39
|
return options;
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -51,6 +52,8 @@ export async function runDbBackup(input = {}) {
|
|
|
51
52
|
|
|
52
53
|
async function runDbBackupMain(input = {}) {
|
|
53
54
|
const options = normalizeOptions(input);
|
|
55
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'db backup', event: 'db_backup_run' });
|
|
56
|
+
if (unknownRefusal) return unknownRefusal;
|
|
54
57
|
let cwd;
|
|
55
58
|
let region;
|
|
56
59
|
let projectName;
|
|
@@ -5,7 +5,7 @@ import { spawn } from 'child_process';
|
|
|
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 { hasAwsCli, AWS_CLI_INSTALL_URL, isAuthError, handleAuthErrorBranch, resolveClient } from '../../utils/aws.js';
|
|
11
11
|
import { resolveRegion, resolveProjectName, resolveCluster, resolveService, resolveAppName, resolveCwd } from '../../utils/resolvers.js';
|
|
@@ -46,10 +46,11 @@ export function parseDbArgs(argv = []) {
|
|
|
46
46
|
const args = normalizeArgv(argv);
|
|
47
47
|
if (args[0] === 'db') args.shift();
|
|
48
48
|
if (args[0] === 'connect') args.shift();
|
|
49
|
-
const { options } = parseFlags(args, {
|
|
49
|
+
const { options, unknown } = parseFlags(args, {
|
|
50
50
|
string: ['port', 'region', 'cluster', 'service', 'workspace'],
|
|
51
|
-
boolean: ['show-credentials'],
|
|
51
|
+
boolean: ['show-credentials', 'headless'],
|
|
52
52
|
});
|
|
53
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
53
54
|
return options;
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -104,6 +105,8 @@ export async function runDbConnect(input = {}) {
|
|
|
104
105
|
|
|
105
106
|
async function runDbConnectMain(input = {}) {
|
|
106
107
|
const options = normalizeOptions(input);
|
|
108
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'db connect', event: 'db_connect_run' });
|
|
109
|
+
if (unknownRefusal) return unknownRefusal;
|
|
107
110
|
let cwd;
|
|
108
111
|
let region;
|
|
109
112
|
let projectName;
|
|
@@ -3,7 +3,7 @@ import { CloudWatchLogsClient } from '@aws-sdk/client-cloudwatch-logs';
|
|
|
3
3
|
import color from 'picocolors';
|
|
4
4
|
import { intro, outro, spinner } from '@clack/prompts';
|
|
5
5
|
import { trackSuccess, setActiveCommandName, resetActiveCommandName } from '../../core/telemetry.js';
|
|
6
|
-
import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized } from '../../utils/command.js';
|
|
6
|
+
import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized, refuseUnknownFlags } from '../../utils/command.js';
|
|
7
7
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../../utils/args.js';
|
|
8
8
|
import { isAuthError, handleAuthErrorBranch, resolveClient } from '../../utils/aws.js';
|
|
9
9
|
import {
|
|
@@ -37,7 +37,7 @@ export function parseDbEnableVectorArgs(argv = []) {
|
|
|
37
37
|
const args = normalizeArgv(argv);
|
|
38
38
|
if (args[0] === 'db') args.shift();
|
|
39
39
|
if (args[0] === 'enable-vector') args.shift();
|
|
40
|
-
const { options, rest } = parseFlags(args, {
|
|
40
|
+
const { options, rest, unknown } = parseFlags(args, {
|
|
41
41
|
string: [
|
|
42
42
|
{ name: 'cluster', key: 'cluster' },
|
|
43
43
|
{ name: 'service', key: 'service' },
|
|
@@ -52,6 +52,7 @@ export function parseDbEnableVectorArgs(argv = []) {
|
|
|
52
52
|
});
|
|
53
53
|
const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
|
|
54
54
|
if (positionals.length > 0) options.unexpectedPositionals = positionals;
|
|
55
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
55
56
|
return options;
|
|
56
57
|
}
|
|
57
58
|
|
|
@@ -129,6 +130,8 @@ export async function runDbEnableVector(input = {}) {
|
|
|
129
130
|
|
|
130
131
|
async function runDbEnableVectorMain(input = {}) {
|
|
131
132
|
const options = normalizeOptions(input);
|
|
133
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'db enable-vector', event: 'db_enable_vector_run' });
|
|
134
|
+
if (unknownRefusal) return unknownRefusal;
|
|
132
135
|
const startTime = Date.now();
|
|
133
136
|
let cwd;
|
|
134
137
|
let region;
|
|
@@ -8,7 +8,7 @@ import zlib from 'node:zlib';
|
|
|
8
8
|
import color from 'picocolors';
|
|
9
9
|
import { intro, outro, spinner, select, text, password, confirm, cancel, isCancel } from '@clack/prompts';
|
|
10
10
|
import { trackSuccess, setActiveCommandName, resetActiveCommandName } from '../../core/telemetry.js';
|
|
11
|
-
import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized } from '../../utils/command.js';
|
|
11
|
+
import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized, refuseUnknownFlags } from '../../utils/command.js';
|
|
12
12
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../../utils/args.js';
|
|
13
13
|
import { hasAwsCli, AWS_CLI_INSTALL_URL, isAuthError, handleAuthErrorBranch, resolveClient } from '../../utils/aws.js';
|
|
14
14
|
import {
|
|
@@ -49,7 +49,7 @@ export function parseDbImportArgs(argv = []) {
|
|
|
49
49
|
const args = normalizeArgv(argv);
|
|
50
50
|
if (args[0] === 'db') args.shift();
|
|
51
51
|
if (args[0] === 'import') args.shift();
|
|
52
|
-
const { options, rest } = parseFlags(args, {
|
|
52
|
+
const { options, rest, unknown } = parseFlags(args, {
|
|
53
53
|
string: [
|
|
54
54
|
{ name: 'file', key: 'file' },
|
|
55
55
|
{ name: 'from', key: 'from' },
|
|
@@ -62,6 +62,7 @@ export function parseDbImportArgs(argv = []) {
|
|
|
62
62
|
});
|
|
63
63
|
const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
|
|
64
64
|
if (positionals.length > 0) options.unexpectedPositionals = positionals;
|
|
65
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
65
66
|
return options;
|
|
66
67
|
}
|
|
67
68
|
|
|
@@ -165,6 +166,8 @@ export async function runDbImport(input = {}) {
|
|
|
165
166
|
|
|
166
167
|
async function runDbImportMain(input = {}) {
|
|
167
168
|
const options = normalizeOptions(input);
|
|
169
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'db import', event: 'db_import_run' });
|
|
170
|
+
if (unknownRefusal) return unknownRefusal;
|
|
168
171
|
let cwd;
|
|
169
172
|
let region;
|
|
170
173
|
let projectName;
|
|
@@ -3,7 +3,7 @@ import { CloudWatchLogsClient } from '@aws-sdk/client-cloudwatch-logs';
|
|
|
3
3
|
import color from 'picocolors';
|
|
4
4
|
import { intro, outro, spinner, text, isCancel } from '@clack/prompts';
|
|
5
5
|
import { trackEvent, trackSuccess, setActiveCommandName, resetActiveCommandName, getCliVersion } from '../../core/telemetry.js';
|
|
6
|
-
import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized } from '../../utils/command.js';
|
|
6
|
+
import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized, refuseUnknownFlags } from '../../utils/command.js';
|
|
7
7
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../../utils/args.js';
|
|
8
8
|
import { isAuthError, handleAuthErrorBranch, resolveClient } from '../../utils/aws.js';
|
|
9
9
|
import {
|
|
@@ -58,7 +58,7 @@ export function parseDbMigrateArgs(argv = []) {
|
|
|
58
58
|
const args = normalizeArgv(argv);
|
|
59
59
|
if (args[0] === 'db') args.shift();
|
|
60
60
|
if (args[0] === 'migrate') args.shift();
|
|
61
|
-
const { options, rest } = parseFlags(args, {
|
|
61
|
+
const { options, rest, unknown } = parseFlags(args, {
|
|
62
62
|
string: [
|
|
63
63
|
{ name: 'cmd', key: 'cmd' },
|
|
64
64
|
{ name: 'task-def', key: 'taskDef' },
|
|
@@ -74,6 +74,7 @@ export function parseDbMigrateArgs(argv = []) {
|
|
|
74
74
|
});
|
|
75
75
|
const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
|
|
76
76
|
if (positionals.length > 0) options.unexpectedPositionals = positionals;
|
|
77
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
77
78
|
return options;
|
|
78
79
|
}
|
|
79
80
|
|
|
@@ -260,6 +261,8 @@ export async function runDbMigrate(input = {}) {
|
|
|
260
261
|
|
|
261
262
|
async function runDbMigrateMain(input = {}) {
|
|
262
263
|
const options = normalizeOptions(input);
|
|
264
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'db migrate', event: 'db_migrate_run' });
|
|
265
|
+
if (unknownRefusal) return unknownRefusal;
|
|
263
266
|
let cwd;
|
|
264
267
|
let region;
|
|
265
268
|
let projectName;
|
|
@@ -4,7 +4,7 @@ import path from 'path';
|
|
|
4
4
|
import color from 'picocolors';
|
|
5
5
|
import { intro, outro, spinner, select, confirm, cancel, isCancel } from '@clack/prompts';
|
|
6
6
|
import { trackSuccess, setActiveCommandName, resetActiveCommandName } from '../../core/telemetry.js';
|
|
7
|
-
import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized } from '../../utils/command.js';
|
|
7
|
+
import { failCommand, failAwsError, trackAwsFailure, failProjectNotInitialized, refuseUnknownFlags } from '../../utils/command.js';
|
|
8
8
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../../utils/args.js';
|
|
9
9
|
import { isAuthError, handleAuthErrorBranch, resolveClient } from '../../utils/aws.js';
|
|
10
10
|
import { resolveRegion, resolveProjectName, resolveAppName, resolveHeadless, resolveCwd } from '../../utils/resolvers.js';
|
|
@@ -24,7 +24,7 @@ export function parseDbRestoreArgs(argv = []) {
|
|
|
24
24
|
const args = normalizeArgv(argv);
|
|
25
25
|
if (args[0] === 'db') args.shift();
|
|
26
26
|
if (args[0] === 'restore') args.shift();
|
|
27
|
-
const { options, rest } = parseFlags(args, {
|
|
27
|
+
const { options, rest, unknown } = parseFlags(args, {
|
|
28
28
|
string: [
|
|
29
29
|
{ name: 'project-name', key: 'projectName' },
|
|
30
30
|
{ name: 'region', key: 'region' },
|
|
@@ -36,6 +36,7 @@ export function parseDbRestoreArgs(argv = []) {
|
|
|
36
36
|
const positionals = rest.filter((arg) => typeof arg === 'string' && !arg.startsWith('-'));
|
|
37
37
|
if (positionals.length > 0) options.snapshotId = positionals[0];
|
|
38
38
|
if (positionals.length > 1) options.unexpectedPositionals = positionals.slice(1);
|
|
39
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
39
40
|
return options;
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -172,6 +173,8 @@ export async function runDbRestore(input = {}) {
|
|
|
172
173
|
|
|
173
174
|
async function runDbRestoreMain(input = {}) {
|
|
174
175
|
const options = normalizeOptions(input);
|
|
176
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'db restore', event: 'db_restore_run' });
|
|
177
|
+
if (unknownRefusal) return unknownRefusal;
|
|
175
178
|
let cwd;
|
|
176
179
|
let region;
|
|
177
180
|
let projectName;
|
package/src/commands/destroy.js
CHANGED
|
@@ -7,7 +7,7 @@ import { S3Client } from '@aws-sdk/client-s3';
|
|
|
7
7
|
import { teardownStateBucket, drainBucketObjects, resolveClient } from '../utils/aws.js';
|
|
8
8
|
import { checkDependency, pollUntil } from '../utils/system.js';
|
|
9
9
|
import { trackEvent, flushTelemetry, trackSuccess, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
10
|
-
import { failCommand, shouldAutoApprove, refuseIfNonInteractive } from '../utils/command.js';
|
|
10
|
+
import { failCommand, shouldAutoApprove, refuseIfNonInteractive, refuseUnknownFlags } from '../utils/command.js';
|
|
11
11
|
import { runTerraformCommand, readLastRunMarker, isInterruptedMarker, ensureTerraformInit, getTerraformStateBuckets, DEFAULT_TERRAFORM_PHASE_TIMEOUT_MS } from '../utils/terraform.js';
|
|
12
12
|
import { classifyTerraformError, getRunbook, ERROR_CODES } from '../utils/terraform-errors.js';
|
|
13
13
|
import { findDbTarget, dbStatusOf, resolveDbIdentifier, resolveDbClusterIdentifier, generateSnapshotId } from '../utils/rds.js';
|
|
@@ -38,10 +38,11 @@ export function treeDeclaresDataLossVar(tfDir) {
|
|
|
38
38
|
|
|
39
39
|
export function parseDestroyArgs(argv = []) {
|
|
40
40
|
const args = normalizeArgv(argv);
|
|
41
|
-
const { options } = parseFlags(args, {
|
|
42
|
-
boolean: ['allow-data-loss', 'force'],
|
|
41
|
+
const { options, unknown } = parseFlags(args, {
|
|
42
|
+
boolean: ['allow-data-loss', 'force', 'headless', 'yes'],
|
|
43
43
|
string: ['force-unlock'],
|
|
44
44
|
});
|
|
45
|
+
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
45
46
|
return { allowDataLoss: false, force: false, ...options };
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -145,6 +146,8 @@ export async function destroyStack(input = {}) {
|
|
|
145
146
|
|
|
146
147
|
async function destroyStackMain(input = {}) {
|
|
147
148
|
const options = normalizeOptions(input);
|
|
149
|
+
const unknownRefusal = await refuseUnknownFlags(options, { command: 'destroy', event: 'infrastructure_destroyed' });
|
|
150
|
+
if (unknownRefusal) return unknownRefusal;
|
|
148
151
|
intro(color.bgRed(color.white(' grada destroy 🗑️ ')));
|
|
149
152
|
|
|
150
153
|
// Ejected trees are user-owned: refuse unless --force.
|
package/src/commands/doctor.js
CHANGED
|
@@ -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 };
|
package/src/commands/domain.js
CHANGED
|
@@ -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
|
|
package/src/commands/drift.js
CHANGED
|
@@ -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;
|
package/src/commands/eject.js
CHANGED
|
@@ -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.'));
|
package/src/commands/exec.js
CHANGED
|
@@ -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;
|
package/src/commands/gc.js
CHANGED
|
@@ -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;
|
package/src/commands/init.js
CHANGED
|
@@ -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,
|
package/src/commands/logs.js
CHANGED
|
@@ -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;
|
package/src/commands/mcp.js
CHANGED
|
@@ -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) {
|
package/src/commands/rollback.js
CHANGED
|
@@ -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;
|
package/src/commands/sleep.js
CHANGED
|
@@ -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;
|
package/src/commands/status.js
CHANGED
|
@@ -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;
|
package/src/commands/wake.js
CHANGED
|
@@ -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;
|
package/src/core/parser.js
CHANGED
|
@@ -69,10 +69,11 @@ export function parseCliArgs(processArgs) {
|
|
|
69
69
|
return false;
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
// 4. Parse execution flags
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
const
|
|
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:
|
|
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
|
-
//
|
|
46
|
-
//
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
}
|
package/src/utils/command.js
CHANGED
|
@@ -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.
|
|
@@ -60,9 +60,10 @@ jobs:
|
|
|
60
60
|
terraform workspace select -or-create ${{ env.WORKSPACE }}
|
|
61
61
|
terraform apply -auto-approve
|
|
62
62
|
|
|
63
|
-
# Extract the
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
# Extract the CloudFront URL to post to GitHub (the ALB origin
|
|
64
|
+
# accepts CloudFront edges only — its direct URL is not browsable)
|
|
65
|
+
PREVIEW_URL=$(terraform output -raw cloudfront_url)
|
|
66
|
+
echo "PREVIEW_URL=$PREVIEW_URL" >> $GITHUB_ENV
|
|
66
67
|
|
|
67
68
|
- name: Comment PR
|
|
68
69
|
uses: actions/github-script@v7
|
|
@@ -41,8 +41,11 @@ jobs:
|
|
|
41
41
|
run: |
|
|
42
42
|
terraform init -input=false
|
|
43
43
|
# PRs that never got a preview (early failure, pre-previews PR)
|
|
44
|
-
# have no workspace — exit green instead of failing the run.
|
|
45
|
-
|
|
44
|
+
# have no workspace — exit green instead of failing the run. But
|
|
45
|
+
# a failed listing (backend outage, dead creds) must stay red:
|
|
46
|
+
# matching against empty output would leak the stack silently.
|
|
47
|
+
WORKSPACES=$(terraform workspace list 2>&1) || { echo "$WORKSPACES"; exit 1; }
|
|
48
|
+
if ! printf '%s\n' "$WORKSPACES" | sed 's/^[* ]*//' | grep -qx "${{ env.WORKSPACE }}"; then
|
|
46
49
|
echo "No preview workspace ${{ env.WORKSPACE }} — nothing to tear down."
|
|
47
50
|
exit 0
|
|
48
51
|
fi
|