11#!/usr/bin/env node
22
3+ process . env . DEBUG = "*" ;
4+
35import chalk from "chalk" ;
46import clear from "clear" ;
57import figlet from "figlet" ;
@@ -16,25 +18,31 @@ console.log(
1618) ;
1719
1820( async ( ) => {
21+ const runCommand = async ( commandName : string ) => {
22+ try {
23+ return ( await require ( `./commands/${ commandName } ` ) ) ( ) ;
24+ } catch ( error ) {
25+ console . error ( chalk . red ( `Command "${ commandName } " not supported yet.` ) ) ;
26+ console . error ( chalk . red ( error ) ) ;
27+ program . outputHelp ( ) ;
28+ }
29+ } ;
1930 program
2031 . name ( "nitro" )
2132 . usage ( "<command>" )
2233 . version ( require ( "../package.json" ) . version )
23- . option ( "--init " , "initialise a new workspace " )
24- . option ( "--login " , "connect to your Azure " )
25- . option ( "--push" , "deploy the app to Azure" )
34+ . option ( "login, --login " , "connect to your Azure " )
35+ . option ( "init, --init " , "initialise a new workspace " )
36+ . option ( "push, --push" , "deploy the app to Azure" )
2637 . parse ( process . argv ) ;
2738
28- if ( ! process . argv . slice ( 2 ) . length ) {
29- program . outputHelp ( ) ;
30- }
39+ // use process.argv not program.argv
40+ const commandName = process . argv [ 2 ] ;
3141
32- const commandName = program . args [ 0 ] ;
33-
34- try {
35- ( await require ( `./commands/${ commandName } ` ) ) ( ) ;
36- } catch ( error ) {
37- console . error ( chalk . red ( `Command ${ commandName } not supported.` ) ) ;
42+ if ( ! process . argv . slice ( 2 ) . length || ! commandName ) {
3843 program . outputHelp ( ) ;
44+ process . exit ( 0 ) ;
3945 }
46+
47+ runCommand ( commandName . replace ( "--" , "" ) ) ;
4048} ) ( ) ;
0 commit comments