1
1
import { Command } from 'commander' ;
2
2
import { fileURLToPath } from 'url' ;
3
+ import { hideBin } from 'yargs/helpers' ;
4
+ import yargs from 'yargs/yargs' ;
3
5
import inquirer from 'inquirer' ;
4
6
import ccx from 'conceal-api' ;
5
7
import path from 'path' ;
@@ -18,18 +20,36 @@ let config = {
18
20
timeout : 5000
19
21
}
20
22
23
+
21
24
// check if we have config.json present in same dir
22
25
if ( fs . existsSync ( path . join ( __dirname , 'config.json' ) ) ) {
23
26
config = JSON . parse ( fs . readFileSync ( path . join ( __dirname , 'config.json' ) , 'utf8' ) ) ;
24
27
}
25
28
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
+
26
42
// create the api with the config
27
43
const ccxApi = new ccx ( config ) ;
28
44
29
45
// creating tool
30
46
program
31
47
. name ( "conceal-api-demo" )
32
48
. 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)' )
33
53
. version ( "1.0.0" ) ;
34
54
35
55
// ****************************************************
@@ -899,4 +919,4 @@ daemon
899
919
} ) ;
900
920
901
921
902
- program . parse ( ) ;
922
+ program . parse ( process . argv ) ;
0 commit comments