-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcmd-organization-list.ts
72 lines (60 loc) · 1.86 KB
/
cmd-organization-list.ts
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
import { stripIndents } from 'common-tags'
import colors from 'yoctocolors-cjs'
import { logger } from '@socketsecurity/registry/lib/logger'
import { handleOrganizationList } from './handle-organization-list'
import constants from '../../constants'
import { commonFlags, outputFlags } from '../../flags'
import { meowOrExit } from '../../utils/meow-with-subcommands'
import { getFlagListOutput } from '../../utils/output-formatting'
import type { CliCommandConfig } from '../../utils/meow-with-subcommands'
const { DRY_RUN_BAIL_TEXT } = constants
const config: CliCommandConfig = {
commandName: 'list',
description: 'List organizations associated with the API key used',
hidden: false,
flags: {
...commonFlags,
...outputFlags
},
help: (command, _config) => `
Usage
$ ${command}
Options
${getFlagListOutput(config.flags, 6)}
`
}
export const cmdOrganizationList = {
description: config.description,
hidden: config.hidden,
run
}
async function run(
argv: string[] | readonly string[],
importMeta: ImportMeta,
{ parentName }: { parentName: string }
): Promise<void> {
const cli = meowOrExit({
argv,
config,
importMeta,
parentName
})
const json = Boolean(cli.flags['json'])
const markdown = Boolean(cli.flags['markdown'])
if (json && markdown) {
// Use exit status of 2 to indicate incorrect usage, generally invalid
// options or missing arguments.
// https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html
process.exitCode = 2
logger.fail(stripIndents`
${colors.bgRed(colors.white('Input error'))}: Please provide the required fields:
- The json and markdown flags cannot be both set, pick one
`)
return
}
if (cli.flags['dryRun']) {
logger.log(DRY_RUN_BAIL_TEXT)
return
}
await handleOrganizationList(json ? 'json' : markdown ? 'markdown' : 'text')
}