23
23
// Also we need `esm` package to handle `ES imports`
24
24
const program = require ( 'commander' )
25
25
26
- require = require ( 'esm' ) ( module /*, options*/ ) //use to handle es6 import/export
27
- const utils = require ( './utils/index' )
28
- const { Account } = require ( './commands' )
26
+ const requireEsm = require ( 'esm' ) ( module /*, options */ ) // use to handle es6 import/export
27
+ const utils = requireEsm ( './utils/index' )
28
+ const { Account } = requireEsm ( './commands' )
29
29
30
30
// ## Initialize `options`
31
31
program
@@ -54,8 +54,7 @@ program
54
54
. option ( '-T, --ttl [ttl]' , 'Validity of the spend transaction in number of blocks (default forever)' , utils . constant . TX_TTL )
55
55
. option ( '-N, --nonce [nonce]' , 'Override the nonce that the transaction is going to be sent with' )
56
56
. option ( '-D, --denomination [denomination]' , 'Denomination of amount' , utils . constant . DENOMINATION )
57
- . action ( async ( walletPath , receiverIdOrName , amount , ...arguments ) => await Account . spend ( walletPath , receiverIdOrName , amount , utils . cli . getCmdFromArguments ( arguments ) ) )
58
-
57
+ . action ( async ( walletPath , receiverIdOrName , amount , ...args ) => await Account . spend ( walletPath , receiverIdOrName , amount , utils . cli . getCmdFromArguments ( args ) ) )
59
58
60
59
// ## Initialize `transfer` command
61
60
//
@@ -75,8 +74,7 @@ program
75
74
. option ( '-T, --ttl [ttl]' , 'Validity of the spend transaction in number of blocks (default forever)' , utils . constant . TX_TTL )
76
75
. option ( '-N, --nonce [nonce]' , 'Override the nonce that the transaction is going to be sent with' )
77
76
. option ( '-D, --denomination [denomination]' , 'Denomination of amount' , utils . constant . DENOMINATION )
78
- . action ( async ( walletPath , receiver , percentage , ...arguments ) => await Account . transferFunds ( walletPath , receiver , percentage , utils . cli . getCmdFromArguments ( arguments ) ) )
79
-
77
+ . action ( async ( walletPath , receiver , percentage , ...args ) => await Account . transferFunds ( walletPath , receiver , percentage , utils . cli . getCmdFromArguments ( args ) ) )
80
78
81
79
// ## Initialize `sign` command
82
80
//
@@ -87,8 +85,7 @@ program
87
85
. command ( 'sign <wallet_path> <tx>' )
88
86
. option ( '--networkId [networkId]' , 'Network id (default: ae_mainnet)' )
89
87
. description ( 'Create a transaction to another wallet' )
90
- . action ( async ( walletPath , tx , ...arguments ) => await Account . sign ( walletPath , tx , utils . cli . getCmdFromArguments ( arguments ) ) )
91
-
88
+ . action ( async ( walletPath , tx , ...args ) => await Account . sign ( walletPath , tx , utils . cli . getCmdFromArguments ( args ) ) )
92
89
93
90
// ## Initialize `sign-message` command
94
91
//
@@ -99,8 +96,7 @@ program
99
96
. command ( 'sign-message <wallet_path> [data...]' )
100
97
. option ( '--filePath [path]' , 'Specify the path to the file for signing(ignore command message argument and use file instead)' )
101
98
. description ( 'Create a transaction to another wallet' )
102
- . action ( async ( walletPath , data , ...arguments ) => await Account . signMessage ( walletPath , data , utils . cli . getCmdFromArguments ( arguments ) ) )
103
-
99
+ . action ( async ( walletPath , data , ...args ) => await Account . signMessage ( walletPath , data , utils . cli . getCmdFromArguments ( args ) ) )
104
100
105
101
// ## Initialize `verify-message` command
106
102
//
@@ -111,8 +107,7 @@ program
111
107
. command ( 'verify-message <wallet_path> <hexSignature> [data...]' )
112
108
. option ( '--filePath [path]' , 'Specify the path to the file(ignore comm and message argument and use file instead)' )
113
109
. description ( 'Create a transaction to another wallet' )
114
- . action ( async ( walletPath , hexSignature , data , ...arguments ) => await Account . verifyMessage ( walletPath , hexSignature , data , utils . cli . getCmdFromArguments ( arguments ) ) )
115
-
110
+ . action ( async ( walletPath , hexSignature , data , ...args ) => await Account . verifyMessage ( walletPath , hexSignature , data , utils . cli . getCmdFromArguments ( args ) ) )
116
111
117
112
// ## Initialize `balance` command
118
113
//
@@ -124,7 +119,7 @@ program
124
119
. option ( '--height [height]' , 'Specific block height' )
125
120
. option ( '--hash [hash]' , 'Specific block hash' )
126
121
. description ( 'Get wallet balance' )
127
- . action ( async ( walletPath , ...arguments ) => await Account . getBalance ( walletPath , utils . cli . getCmdFromArguments ( arguments ) ) )
122
+ . action ( async ( walletPath , ...args ) => await Account . getBalance ( walletPath , utils . cli . getCmdFromArguments ( args ) ) )
128
123
129
124
// ## Initialize `address` command
130
125
//
@@ -138,7 +133,7 @@ program
138
133
. option ( '--privateKey' , 'Print private key' )
139
134
. option ( '--forcePrompt' , 'Force prompting' )
140
135
. description ( 'Get wallet address' )
141
- . action ( async ( walletPath , ...arguments ) => await Account . getAddress ( walletPath , utils . cli . getCmdFromArguments ( arguments ) ) )
136
+ . action ( async ( walletPath , ...args ) => await Account . getAddress ( walletPath , utils . cli . getCmdFromArguments ( args ) ) )
142
137
143
138
// ## Initialize `create` command
144
139
//
@@ -155,7 +150,7 @@ program
155
150
. option ( '-O, --output [output]' , 'Output directory' , '.' )
156
151
. option ( '--overwrite' , 'Overwrite if exist' )
157
152
. description ( 'Create a secure wallet' )
158
- . action ( async ( name , ...arguments ) => await Account . createSecureWallet ( name , utils . cli . getCmdFromArguments ( arguments ) ) )
153
+ . action ( async ( name , ...args ) => await Account . createSecureWallet ( name , utils . cli . getCmdFromArguments ( args ) ) )
159
154
160
155
// ## Initialize `save` command
161
156
//
@@ -172,7 +167,7 @@ program
172
167
. option ( '-O, --output [output]' , 'Output directory' , '.' )
173
168
. option ( '--overwrite' , 'Overwrite if exist' )
174
169
. description ( 'Save a private keys string to a password protected file wallet' )
175
- . action ( async ( name , priv , ...arguments ) => await Account . createSecureWalletByPrivKey ( name , priv , utils . cli . getCmdFromArguments ( arguments ) ) )
170
+ . action ( async ( name , priv , ...args ) => await Account . createSecureWalletByPrivKey ( name , priv , utils . cli . getCmdFromArguments ( args ) ) )
176
171
177
172
// ## Initialize `nonce` command
178
173
//
@@ -184,7 +179,7 @@ program
184
179
program
185
180
. command ( 'nonce <wallet_path>' )
186
181
. description ( 'Get account nonce' )
187
- . action ( async ( walletPath , ...arguments ) => await Account . getAccountNonce ( walletPath , utils . cli . getCmdFromArguments ( arguments ) ) )
182
+ . action ( async ( walletPath , ...args ) => await Account . getAccountNonce ( walletPath , utils . cli . getCmdFromArguments ( args ) ) )
188
183
189
184
// ## Initialize `generateKeyPairs` command
190
185
//
@@ -195,12 +190,7 @@ program
195
190
. command ( 'generate <count>' )
196
191
. option ( '--forcePrompt' , 'Force prompting' )
197
192
. description ( 'Generate keyPairs' )
198
- . action ( async ( count , ...arguments ) => await Account . generateKeyPairs ( count , utils . cli . getCmdFromArguments ( arguments ) ) )
199
-
200
-
201
- // Handle unknown command's
202
- program . on ( 'command:*' , ( ) => utils . errors . unknownCommandHandler ( program ) ( ) )
193
+ . action ( async ( count , ...args ) => await Account . generateKeyPairs ( count , utils . cli . getCmdFromArguments ( args ) ) )
203
194
204
- // Parse arguments or show `help` if argument's is empty
195
+ // Parse arguments
205
196
program . parse ( process . argv )
206
- if ( program . args . length === 0 ) program . help ( )
0 commit comments