import * as program from 'commander' ; export abstract class CliApp { protected abstract _init ( ) ; private _did_exec_cmd = false ; protected action ( func ) { let newfunc = ( ... args ) => { this . _did_exec_cmd = true ; this . beforeCommand . apply ( this ) ; func . apply ( this , args ) ; this . afterCommand . apply ( this ) ; } ; return newfunc ; } protected fix ( arg1 , arg2 ) { if ( typeof arg1 != "undefined" && arg2 && arg2 . length > 0 ) { return [ arg1 ] . concat ( arg2 ) ; } else if ( ! ! arg1 ) { return [ arg1 ] ; } return [ ] ; } protected beforeCommand ( ) { } protected afterCommand ( ) { } public main ( ) { this . _init ( ) ; try { program . parse ( process . argv ) ; if ( ! this . _did_exec_cmd ) { program . help ( ) ; } } catch ( e ) { if ( program . verbose ) { console . log ( e ) ; } else { console . log ( e . message ) ; } } } }