-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathcmd-ask.mts
More file actions
93 lines (78 loc) · 2.3 KB
/
Copy pathcmd-ask.mts
File metadata and controls
93 lines (78 loc) · 2.3 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
91
92
93
import { handleAsk } from './handle-ask.mts'
import { defineFlags } from '../../meow.mts'
import { commonFlags } from '../../flags.mts'
import { meowOrExit } from '../../util/cli/with-subcommands.mjs'
import { InputError } from '../../util/error/errors.mjs'
import {
getFlagApiRequirementsOutput,
getFlagListOutput,
} from '../../util/output/formatting.mts'
import type { CliCommandContext } from '../../util/cli/with-subcommands.mjs'
import type { MeowFlags } from '../../flags.mts'
export const CMD_NAME = 'ask'
const description = 'Ask in plain English'
const hidden = false
export const cmdAsk = {
description,
hidden,
run,
}
export async function run(
argv: string[] | readonly string[],
importMeta: ImportMeta,
{ parentName }: CliCommandContext,
): Promise<void> {
const config = {
commandName: CMD_NAME,
description,
hidden,
flags: defineFlags({
...commonFlags,
execute: {
type: 'boolean',
shortFlag: 'e',
default: false,
description: 'Execute the command directly',
},
explain: {
type: 'boolean',
default: false,
description: 'Show detailed explanation',
},
}),
help: (command: string, helpConfig: { flags: MeowFlags }) => `
Usage
$ ${command} "<question>" [options]
API Token Requirements
${getFlagApiRequirementsOutput(`${parentName}:${CMD_NAME}`)}
Options
${getFlagListOutput(helpConfig.flags)}
Examples
$ ${command} "scan for vulnerabilities"
$ ${command} "is express safe to use"
$ ${command} "fix critical issues" --execute
$ ${command} "show production vulnerabilities" --explain
$ ${command} "optimize my dependencies"
Tips
- Be specific about what you want
- Mention "production" or "dev" to filter
- Use severity levels: critical, high, medium, low
- Say "dry run" to preview changes
`,
}
const cli = meowOrExit({
argv,
config,
importMeta,
parentName,
})
const query = cli.input[0]
if (!query) {
throw new InputError(
'socket ask requires a QUERY positional argument; pass a question like `socket ask "scan for vulnerabilities"`',
)
}
const execute = cli.flags['execute']
const explain = cli.flags['explain']
await handleAsk(query, { execute, explain })
}