Skip to content

Commit 290b1c5

Browse files
committed
Catch errors better and fix async yargs
1 parent 9144d42 commit 290b1c5

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

src/cli.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import fs from 'fs';
33
import path from 'path';
44
import { serve, build, init } from './main';
55
import chalk from 'chalk';
6+
import { printError } from './utils';
67
import { version } from '../package.json';
78

89
yargs.usage(
@@ -138,17 +139,18 @@ export const createCommands = (yargs) => {
138139
},
139140
})
140141
.recommendCommands()
142+
.strict()
141143
}
142144

143-
export const argsToOpts = () => {
144-
const { argv } = createCommands(yargs);
145-
const result = { ...argv };
146-
delete result.$0;
147-
148-
return result;
145+
export const argsToOpts = async () => {
146+
return await createCommands(yargs).parse();
149147
};
150148

151-
export default (opts = {}) => {
152-
let options = argsToOpts();
153-
if (!options._.length) yargs.showHelp();
149+
export default async (opts = {}) => {
150+
try {
151+
let options = await argsToOpts();
152+
if (!options._.length) yargs.showHelp();
153+
} catch (error) {
154+
printError((error.stack || error).toString())
155+
}
154156
}

0 commit comments

Comments
 (0)