Skip to content

Commit 7ee8a03

Browse files
pvdzjdalton
authored andcommitted
Add --interactive flag to scan create (#461)
* Add --interactive flag to scan create * um yeah obviously
1 parent e7ae7c1 commit 7ee8a03

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

src/commands/ci/handle-ci.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export async function handleCI(): Promise<void> {
2020
committers: '',
2121
cwd: process.cwd(),
2222
defaultBranch: false,
23+
interactive: false,
2324
orgSlug,
2425
outputKind: 'json',
2526
pendingHead: true, // when true, requires branch name set, tmp false

src/commands/scan/cmd-scan-create.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ describe('socket scan create', async () => {
5757
--cwd working directory, defaults to process.cwd()
5858
--defaultBranch Set the default branch of the repository to the branch of this full-scan. Should only need to be done once, for example for the "main" or "master" branch.
5959
--help Print this help
60+
--interactive Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions, defaulting them to cancel/no.
6061
--json Output result as json
6162
--markdown Output result as markdown
6263
--pendingHead Designate this full-scan as the latest scan of a given branch. This must be set to have it show up in the dashboard.

src/commands/scan/cmd-scan-create.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ const config: CliCommandConfig = {
5656
description:
5757
'Set the default branch of the repository to the branch of this full-scan. Should only need to be done once, for example for the "main" or "master" branch.'
5858
},
59+
interactive: {
60+
type: 'boolean',
61+
default: true,
62+
description:
63+
'Allow for interactive elements, asking for input. Use --no-interactive to prevent any input questions, defaulting them to cancel/no.'
64+
},
5965
pendingHead: {
6066
type: 'boolean',
6167
default: true,
@@ -159,6 +165,7 @@ async function run(
159165
cwd: cwdOverride,
160166
defaultBranch,
161167
dryRun,
168+
interactive = true,
162169
json,
163170
markdown,
164171
pendingHead,
@@ -175,6 +182,7 @@ async function run(
175182
committers: string
176183
defaultBranch: boolean
177184
dryRun: boolean
185+
interactive: boolean
178186
json: boolean
179187
markdown: boolean
180188
pendingHead: boolean
@@ -202,7 +210,7 @@ async function run(
202210
// the command without requiring user input, as a suggestion.
203211
let updatedInput = false
204212

205-
if (!targets.length && !dryRun) {
213+
if (!targets.length && !dryRun && interactive) {
206214
const received = await suggestTarget()
207215
targets = received ?? []
208216
updatedInput = true
@@ -211,7 +219,7 @@ async function run(
211219
// If the current cwd is unknown and is used as a repo slug anyways, we will
212220
// first need to register the slug before we can use it.
213221
// Only do suggestions with an apiToken and when not in dryRun mode
214-
if (apiToken && !dryRun) {
222+
if (apiToken && !dryRun && interactive) {
215223
if (!orgSlug) {
216224
const suggestion = await suggestOrgSlug()
217225
if (suggestion) {
@@ -302,6 +310,7 @@ async function run(
302310
committers: (committers && String(committers)) || '',
303311
cwd,
304312
defaultBranch: Boolean(defaultBranch),
313+
interactive: Boolean(interactive),
305314
orgSlug,
306315
outputKind: json ? 'json' : markdown ? 'markdown' : 'text',
307316
pendingHead: Boolean(pendingHead),

src/commands/scan/handle-create-new-scan.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export async function handleCreateNewScan({
1414
committers,
1515
cwd,
1616
defaultBranch,
17+
interactive,
1718
orgSlug,
1819
outputKind,
1920
pendingHead,
@@ -30,6 +31,7 @@ export async function handleCreateNewScan({
3031
committers: string
3132
cwd: string
3233
defaultBranch: boolean
34+
interactive: boolean
3335
orgSlug: string
3436
pendingHead: boolean
3537
pullRequest: number
@@ -106,6 +108,6 @@ export async function handleCreateNewScan({
106108
process.exitCode = 1
107109
}
108110
} else {
109-
await outputCreateNewScan(data, outputKind)
111+
await outputCreateNewScan(data, outputKind, interactive)
110112
}
111113
}

src/commands/scan/output-create-new-scan.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import type { SocketSdkReturnType } from '@socketsecurity/sdk'
88

99
export async function outputCreateNewScan(
1010
data: SocketSdkReturnType<'CreateOrgFullScan'>['data'],
11-
outputKind: 'json' | 'markdown' | 'text'
11+
outputKind: 'json' | 'markdown' | 'text',
12+
interactive: boolean
1213
) {
1314
if (!data.id) {
1415
logger.fail('Did not receive a scan ID from the API...')
@@ -47,10 +48,11 @@ export async function outputCreateNewScan(
4748
logger.log(`Available at: ${link}`)
4849

4950
if (
50-
await confirm({
51+
interactive &&
52+
(await confirm({
5153
message: 'Would you like to open it in your browser?',
5254
default: false
53-
})
55+
}))
5456
) {
5557
await open(`${data.html_report_url}`)
5658
}

0 commit comments

Comments
 (0)