import yargs , { Argv , CommandModule } from 'yargs' ; process . on ( 'unhandledRejection' , ( err ) => { throw err ; } ) ; param { any } commands export default async function cli ( commands ) { let appCommands = yargs . usage ( '$0 <command>' ) ; ( appCommands as any ) . $0 = 'jss' ; for ( const cmd of Object . keys ( commands ) ) { const commandObject = commands [ cmd ] ; if ( typeof commandObject . builder === 'function' ) { appCommands = await commandObject . builder ( appCommands ) ; } if ( typeof commandObject . builder === 'object' ) { const ogBuilder = commandObject . builder ; const builderFunc = commandObject . disableStrictArgs ? ( yarrrrg ) => yarrrrg . options ( ogBuilder ) : ( yarrrrg ) => yarrrrg . options ( ogBuilder ) . strict ( ) ; commandObject . builder = builderFunc ; appCommands = appCommands . command ( commandObject ) ; } } const argv = await appCommands . demandCommand ( 1 ) . help ( ) . argv ; if ( ! argv . _ [ 0 ] ) { console . log ( 'Missing command. Use --help to see all available options.' ) ; } }