File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,8 +4,8 @@ import { API } from './api.js';
44import { ArgumentError } from './errors/argument.error.js' ;
55import { ReferenceError } from './errors/reference.error.js' ;
66
7- export function cli ( args : string [ ] ) {
8- const program = new Command ( )
7+ function buildProgram ( ) : Command {
8+ return new Command ( )
99 . name ( 'faker' )
1010 . version ( packageJson . version )
1111 . description ( packageJson . description )
@@ -31,13 +31,23 @@ export function cli(args: string[]) {
3131 }
3232
3333 process . stdout . write ( String ( entryRef ( ) ) ) ;
34- process . exit ( 0 ) ;
3534 } ) ;
35+ }
36+
37+ export function cli ( args : string [ ] ) {
38+ try {
39+ const program = buildProgram ( ) ;
40+
41+ const hasArgs = args . length > 2 ;
42+ if ( ! hasArgs ) {
43+ program . help ( ) ;
44+ } else {
45+ program . parse ( args ) ;
46+ }
3647
37- const hasArgs = args . length > 2 ;
38- if ( ! hasArgs ) {
39- program . help ( ) ;
40- } else {
41- program . parse ( args ) ;
48+ process . exit ( 0 ) ;
49+ } catch ( error ) {
50+ process . stderr . write ( String ( error ) ) ;
51+ process . exit ( 1 ) ;
4252 }
4353}
You can’t perform that action at this time.
0 commit comments