@cantinasecurity/apex-cli 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/args.js +6 -0
- package/dist/commands.js +3 -3
- package/dist/session.js +20 -7
- package/package.json +1 -1
package/dist/args.js
CHANGED
|
@@ -41,6 +41,12 @@ export function isJsonMode(flags) {
|
|
|
41
41
|
export function isNonInteractive(flags) {
|
|
42
42
|
return flags["non-interactive"] === true;
|
|
43
43
|
}
|
|
44
|
+
export function canPromptInteractively(flags) {
|
|
45
|
+
return (!isJsonMode(flags) &&
|
|
46
|
+
!isNonInteractive(flags) &&
|
|
47
|
+
process.stdin.isTTY === true &&
|
|
48
|
+
process.stdout.isTTY === true);
|
|
49
|
+
}
|
|
44
50
|
export function getFlagString(flags, key) {
|
|
45
51
|
const value = flags[key];
|
|
46
52
|
return typeof value === "string" && value.trim().length > 0 ? value.trim() : null;
|
package/dist/commands.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getFlagList, getFlagString, isJsonMode,
|
|
1
|
+
import { canPromptInteractively, getFlagList, getFlagString, isJsonMode, } from "./args.js";
|
|
2
2
|
import { logout } from "./auth.js";
|
|
3
3
|
import { ApiError } from "./api-client.js";
|
|
4
4
|
import { openInBrowser } from "./browser.js";
|
|
@@ -341,7 +341,7 @@ async function maybePersistFindingSelectionBinding(params) {
|
|
|
341
341
|
return nextBinding;
|
|
342
342
|
}
|
|
343
343
|
function canPromptForConfirmation(flags) {
|
|
344
|
-
return
|
|
344
|
+
return canPromptInteractively(flags);
|
|
345
345
|
}
|
|
346
346
|
async function findFallbackActiveScan(client, binding) {
|
|
347
347
|
if (!binding?.lastScanId) {
|
|
@@ -572,7 +572,7 @@ export async function commandScan(client, cwd, flags) {
|
|
|
572
572
|
throw new Error("Workspace resolution did not return a workspaceId.");
|
|
573
573
|
}
|
|
574
574
|
if (legacyResolve.missing.length > 0) {
|
|
575
|
-
if (
|
|
575
|
+
if (!canPromptInteractively(flags)) {
|
|
576
576
|
throw new Error(`PR scans require connected provider access for ${formatMissingProviderConnections(legacyResolve.missing)}. Re-run interactively or pre-connect providers.`);
|
|
577
577
|
}
|
|
578
578
|
await remediateMissingConnections(legacyResolve.missing, flags);
|
package/dist/session.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import { getFlagList, getFlagString, isJsonMode,
|
|
2
|
+
import { canPromptInteractively, getFlagList, getFlagString, isJsonMode, } from "./args.js";
|
|
3
3
|
import { login } from "./auth.js";
|
|
4
4
|
import { ApiError } from "./api-client.js";
|
|
5
5
|
import { openInBrowser } from "./browser.js";
|
|
@@ -37,10 +37,13 @@ export async function chooseCompany(me, flags, binding) {
|
|
|
37
37
|
throw new Error(`Unknown company: ${requested}`);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
if (me.companies.length === 0) {
|
|
41
|
+
throw new Error("No Apex companies are available for this account.");
|
|
42
|
+
}
|
|
40
43
|
if (me.companies.length === 1) {
|
|
41
44
|
return me.companies[0];
|
|
42
45
|
}
|
|
43
|
-
if (
|
|
46
|
+
if (!canPromptInteractively(flags)) {
|
|
44
47
|
throw new Error("Multiple companies available. Re-run with --company <id-or-handle>.");
|
|
45
48
|
}
|
|
46
49
|
const selected = await chooseOne("Select the Apex company to use for this directory:", me.companies.map((company) => ({
|
|
@@ -60,12 +63,21 @@ async function chooseWorkspaceName(cwd, flags, binding) {
|
|
|
60
63
|
return binding.workspaceName;
|
|
61
64
|
}
|
|
62
65
|
const suggested = path.basename(cwd);
|
|
63
|
-
if (
|
|
66
|
+
if (!canPromptInteractively(flags)) {
|
|
64
67
|
return suggested;
|
|
65
68
|
}
|
|
66
69
|
const chosen = await promptText("Workspace name to use in Apex for this directory (press Enter to use the current folder name)", suggested);
|
|
67
70
|
return chosen.trim().length > 0 ? chosen.trim() : suggested;
|
|
68
71
|
}
|
|
72
|
+
function selectBindingForWorkspaceName(flags, binding, workspaceName) {
|
|
73
|
+
const explicit = getFlagString(flags, "workspace-name");
|
|
74
|
+
if (!explicit || !binding) {
|
|
75
|
+
return binding;
|
|
76
|
+
}
|
|
77
|
+
return binding.workspaceName.trim().toLowerCase() === workspaceName.trim().toLowerCase()
|
|
78
|
+
? binding
|
|
79
|
+
: null;
|
|
80
|
+
}
|
|
69
81
|
function getSourceMode(flags) {
|
|
70
82
|
const value = getFlagString(flags, "source-mode");
|
|
71
83
|
return value === "remote" || value === "local" ? value : "auto";
|
|
@@ -127,9 +139,10 @@ export async function resolveWorkspace(client, cwd, me, flags) {
|
|
|
127
139
|
return resolveWorkspaceSelection(client, selection);
|
|
128
140
|
}
|
|
129
141
|
export async function selectWorkspaceTarget(cwd, me, flags) {
|
|
130
|
-
const
|
|
131
|
-
const company = await chooseCompany(me, flags,
|
|
132
|
-
const workspaceName = await chooseWorkspaceName(cwd, flags,
|
|
142
|
+
const loadedBinding = await loadWorkspaceBinding(cwd);
|
|
143
|
+
const company = await chooseCompany(me, flags, loadedBinding);
|
|
144
|
+
const workspaceName = await chooseWorkspaceName(cwd, flags, loadedBinding);
|
|
145
|
+
const binding = selectBindingForWorkspaceName(flags, loadedBinding, workspaceName);
|
|
133
146
|
const sourceSelection = getFlagList(flags, "repo");
|
|
134
147
|
const discovered = await discoverSources(cwd, sourceSelection);
|
|
135
148
|
if (discovered.sources.length === 0) {
|
|
@@ -218,7 +231,7 @@ export async function remediateMissingConnections(missing, flags) {
|
|
|
218
231
|
if (missing.length === 0) {
|
|
219
232
|
return;
|
|
220
233
|
}
|
|
221
|
-
if (
|
|
234
|
+
if (!canPromptInteractively(flags)) {
|
|
222
235
|
throw new Error("Missing provider connections. Re-run interactively or pre-connect providers.");
|
|
223
236
|
}
|
|
224
237
|
for (const item of missing) {
|