-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathcli.mjs
More file actions
executable file
·47 lines (35 loc) · 1.2 KB
/
cli.mjs
File metadata and controls
executable file
·47 lines (35 loc) · 1.2 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
#!/usr/bin/env node
import process from 'node:process';
import { Command, Option } from 'commander';
import commands from './commands/index.mjs';
import interactive from './commands/interactive.mjs';
import { errorWrap } from './utils.mjs';
const program = new Command()
.name('@nodejs/doc-kit')
.description('CLI tool to generate the Node.js API documentation');
// Registering commands
commands.forEach(({ name, description, options, action }) => {
const cmd = program.command(name).description(description);
// Add options to the command
Object.values(options).forEach(({ flags, desc, prompt }) => {
const option = new Option(flags.join(', '), desc).default(
prompt.initialValue
);
if (prompt.required) {
option.makeOptionMandatory();
}
if (prompt.type === 'multiselect') {
option.choices(prompt.options.map(({ value }) => value));
}
cmd.addOption(option);
});
// Set the action for the command
cmd.action(errorWrap(action));
});
// Register the interactive command
program
.command('interactive')
.description('Launch guided CLI wizard')
.action(errorWrap(interactive));
// Parse and execute command-line arguments
program.parse(process.argv);