-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.ts
More file actions
71 lines (63 loc) · 2.11 KB
/
check.ts
File metadata and controls
71 lines (63 loc) · 2.11 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
/**
* @fileoverview `socket-lib check <name>` subcommand group.
*
* Routes to per-check handlers by name. Each check resolves its
* config file and runs its check; the group itself just dispatches
* and prints help.
*
* Available checks:
* primordials Drift between a repo's `primordials` destructures
* and socket-lib's userland mirror.
*
* Aliases let callers shorten the common ones:
* prim → primordials
*/
import { getDefaultLogger } from '../logger'
import { runCheckPrimordials } from './check-primordials'
const logger = getDefaultLogger()
// Each entry maps an invocation name to the canonical name. Aliases
// resolve to the same handler; help prints them grouped.
const CHECKS: ReadonlyMap<string, string> = new Map([
['primordials', 'primordials'],
['prim', 'primordials'],
])
const ALIASES: ReadonlyMap<string, readonly string[]> = new Map([
['primordials', ['prim']],
])
function printHelp(): void {
logger.log('socket-lib check — fleet-wide static-analysis checks')
logger.log('')
logger.log('Usage:')
logger.log(' socket-lib check <name> [...opts]')
logger.log('')
logger.log('Checks:')
for (const [canonical, aliases] of ALIASES) {
const aliasStr = aliases.length > 0 ? ` (alias: ${aliases.join(', ')})` : ''
logger.log(` ${canonical}${aliasStr}`)
}
logger.log('')
logger.log('Run `socket-lib check <name> --help` for check-specific options.')
}
export async function runCheck(args: readonly string[]): Promise<number> {
const name = args[0]
if (!name || name === '--help' || name === '-h') {
printHelp()
return 0
}
const canonical = CHECKS.get(name)
if (!canonical) {
logger.error(`socket-lib check: unknown check '${name}'`)
logger.error('Run `socket-lib check --help` for the list of checks.')
return 1
}
switch (canonical) {
case 'primordials':
return await runCheckPrimordials(args.slice(1))
// Unreachable; CHECKS map is exhaustive.
/* c8 ignore start */
default:
logger.error(`socket-lib check: missing handler for '${canonical}'`)
return 1
/* c8 ignore stop */
}
}