-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.ts
27 lines (24 loc) · 882 Bytes
/
index.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
import { Command, ux } from '@oclif/core';
import { generatePromptMessages } from '../prompt';
import { translate } from '../translator';
import type { CommandLine } from '../types';
export default class DefaultCommand extends Command {
static strict = false;
async run(): Promise<void> {
const userInput = this.argv.join(' ');
generatePromptMessages(userInput);
let command: CommandLine;
try {
ux.action.start('Translating your words into command line...');
command = await translate(userInput);
ux.action.stop();
this.log(`\x1b[36m\n${command.content}\n\x1b[0m`);
if (command.isDangerous) {
ux.log('\x1b[41m CAUTION \x1b[0m\x1b[31m This command is dangerous!\x1b[0m');
}
} catch (e) {
ux.action.stop('Error');
ux.error(e instanceof Error ? e.message : 'Unknown error', { exit: 500 });
}
}
}