Skip to content

Commit c7803c5

Browse files
committed
Move dryRun check to before login check
1 parent 655d2a4 commit c7803c5

20 files changed

+40
-61
lines changed

src/commands/analytics/cmd-analytics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,15 @@ async function run(
9393
return
9494
}
9595

96+
if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now')
97+
9698
const apiToken = getDefaultToken()
9799
if (!apiToken) {
98100
throw new AuthError(
99101
'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API token.'
100102
)
101103
}
102104

103-
if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now')
104-
105105
return await displayAnalytics({
106106
apiToken,
107107
scope,

src/commands/audit-log/cmd-audit-log.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ async function run(
7676
return
7777
}
7878

79+
if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now')
80+
7981
const apiToken = getDefaultToken()
8082
if (!apiToken) {
8183
throw new AuthError(
8284
'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.'
8385
)
8486
}
8587

86-
if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now')
87-
8888
await getAuditLog({
8989
apiToken,
9090
orgSlug,

src/commands/diff-scan/cmd-diff-scan-get.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ async function run(
8585
return
8686
}
8787

88+
if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now')
89+
8890
const apiToken = getDefaultToken()
8991
if (!apiToken) {
9092
throw new AuthError(
9193
'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.'
9294
)
9395
}
9496

95-
if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now')
96-
9797
await getDiffScan(
9898
{
9999
outputJson: Boolean(cli.flags['json']),

src/commands/login/cmd-login.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,16 @@ async function run(
5656
parentName
5757
})
5858

59-
const isDryRun = cli.flags['dryRun']
59+
let apiBaseUrl = cli.flags['apiBaseUrl'] as string | undefined
60+
let apiProxy = cli.flags['apiProxy'] as string | undefined
6061

61-
if (!isInteractive() && !isDryRun) {
62+
if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now')
63+
64+
if (!isInteractive()) {
6265
throw new InputError(
6366
'Cannot prompt for credentials in a non-interactive shell'
6467
)
6568
}
6669

67-
let apiBaseUrl = cli.flags['apiBaseUrl'] as string | undefined
68-
let apiProxy = cli.flags['apiProxy'] as string | undefined
69-
70-
if (isDryRun) return console.log('[DryRun] Bailing now')
71-
7270
await attemptLogin(apiBaseUrl, apiProxy)
7371
}

src/commands/manifest/cmd-manifest-auto.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ async function run(
7373
if (verbose) {
7474
subArgs.push('--verbose')
7575
}
76+
7677
const dir = cwd
78+
7779
if (existsSync(path.join(dir, 'build.sbt'))) {
7880
console.log(
7981
'Detected a Scala sbt build, running default Scala generator...'
@@ -88,6 +90,7 @@ async function run(
8890
await cmdManifestScala.run(subArgs, importMeta, { parentName })
8991
return
9092
}
93+
9194
if (existsSync(path.join(dir, 'gradlew'))) {
9295
console.log('Detected a gradle build, running default gradle generator...')
9396
if (cwd) {
@@ -100,6 +103,7 @@ async function run(
100103
await cmdManifestGradle.run(subArgs, importMeta, { parentName })
101104
return
102105
}
106+
103107
// Show new help screen and exit.
104108
meow(
105109
`

src/commands/manifest/cmd-manifest-kotlin.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import path from 'node:path'
22

33
import colors from 'yoctocolors-cjs'
44

5-
import { Spinner } from '@socketsecurity/registry/lib/spinner'
6-
75
import { convertGradleToMaven } from './convert_gradle_to_maven.ts'
86
import { commonFlags } from '../../flags.ts'
97
import { meowOrExit } from '../../utils/meow-with-subcommands'
@@ -149,16 +147,6 @@ async function run(
149147
out = '-'
150148
}
151149

152-
// TODO: I'm not sure it's feasible to parse source file from stdin. We could try, store contents in a file in some folder, target that folder... what would the file name be?
153-
if (target === '-') {
154-
new Spinner()
155-
.start('Parsing...')
156-
.error(
157-
`Failure: Currently source code from stdin is not supported. See \`${parentName} ${config.commandName} --help\` for details.`
158-
)
159-
process.exit(1)
160-
}
161-
162150
if (verbose) {
163151
console.group()
164152
console.log('- target:', target)

src/commands/manifest/cmd-manifest-scala.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import colors from 'yoctocolors-cjs'
22

3-
import { Spinner } from '@socketsecurity/registry/lib/spinner'
4-
53
import { convertSbtToMaven } from './convert_sbt_to_maven.ts'
64
import { commonFlags } from '../../flags.ts'
75
import { meowOrExit } from '../../utils/meow-with-subcommands'
@@ -146,16 +144,6 @@ async function run(
146144
console.groupEnd()
147145
}
148146

149-
// TODO: we can make `-` (accept from stdin) work by storing it into /tmp
150-
if (target === '-') {
151-
new Spinner()
152-
.start('Parsing...')
153-
.error(
154-
`Failure: Currently source code from stdin is not supported. See \`${parentName} ${config.commandName} --help\` for details.`
155-
)
156-
process.exit(1)
157-
}
158-
159147
let sbtOpts: Array<string> = []
160148
if (cli.flags['sbtOpts']) {
161149
sbtOpts = (cli.flags['sbtOpts'] as string)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ async function run(
8989
return
9090
}
9191

92+
if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now')
93+
9294
const apiToken = getDefaultToken()
9395
if (!apiToken) {
9496
throw new AuthError(
9597
'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.'
9698
)
9799
}
98100

99-
if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now')
100-
101101
await createRepo({
102102
outputJson: Boolean(cli.flags['json']),
103103
outputMarkdown: Boolean(cli.flags['markdown']),

src/commands/repos/cmd-repos-del.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ async function run(
5858
return
5959
}
6060

61+
if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now')
62+
6163
const apiToken = getDefaultToken()
6264
if (!apiToken) {
6365
throw new AuthError(
6466
'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.'
6567
)
6668
}
6769

68-
if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now')
69-
7070
await deleteRepo(orgSlug, repoName, apiToken)
7171
}

src/commands/repos/cmd-repos-list.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ async function run(
8181
return
8282
}
8383

84+
if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now')
85+
8486
const apiToken = getDefaultToken()
8587
if (!apiToken) {
8688
throw new AuthError(
8789
'User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.'
8890
)
8991
}
9092

91-
if (cli.flags['dryRun']) return console.log('[DryRun] Bailing now')
92-
9393
await listRepos({
9494
apiToken,
9595
outputJson: Boolean(cli.flags['json']),

0 commit comments

Comments
 (0)