Skip to content

Commit c479c95

Browse files
committed
improvements
1 parent 481730f commit c479c95

File tree

5 files changed

+37
-40
lines changed

5 files changed

+37
-40
lines changed

lib/commands/fullscans/create.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import ora from 'ora'
1010
import { ErrorWithCause } from 'pony-cause'
1111

1212
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
13-
import { InputError } from '../../utils/errors.js'
1413
import { prepareFlags } from '../../utils/flags.js'
1514
import { printFlagList } from '../../utils/formatting.js'
1615
import { createDebugLogger } from '../../utils/misc.js'
@@ -126,7 +125,7 @@ async function setupCommand (name, description, argv, importMeta) {
126125
${printFlagList(flags, 6)}
127126
128127
Examples
129-
$ ${name} --org=FakeOrg --repo=test-repo --branch=main --tmp=true ./package.json
128+
$ ${name} --org=FakeOrg --repo=test-repo --branch=main ./package.json
130129
`, {
131130
argv,
132131
description,
@@ -146,16 +145,12 @@ async function setupCommand (name, description, argv, importMeta) {
146145
pullRequest
147146
} = cli.flags
148147

149-
if (!repoName) {
150-
throw new InputError('Please provide a repository name')
151-
}
152-
153148
if (!cli.input[0]) {
154149
cli.showHelp()
155150
return
156151
}
157152

158-
const orgSlug = cli.input[0] || ''
153+
const [orgSlug = ''] = cli.input
159154

160155
const cwd = process.cwd()
161156
const socketSdk = await setupSdk()
@@ -171,6 +166,15 @@ async function setupCommand (name, description, argv, importMeta) {
171166
const debugLog = createDebugLogger(false)
172167
const packagePaths = await getPackageFilesFullScans(cwd, cli.input, supportedFiles, debugLog)
173168

169+
if (!repoName || !branchName || !packagePaths.length) {
170+
console.error(`${chalk.bgRed('Input error')}: Please provide the required fields: \n
171+
- Repository name using --repo, \n
172+
- Branch name using --branch \n
173+
- At least one file path (e.g. ./package.json) .\n`)
174+
cli.showHelp()
175+
return
176+
}
177+
174178
return {
175179
orgSlug,
176180
repoName,

lib/commands/fullscans/delete.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable no-console */
22

3+
import chalk from 'chalk'
34
import meow from 'meow'
45
import ora from 'ora'
56

67
import { outputFlags } from '../../flags/index.js'
78
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
8-
import { InputError } from '../../utils/errors.js'
99
import { printFlagList } from '../../utils/formatting.js'
1010
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
1111

@@ -68,14 +68,12 @@ function setupCommand (name, description, argv, importMeta) {
6868
} = cli.flags
6969

7070
if (cli.input.length < 2) {
71-
throw new InputError(`Please specify an organization slug and a scan ID. \n
72-
Example:
73-
socket scan del FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
74-
`)
71+
console.error(`${chalk.bgRed('Input error')}: Please specify an organization slug and a scan ID.\n`)
72+
cli.showHelp()
73+
return
7574
}
7675

77-
const orgSlug = cli.input[0] || ''
78-
const fullScanId = cli.input[1] || ''
76+
const [orgSlug = '', fullScanId = ''] = cli.input
7977

8078
return {
8179
outputJson,

lib/commands/fullscans/list.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import ora from 'ora'
88

99
import { outputFlags } from '../../flags/index.js'
1010
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
11-
import { InputError } from '../../utils/errors.js'
1211
import { prepareFlags } from '../../utils/flags.js'
1312
import { printFlagList } from '../../utils/formatting.js'
1413
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
@@ -76,10 +75,10 @@ const listFullScanFlags = prepareFlags({
7675
* @property {string} orgSlug
7776
* @property {string} sort
7877
* @property {string} direction
79-
* @property {number} perPage
78+
* @property {number} per_page
8079
* @property {number} page
81-
* @property {string} fromTime
82-
* @property {string} untilTime
80+
* @property {string} from_time
81+
* @property {string} until_time
8382
*/
8483

8584
/**
@@ -123,24 +122,23 @@ function setupCommand (name, description, argv, importMeta) {
123122
} = cli.flags
124123

125124
if (!cli.input[0]) {
126-
throw new InputError(`Please specify an organization slug. \n
127-
Example:
128-
socket scan list FakeOrg
129-
`)
125+
console.error(`${chalk.bgRed('Input error')}: Please specify an organization slug.\n`)
126+
cli.showHelp()
127+
return
130128
}
131129

132-
const orgSlug = cli.input[0] || ''
130+
const [orgSlug = ''] = cli.input
133131

134132
return {
135133
outputJson,
136134
outputMarkdown,
137135
orgSlug,
138136
sort,
139137
direction,
140-
perPage,
138+
per_page: perPage,
141139
page,
142-
fromTime,
143-
untilTime
140+
from_time: fromTime,
141+
until_time: untilTime
144142
}
145143
}
146144

@@ -157,6 +155,7 @@ socket scan list FakeOrg
157155
*/
158156
async function listOrgFullScan (orgSlug, input, spinner) {
159157
const socketSdk = await setupSdk(getDefaultKey())
158+
console.log(input)
160159
// @ts-ignore
161160
const result = await handleApiCall(socketSdk.getOrgFullScanList(orgSlug, input), 'Listing scans')
162161

@@ -180,7 +179,7 @@ async function listOrgFullScan (orgSlug, input, spinner) {
180179
return {
181180
id: d.id,
182181
report_url: chalk.underline(`${d.html_report_url}`),
183-
created_at: d.created_at ? new Date(d.created_at).toLocaleDateString('en-us', { year: 'numeric', month: 'short', day: 'numeric' }) : '',
182+
created_at: d.created_at ? new Date(d.created_at).toLocaleDateString('en-us', { year: 'numeric', month: 'numeric', day: 'numeric' }) : '',
184183
branch: d.branch
185184
}
186185
})

lib/commands/fullscans/metadata.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable no-console */
22

3+
import chalk from 'chalk'
34
import meow from 'meow'
45
import ora from 'ora'
56

67
import { outputFlags } from '../../flags/index.js'
78
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
8-
import { InputError } from '../../utils/errors.js'
99
import { printFlagList } from '../../utils/formatting.js'
1010
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
1111

@@ -68,10 +68,9 @@ function setupCommand (name, description, argv, importMeta) {
6868
} = cli.flags
6969

7070
if (cli.input.length < 2) {
71-
throw new InputError(`Please specify an organization slug and a scan id. \n
72-
Example:
73-
socket scan metadata FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
74-
`)
71+
console.error(`${chalk.bgRed('Input error')}: Please specify an organization slug and a scan ID.\n`)
72+
cli.showHelp()
73+
return
7574
}
7675

7776
const [orgSlug = '', scanID = ''] = cli.input

lib/commands/fullscans/stream.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* eslint-disable no-console */
22

3+
import chalk from 'chalk'
34
import meow from 'meow'
45
import ora from 'ora'
56

67
import { outputFlags } from '../../flags/index.js'
78
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api-helpers.js'
8-
import { InputError } from '../../utils/errors.js'
99
import { printFlagList } from '../../utils/formatting.js'
1010
import { getDefaultKey, setupSdk } from '../../utils/sdk.js'
1111

@@ -69,15 +69,12 @@ function setupCommand (name, description, argv, importMeta) {
6969
} = cli.flags
7070

7171
if (cli.input.length < 2) {
72-
throw new InputError(`Please specify an organization slug and a scan ID.\n
73-
Example:
74-
socket scan stream FakeOrg 000aaaa1-0000-0a0a-00a0-00a0000000a0
75-
`)
72+
console.error(`${chalk.bgRed('Input error')}: Please specify an organization slug and a scan ID.\n`)
73+
cli.showHelp()
74+
return
7675
}
7776

78-
const orgSlug = cli.input[0] || ''
79-
const fullScanId = cli.input[1] || ''
80-
const file = cli.input[2]
77+
const [orgSlug = '', fullScanId = '', file] = cli.input
8178

8279
return {
8380
outputJson,

0 commit comments

Comments
 (0)