Skip to content

Commit

Permalink
Catch errors better and fix async yargs
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Feb 3, 2023
1 parent 9144d42 commit 290b1c5
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from 'fs';
import path from 'path';
import { serve, build, init } from './main';
import chalk from 'chalk';
import { printError } from './utils';
import { version } from '../package.json';

yargs.usage(
Expand Down Expand Up @@ -138,17 +139,18 @@ export const createCommands = (yargs) => {
},
})
.recommendCommands()
.strict()
}

export const argsToOpts = () => {
const { argv } = createCommands(yargs);
const result = { ...argv };
delete result.$0;

return result;
export const argsToOpts = async () => {
return await createCommands(yargs).parse();
};

export default (opts = {}) => {
let options = argsToOpts();
if (!options._.length) yargs.showHelp();
export default async (opts = {}) => {
try {
let options = await argsToOpts();
if (!options._.length) yargs.showHelp();
} catch (error) {
printError((error.stack || error).toString())
}
}

0 comments on commit 290b1c5

Please sign in to comment.