@monster-orange/den 0.0.0 → 0.2.0
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/CHANGELOG.md +204 -0
- package/LICENSE +21 -0
- package/README.md +165 -1
- package/bin/den +68 -0
- package/docs/distributions.md +499 -0
- package/make/demo.mk +82 -0
- package/make/den.mk +80 -0
- package/make/journeys.mk +57 -0
- package/make/local_dev.mk +154 -0
- package/make/security.mk +59 -0
- package/make/test.mk +405 -0
- package/package.json +101 -4
- package/scripts/auth-configure.ts +415 -0
- package/scripts/heal-config.ts +92 -0
- package/scripts/jsonl-playwright-reporter.js +70 -0
- package/scripts/manifest-read.cjs +91 -0
- package/scripts/setup-1password.ts +570 -0
- package/scripts/setup-secrets.ts +149 -0
- package/scripts/view-results.js +156 -0
- package/service/install.sh +112 -0
- package/src/pillars/api/fixtures/index.ts +128 -0
- package/src/pillars/api/fixtures/openapi-validator.ts +111 -0
- package/src/pillars/api/global-setup.ts +103 -0
- package/src/pillars/api/playwright.config.ts +105 -0
- package/src/pillars/api/schemas/example-api.json +110 -0
- package/src/pillars/api/tests/health/health.spec.ts +19 -0
- package/src/pillars/api/tests/health/manifest.yml +6 -0
- package/src/pillars/browser/fixtures/index.ts +232 -0
- package/src/pillars/browser/fixtures/package.json +10 -0
- package/src/pillars/browser/global-setup.ts +140 -0
- package/src/pillars/browser/global-teardown.ts +48 -0
- package/src/pillars/browser/playwright.config.ts +212 -0
- package/src/pillars/browser/setup.ts +219 -0
- package/src/pillars/journeys/app-config.ts +237 -0
- package/src/pillars/journeys/discover.ts +160 -0
- package/src/pillars/journeys/hooks/deny-shell.cjs +44 -0
- package/src/pillars/journeys/observability/events.ts +288 -0
- package/src/pillars/journeys/observability/sdk-mapper.ts +306 -0
- package/src/pillars/journeys/report/friction.ts +304 -0
- package/src/pillars/journeys/report/junit.ts +105 -0
- package/src/pillars/journeys/report/render.ts +273 -0
- package/src/pillars/journeys/report/results.ts +323 -0
- package/src/pillars/journeys/run.ts +673 -0
- package/src/pillars/journeys/runner.ts +1025 -0
- package/src/pillars/journeys/sandbox.ts +403 -0
- package/src/pillars/journeys/spec/loader.ts +152 -0
- package/src/pillars/journeys/spec/schema.ts +208 -0
- package/src/pillars/journeys/teardown.ts +98 -0
- package/src/pillars/journeys/tools/browser-session.ts +219 -0
- package/src/pillars/journeys/tools/browser-tool.ts +914 -0
- package/src/pillars/journeys/tools/http-tool.ts +564 -0
- package/src/pillars/journeys/tools/ledger.ts +278 -0
- package/src/pillars/journeys/tools/snapshot-store.ts +117 -0
- package/src/pillars/journeys/verify/assertions.ts +502 -0
- package/src/pillars/journeys/verify/verdict.ts +71 -0
- package/src/pillars/perf/build-report.ts +36 -0
- package/src/pillars/perf/k6.config.js +112 -0
- package/src/pillars/perf/run.ts +345 -0
- package/src/pillars/perf/scenarios/load-profile.js +97 -0
- package/src/pillars/perf/staging.ts +73 -0
- package/src/pillars/security/discover.ts +124 -0
- package/src/pillars/security/findings.ts +151 -0
- package/src/pillars/security/plan.ts +355 -0
- package/src/pillars/security/run.ts +757 -0
- package/src/pillars/smoke/admin-probe.ts +68 -0
- package/src/pillars/smoke/base-url.ts +56 -0
- package/src/pillars/smoke/cleanup.ts +8 -0
- package/src/pillars/smoke/discover.ts +237 -0
- package/src/pillars/smoke/ensure-smoke-teardown.ts +40 -0
- package/src/pillars/smoke/fixture-manager.ts +217 -0
- package/src/pillars/smoke/fixtures.ts +468 -0
- package/src/pillars/smoke/global-setup-all.ts +262 -0
- package/src/pillars/smoke/global-setup-global.ts +262 -0
- package/src/pillars/smoke/global-setup.ts +273 -0
- package/src/pillars/smoke/global-teardown-all.ts +8 -0
- package/src/pillars/smoke/global-teardown-global.ts +8 -0
- package/src/pillars/smoke/global-teardown.ts +139 -0
- package/src/pillars/smoke/playwright-all.config.ts +147 -0
- package/src/pillars/smoke/playwright-global.config.ts +141 -0
- package/src/pillars/smoke/playwright.config.ts +162 -0
- package/src/pillars/smoke/setup-env.ts +132 -0
- package/src/pillars/smoke/setup-global.ts +126 -0
- package/src/pillars/smoke/setup.ts +115 -0
- package/src/pillars/smoke/smoke-repo.ts +16 -0
- package/src/pillars/smoke/staging.ts +49 -0
- package/src/pillars/suites/run.ts +147 -0
- package/src/scripts/configure-aws-profiles.ts +114 -0
- package/src/scripts/register-repos.ts +307 -0
- package/src/scripts/setup-default-workspace.ts +203 -0
- package/src/shared/agent-actor.ts +77 -0
- package/src/shared/applications.ts +138 -0
- package/src/shared/auth/api-token.ts +416 -0
- package/src/shared/auth/auth0-helper.ts +284 -0
- package/src/shared/auth/headless-login.ts +265 -0
- package/src/shared/auth/jwt-helper.ts +186 -0
- package/src/shared/auth/sudo-vault.ts +69 -0
- package/src/shared/auth/test-accounts.ts +98 -0
- package/src/shared/auth/token-injection.ts +184 -0
- package/src/shared/auth/token-providers/auth0.ts +80 -0
- package/src/shared/auth/token-providers/index.ts +182 -0
- package/src/shared/auth/token-refresh.ts +273 -0
- package/src/shared/banner.ts +15 -0
- package/src/shared/brand.ts +79 -0
- package/src/shared/cli-tabs.ts +131 -0
- package/src/shared/constants.ts +128 -0
- package/src/shared/den-config.ts +688 -0
- package/src/shared/dev-metrics/emit.ts +354 -0
- package/src/shared/edge/config.ts +229 -0
- package/src/shared/edge/render.ts +221 -0
- package/src/shared/edge/runtime.ts +268 -0
- package/src/shared/edge/status.ts +74 -0
- package/src/shared/edge/types.ts +62 -0
- package/src/shared/engine.ts +67 -0
- package/src/shared/environment/aws-profiles.ts +49 -0
- package/src/shared/environment/env-selector.ts +161 -0
- package/src/shared/environment/playwright-env.ts +82 -0
- package/src/shared/environment-manager/catalog.ts +77 -0
- package/src/shared/environment-manager/clone-guard.ts +163 -0
- package/src/shared/environment-manager/dag.ts +286 -0
- package/src/shared/environment-manager/default-workspace.ts +182 -0
- package/src/shared/environment-manager/derivation/alias.ts +90 -0
- package/src/shared/environment-manager/derivation/cache.ts +97 -0
- package/src/shared/environment-manager/derivation/derive-graph.ts +421 -0
- package/src/shared/environment-manager/derivation/derived-up.ts +354 -0
- package/src/shared/environment-manager/derivation/load-alias.ts +11 -0
- package/src/shared/environment-manager/derivation/rules-compose.ts +42 -0
- package/src/shared/environment-manager/derivation/rules-events.ts +50 -0
- package/src/shared/environment-manager/derivation/rules-http.ts +247 -0
- package/src/shared/environment-manager/derivation/rules-infra.ts +64 -0
- package/src/shared/environment-manager/derivation/rules-readiness.ts +96 -0
- package/src/shared/environment-manager/derivation/scan.ts +160 -0
- package/src/shared/environment-manager/derivation/text.ts +40 -0
- package/src/shared/environment-manager/derivation/types.ts +69 -0
- package/src/shared/environment-manager/health.ts +635 -0
- package/src/shared/environment-manager/index.ts +6 -0
- package/src/shared/environment-manager/load-applications.ts +108 -0
- package/src/shared/environment-manager/log-tail.ts +213 -0
- package/src/shared/environment-manager/make-targets.ts +78 -0
- package/src/shared/environment-manager/opctl.ts +335 -0
- package/src/shared/environment-manager/readiness.ts +93 -0
- package/src/shared/environment-manager/register-local.ts +72 -0
- package/src/shared/environment-manager/secrets-check.ts +260 -0
- package/src/shared/environment-manager/service-container.ts +47 -0
- package/src/shared/environment-manager/service-env.ts +110 -0
- package/src/shared/environment-manager/service-runner.ts +1603 -0
- package/src/shared/environment-manager/sync-targets.ts +66 -0
- package/src/shared/environment-manager/up-plan.ts +326 -0
- package/src/shared/environment-manager/workspace-manager.ts +905 -0
- package/src/shared/environment-manager/workspaces.ts +860 -0
- package/src/shared/manifest/deps.ts +27 -0
- package/src/shared/manifest/merge-override.ts +75 -0
- package/src/shared/manifest/migrate-manifest.ts +101 -0
- package/src/shared/manifest/placement.ts +321 -0
- package/src/shared/manifest/read-manifest.ts +278 -0
- package/src/shared/manifest/schema.ts +313 -0
- package/src/shared/manifest/service-links.ts +93 -0
- package/src/shared/manifest/validate-layers.ts +229 -0
- package/src/shared/manifest/validate-manifest.ts +200 -0
- package/src/shared/manifest/workspace-manifests.ts +92 -0
- package/src/shared/open-url.ts +122 -0
- package/src/shared/org.ts +44 -0
- package/src/shared/paths.ts +190 -0
- package/src/shared/perf/optional-fields.ts +105 -0
- package/src/shared/perf/report-normalizer.ts +404 -0
- package/src/shared/perf/report-paths.ts +19 -0
- package/src/shared/perf/report-store.ts +110 -0
- package/src/shared/perf/report-types.ts +70 -0
- package/src/shared/perf/test-paths.ts +25 -0
- package/src/shared/process/log-rotation.ts +147 -0
- package/src/shared/process/spawn-streaming.ts +229 -0
- package/src/shared/product.ts +92 -0
- package/src/shared/profile.ts +141 -0
- package/src/shared/redact.ts +107 -0
- package/src/shared/repo-kind.ts +32 -0
- package/src/shared/reporting/jsonl-reporter.ts +131 -0
- package/src/shared/reporting/slack-reporter.ts +340 -0
- package/src/shared/results/result-reader.ts +266 -0
- package/src/shared/results/result-writer.ts +168 -0
- package/src/shared/secrets/doppler.ts +126 -0
- package/src/shared/secrets/env.ts +48 -0
- package/src/shared/secrets/index.ts +197 -0
- package/src/shared/secrets/keys.ts +33 -0
- package/src/shared/secrets/onepassword.ts +75 -0
- package/src/shared/secrets/types.ts +52 -0
- package/src/shared/service-url.ts +119 -0
- package/src/shared/smoke/branch-resolver.ts +141 -0
- package/src/shared/smoke/git-remote.ts +70 -0
- package/src/shared/smoke/repo-cloner.ts +151 -0
- package/src/shared/stacks/config.ts +137 -0
- package/src/shared/stacks/manifest-commands.ts +118 -0
- package/src/shared/stacks/render.ts +253 -0
- package/src/shared/stacks/runtime.ts +334 -0
- package/src/shared/stacks/status.ts +99 -0
- package/src/shared/stacks/types.ts +53 -0
- package/src/shared/terminal/tabs.ts +212 -0
- package/src/shared/test-discovery/module-scanner.ts +569 -0
- package/src/shared/types/index.ts +701 -0
- package/src/shared/ui-marker.ts +19 -0
- package/src/ui/cli/applications-command.ts +148 -0
- package/src/ui/cli/config-command.ts +68 -0
- package/src/ui/cli/create-main.ts +9 -0
- package/src/ui/cli/create.ts +360 -0
- package/src/ui/cli/edge-command.ts +81 -0
- package/src/ui/cli/flag-parser.ts +246 -0
- package/src/ui/cli/graph-command.ts +570 -0
- package/src/ui/cli/health-display.ts +63 -0
- package/src/ui/cli/index.ts +3742 -0
- package/src/ui/cli/init.ts +855 -0
- package/src/ui/cli/invocation-target.ts +175 -0
- package/src/ui/cli/logs-command.ts +104 -0
- package/src/ui/cli/mcp-main.ts +13 -0
- package/src/ui/cli/mcp-stdout-guard.ts +10 -0
- package/src/ui/cli/module-selection.ts +31 -0
- package/src/ui/cli/prompts.ts +767 -0
- package/src/ui/cli/results-viewer.ts +436 -0
- package/src/ui/cli/secrets-preflight.ts +91 -0
- package/src/ui/cli/stack-command.ts +117 -0
- package/src/ui/cli/stalled-setup-recovery.ts +129 -0
- package/src/ui/cli/test-runner.ts +1319 -0
- package/src/ui/cli/web-command.ts +1073 -0
- package/src/ui/mcp/api.ts +284 -0
- package/src/ui/mcp/guards.ts +141 -0
- package/src/ui/mcp/server.ts +147 -0
- package/src/ui/mcp/tools.ts +565 -0
- package/src/ui/server/audit.ts +71 -0
- package/src/ui/server/changelog-parser.ts +105 -0
- package/src/ui/server/daemon-reaper.ts +129 -0
- package/src/ui/server/editor-manager.ts +301 -0
- package/src/ui/server/github-service.ts +223 -0
- package/src/ui/server/graph-prefs.ts +89 -0
- package/src/ui/server/health-row.ts +15 -0
- package/src/ui/server/http-helpers.ts +98 -0
- package/src/ui/server/index.ts +3350 -0
- package/src/ui/server/log-history.ts +453 -0
- package/src/ui/server/perf-report.ts +42 -0
- package/src/ui/server/public/environments.html +496 -0
- package/src/ui/server/public/favicon.ico +0 -0
- package/src/ui/server/public/graph-model.js +416 -0
- package/src/ui/server/public/graph.css +976 -0
- package/src/ui/server/public/graph.js +986 -0
- package/src/ui/server/public/header.js +1373 -0
- package/src/ui/server/public/index.html +2595 -0
- package/src/ui/server/public/local-dev.html +5344 -0
- package/src/ui/server/public/logs.html +1496 -0
- package/src/ui/server/public/panel.js +787 -0
- package/src/ui/server/public/perf-report.js +359 -0
- package/src/ui/server/public/release.html +2111 -0
- package/src/ui/server/public/services.html +1103 -0
- package/src/ui/server/public/workspace-picker.js +69 -0
- package/src/ui/server/readonly-routes.ts +200 -0
- package/src/ui/server/release-deploy-session.ts +246 -0
- package/src/ui/server/release-service.ts +1125 -0
- package/src/ui/server/sudo-store.ts +111 -0
- package/src/ui/server/ui-assets.ts +73 -0
- package/src/ui/server/workspace-routes.ts +2185 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { product } from "../../shared/product.js";
|
|
2
|
+
export type CommandName =
|
|
3
|
+
| "run"
|
|
4
|
+
| "menu"
|
|
5
|
+
| "view-results"
|
|
6
|
+
| "web"
|
|
7
|
+
| "up"
|
|
8
|
+
| "down"
|
|
9
|
+
| "restart"
|
|
10
|
+
| "status"
|
|
11
|
+
| "logs"
|
|
12
|
+
| "services"
|
|
13
|
+
| "graph"
|
|
14
|
+
| "register"
|
|
15
|
+
| "use-local"
|
|
16
|
+
| "use-managed"
|
|
17
|
+
| "setup"
|
|
18
|
+
| "workspace"
|
|
19
|
+
| "sync"
|
|
20
|
+
| "init"
|
|
21
|
+
| "validate"
|
|
22
|
+
| "create"
|
|
23
|
+
| "local-dev"
|
|
24
|
+
| "config"
|
|
25
|
+
| "--help"
|
|
26
|
+
| "-h"
|
|
27
|
+
| "--version"
|
|
28
|
+
| "-v";
|
|
29
|
+
|
|
30
|
+
export interface ParsedCliArgs {
|
|
31
|
+
command?: string;
|
|
32
|
+
args: string[];
|
|
33
|
+
flags: {
|
|
34
|
+
workspace?: string;
|
|
35
|
+
forceTabs?: boolean;
|
|
36
|
+
skipSecrets?: boolean;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Commands that CHANGE what is running, so `-w` must name an active workspace:
|
|
42
|
+
* ownership refcounts, conflict blocks and shared-instance decisions are all
|
|
43
|
+
* defined over the active set (design decision 6).
|
|
44
|
+
*/
|
|
45
|
+
const WORKSPACE_MUTATION_COMMANDS = new Set(["up", "down", "restart"]);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Read-only commands that are workspace-relative but require no activation —
|
|
49
|
+
* inspecting a workspace is not operating on it. `/api/graph` has always
|
|
50
|
+
* allowed this ("any workspace may be graphed"); requiring activation here
|
|
51
|
+
* would also regress the pre-multi-active `-w` ("use this workspace for this
|
|
52
|
+
* command only").
|
|
53
|
+
*/
|
|
54
|
+
const WORKSPACE_READ_COMMANDS = new Set([
|
|
55
|
+
"status",
|
|
56
|
+
"logs",
|
|
57
|
+
"services",
|
|
58
|
+
// A repo name resolves per workspace, so the graph is workspace-relative too.
|
|
59
|
+
"graph",
|
|
60
|
+
// Compose stacks run per workspace (project `<stack>-<workspace>`).
|
|
61
|
+
"stack",
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
const WORKSPACE_COMMANDS = new Set([
|
|
65
|
+
...WORKSPACE_MUTATION_COMMANDS,
|
|
66
|
+
...WORKSPACE_READ_COMMANDS,
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
/** Whether `-w <name>` on this command requires `<name>` to be active. */
|
|
70
|
+
export function workspaceFlagRequiresActive(command: string): boolean {
|
|
71
|
+
return WORKSPACE_MUTATION_COMMANDS.has(command);
|
|
72
|
+
}
|
|
73
|
+
const TAB_COMMANDS = new Set(["up", "restart"]);
|
|
74
|
+
const SKIP_SECRETS_COMMANDS = new Set(["up", "restart", "logs"]);
|
|
75
|
+
|
|
76
|
+
function consumeFlagValue(raw: string[], index: number, flag: string): string {
|
|
77
|
+
const value = raw[index + 1];
|
|
78
|
+
if (!value || value.startsWith("-")) {
|
|
79
|
+
throw new Error(`${flag} requires a value`);
|
|
80
|
+
}
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function applyFlag(
|
|
85
|
+
raw: string[],
|
|
86
|
+
index: number,
|
|
87
|
+
flags: ParsedCliArgs["flags"],
|
|
88
|
+
): number | null {
|
|
89
|
+
const token = raw[index];
|
|
90
|
+
// `--flag=value` form for value-taking flags (-w/--workspace).
|
|
91
|
+
const eq = token.indexOf("=");
|
|
92
|
+
const name = eq === -1 ? token : token.slice(0, eq);
|
|
93
|
+
if (name === "-w" || name === "--workspace") {
|
|
94
|
+
if (eq !== -1) {
|
|
95
|
+
const value = token.slice(eq + 1);
|
|
96
|
+
if (!value) {
|
|
97
|
+
throw new Error(`${name} requires a value`);
|
|
98
|
+
}
|
|
99
|
+
flags.workspace = value;
|
|
100
|
+
return index + 1;
|
|
101
|
+
}
|
|
102
|
+
flags.workspace = consumeFlagValue(raw, index, token);
|
|
103
|
+
return index + 2;
|
|
104
|
+
}
|
|
105
|
+
if (token === "-t" || token === "--tabs") {
|
|
106
|
+
flags.forceTabs = true;
|
|
107
|
+
return index + 1;
|
|
108
|
+
}
|
|
109
|
+
if (token === "--no-tabs") {
|
|
110
|
+
flags.forceTabs = false;
|
|
111
|
+
return index + 1;
|
|
112
|
+
}
|
|
113
|
+
if (token === "--skip-secrets") {
|
|
114
|
+
flags.skipSecrets = true;
|
|
115
|
+
return index + 1;
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function validateFlagScopes(parsed: ParsedCliArgs): void {
|
|
121
|
+
const command = parsed.command;
|
|
122
|
+
if (!command) {
|
|
123
|
+
if (
|
|
124
|
+
parsed.flags.workspace ||
|
|
125
|
+
parsed.flags.forceTabs !== undefined ||
|
|
126
|
+
parsed.flags.skipSecrets
|
|
127
|
+
) {
|
|
128
|
+
throw new Error("Global flags require a command");
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (parsed.flags.workspace && !WORKSPACE_COMMANDS.has(command)) {
|
|
134
|
+
if (command === "workspace") {
|
|
135
|
+
throw new Error(
|
|
136
|
+
`-w/--workspace is not valid with workspace mutations; use \`${product().cli} workspace use <name>\` instead`,
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
throw new Error(`-w/--workspace is not valid with ${command}`);
|
|
140
|
+
}
|
|
141
|
+
if (parsed.flags.forceTabs !== undefined && !TAB_COMMANDS.has(command)) {
|
|
142
|
+
throw new Error(`--tabs/--no-tabs is not valid with ${command}`);
|
|
143
|
+
}
|
|
144
|
+
if (parsed.flags.skipSecrets && !SKIP_SECRETS_COMMANDS.has(command)) {
|
|
145
|
+
throw new Error(`--skip-secrets is not valid with ${command}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Dash-flags each mutation subcommand accepts (global flags — -w/--workspace,
|
|
150
|
+
// -t/--tabs/--no-tabs, --skip-secrets — are consumed by parseCliArgs before
|
|
151
|
+
// dispatch, and -h/--help is handled by the dispatcher). Commands not listed
|
|
152
|
+
// here are not checked.
|
|
153
|
+
const COMMAND_FLAGS: Record<string, readonly string[]> = {
|
|
154
|
+
up: [
|
|
155
|
+
"--manifest",
|
|
156
|
+
"--no-derive",
|
|
157
|
+
"-x",
|
|
158
|
+
"--exclude",
|
|
159
|
+
"-a",
|
|
160
|
+
"--all",
|
|
161
|
+
"-n",
|
|
162
|
+
"--dry-run",
|
|
163
|
+
"--plan",
|
|
164
|
+
"--pull",
|
|
165
|
+
"-A",
|
|
166
|
+
"--app",
|
|
167
|
+
],
|
|
168
|
+
down: [
|
|
169
|
+
"--manifest",
|
|
170
|
+
"--no-derive",
|
|
171
|
+
"-a",
|
|
172
|
+
"--all",
|
|
173
|
+
"-n",
|
|
174
|
+
"--dry-run",
|
|
175
|
+
"-f",
|
|
176
|
+
"--force",
|
|
177
|
+
"-A",
|
|
178
|
+
"--app",
|
|
179
|
+
],
|
|
180
|
+
restart: ["-A", "--app"],
|
|
181
|
+
logs: [],
|
|
182
|
+
setup: ["-f", "--force"],
|
|
183
|
+
sync: [],
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Unrecognized dash-args for `command` among `args`, stopping at the first
|
|
188
|
+
* `--` terminator (everything after it belongs to a child command). Returns
|
|
189
|
+
* [] when the command isn't flag-checked or every flag is known — mutation
|
|
190
|
+
* commands must NOT run when this is non-empty (a typo'd --dry-run would
|
|
191
|
+
* otherwise silently perform a real bring-up).
|
|
192
|
+
*/
|
|
193
|
+
export function unknownCommandFlags(command: string, args: string[]): string[] {
|
|
194
|
+
const allowed = COMMAND_FLAGS[command];
|
|
195
|
+
if (!allowed) return [];
|
|
196
|
+
const end = args.indexOf("--");
|
|
197
|
+
const own = end === -1 ? args : args.slice(0, end);
|
|
198
|
+
return own.filter(
|
|
199
|
+
(a) =>
|
|
200
|
+
a.startsWith("-") &&
|
|
201
|
+
!allowed.includes(a) &&
|
|
202
|
+
// `--app=<name>` is the one flag that also takes the = form.
|
|
203
|
+
!(allowed.includes("--app") && a.startsWith("--app=")),
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function parseCliArgs(raw: string[]): ParsedCliArgs {
|
|
208
|
+
const parsed: ParsedCliArgs = { args: [], flags: {} };
|
|
209
|
+
let i = 0;
|
|
210
|
+
let passthrough = false;
|
|
211
|
+
|
|
212
|
+
while (i < raw.length) {
|
|
213
|
+
const token = raw[i];
|
|
214
|
+
|
|
215
|
+
if (passthrough) {
|
|
216
|
+
parsed.args.push(token);
|
|
217
|
+
i += 1;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (token === "--") {
|
|
222
|
+
// Keep the terminator so downstream dispatch can tell den's own
|
|
223
|
+
// args from passthrough args intended for a child command.
|
|
224
|
+
passthrough = true;
|
|
225
|
+
parsed.args.push(token);
|
|
226
|
+
i += 1;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const nextIndex = applyFlag(raw, i, parsed.flags);
|
|
231
|
+
if (nextIndex !== null) {
|
|
232
|
+
i = nextIndex;
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (!parsed.command) {
|
|
237
|
+
parsed.command = token;
|
|
238
|
+
} else {
|
|
239
|
+
parsed.args.push(token);
|
|
240
|
+
}
|
|
241
|
+
i += 1;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
validateFlagScopes(parsed);
|
|
245
|
+
return parsed;
|
|
246
|
+
}
|