-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcmd-organization-quota.mts
More file actions
90 lines (76 loc) · 2.08 KB
/
cmd-organization-quota.mts
File metadata and controls
90 lines (76 loc) · 2.08 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
89
90
import { handleQuota } from './handle-quota.mts'
import { outputDryRunFetch } from '../../utils/dry-run/output.mts'
import { commonFlags, outputFlags } from '../../flags.mts'
import { meowOrExit } from '../../utils/cli/with-subcommands.mjs'
import { getFlagListOutput } from '../../utils/output/formatting.mts'
import { getOutputKind } from '../../utils/output/mode.mjs'
import { hasDefaultApiToken } from '../../utils/socket/sdk.mjs'
import { checkCommandInput } from '../../utils/validation/check-input.mts'
import type {
CliCommandConfig,
CliCommandContext,
} from '../../utils/cli/with-subcommands.mjs'
const config: CliCommandConfig = {
commandName: 'quota',
description:
'Show remaining Socket API quota for the current token, plus refresh window',
hidden: false,
flags: {
...commonFlags,
...outputFlags,
},
help: (command, _config) => `
Usage
$ ${command} [options]
Options
${getFlagListOutput(config.flags)}
Examples
$ ${command}
$ ${command} --json
`,
}
export const cmdOrganizationQuota = {
description: config.description,
hidden: config.hidden,
run,
}
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 json = Boolean(cli.flags['json'])
const markdown = Boolean(cli.flags['markdown'])
const hasApiToken = hasDefaultApiToken()
const outputKind = getOutputKind(json, markdown)
const wasValidInput = checkCommandInput(
outputKind,
{
nook: true,
test: !json || !markdown,
message: 'The json and markdown flags cannot be both set, pick one',
fail: 'omit one',
},
{
nook: true,
test: hasApiToken,
message: 'This command requires a Socket API token for access',
fail: 'try `socket login`',
},
)
if (!wasValidInput) {
return
}
if (dryRun) {
outputDryRunFetch('organization quota')
return
}
await handleQuota(outputKind)
}