-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathcmd-scan-setup.mts
More file actions
88 lines (73 loc) · 2.68 KB
/
Copy pathcmd-scan-setup.mts
File metadata and controls
88 lines (73 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import path from 'node:path'
import { handleScanConfig } from './handle-scan-config.mts'
import { SOCKET_JSON } from '../../constants/paths.mts'
import { outputDryRunWrite } from '../../util/dry-run/output.mts'
import { defineFlags } from '../../meow.mts'
import { commonFlags } from '../../flags.mts'
import { meowOrExit } from '../../util/cli/with-subcommands.mjs'
import { getFlagListOutput } from '../../util/output/formatting.mts'
import type { CliCommandContext } from '../../util/cli/with-subcommands.mjs'
import type { MeowFlags } from '../../flags.mts'
const config = {
commandName: 'setup',
description:
'Start interactive configurator to customize default flag values for `socket scan` in this dir',
flags: defineFlags({
...commonFlags,
defaultOnReadError: {
type: 'boolean',
description: `If reading the ${SOCKET_JSON} fails, just use a default config? Warning: This might override the existing json file!`,
},
}),
help: (command: string, helpConfig: { flags: MeowFlags }) => `
Usage
$ ${command} [options] [CWD=.]
Options
${getFlagListOutput(helpConfig.flags)}
Interactive configurator to create a local json file in the target directory
that helps to set flag defaults for \`socket scan create\`.
This helps to configure the (Socket reported) repo and branch names, as well
as which branch name is the "default branch" (main, master, etc). This way
you don't have to specify these flags when creating a scan in this dir.
This generated configuration file will only be used locally by the CLI. You
can commit it to the repo (useful for collaboration) or choose to add it to
your .gitignore all the same. Only this CLI will use it.
Examples
$ ${command}
$ ${command} ./proj
`,
hidden: false,
}
export const cmdScanSetup = {
description: config.description,
hidden: config.hidden,
run,
}
export async function run(
argv: string[] | readonly string[],
importMeta: ImportMeta,
{ parentName }: CliCommandContext,
): Promise<void> {
const cli = meowOrExit({
argv,
config,
parentName,
importMeta,
})
const dryRun = cli.flags['dryRun']
const { defaultOnReadError = false } = cli.flags
let { 0: cwd = '.' } = cli.input
// Note: path.resolve vs .join:
// If given path is absolute then cwd should not affect it.
cwd = path.resolve(process.cwd(), cwd)
if (dryRun) {
const socketJsonPath = path.join(cwd, SOCKET_JSON)
outputDryRunWrite(socketJsonPath, 'create or update scan configuration', [
'Set default repository name',
'Set default branch name',
'Configure scan options',
])
return
}
await handleScanConfig(cwd, defaultOnReadError)
}