11import { Command } from 'commander' ;
22import { fileURLToPath } from 'url' ;
3+ import { hideBin } from 'yargs/helpers' ;
4+ import yargs from 'yargs/yargs' ;
35import inquirer from 'inquirer' ;
46import ccx from 'conceal-api' ;
57import path from 'path' ;
@@ -18,18 +20,36 @@ let config = {
1820 timeout : 5000
1921}
2022
23+
2124// check if we have config.json present in same dir
2225if ( fs . existsSync ( path . join ( __dirname , 'config.json' ) ) ) {
2326 config = JSON . parse ( fs . readFileSync ( path . join ( __dirname , 'config.json' ) , 'utf8' ) ) ;
2427}
2528
29+ // parse arguments and options
30+ const argv = yargs ( hideBin ( process . argv ) ) . argv
31+
32+ if ( argv . dh ) { config . daemonHost = argv . dh ; }
33+ if ( argv . dp ) { config . daemonRpcPort = argv . dp ; }
34+ if ( argv . wh ) { config . walletHost = argv . wh ; }
35+ if ( argv . wp ) { config . walletRpcPort = argv . wp ; }
36+
37+ if ( argv . daemonHost ) { config . daemonHost = argv . daemonHost ; }
38+ if ( argv . daemonPort ) { config . daemonRpcPort = argv . daemonPort ; }
39+ if ( argv . walletdHost ) { config . daemonHost = argv . walletdHost ; }
40+ if ( argv . walletdPort ) { config . walletRpcPort = argv . walletdPort ; }
41+
2642// create the api with the config
2743const ccxApi = new ccx ( config ) ;
2844
2945// creating tool
3046program
3147 . name ( "conceal-api-demo" )
3248 . description ( "A CLI demo for conceal api" )
49+ . option ( '--dh, --daemon-host <type>' , 'Daemon Host (URL)' )
50+ . option ( '--dp, --daemon-port <type>' , 'Daemon Port (Number)' )
51+ . option ( '--wh, --walletd-host <type>' , 'Walletd Host (URL)' )
52+ . option ( '--wp, --walletd-port <type>' , 'Walletd Host (Number)' )
3353 . version ( "1.0.0" ) ;
3454
3555// ****************************************************
@@ -899,4 +919,4 @@ daemon
899919 } ) ;
900920
901921
902- program . parse ( ) ;
922+ program . parse ( process . argv ) ;
0 commit comments