File tree Expand file tree Collapse file tree 1 file changed +32
-22
lines changed Expand file tree Collapse file tree 1 file changed +32
-22
lines changed Original file line number Diff line number Diff line change 22
33'use strict' ;
44
5- require ( 'v8-compile-cache' ) ;
6-
75const Conf = require ( 'conf' ) ;
8- const meow = require ( 'meow ' ) ;
6+ const getopts = require ( 'getopts ' ) ;
97const chalk = require ( 'chalk' ) ;
108const prompts = require ( 'prompts' ) ;
119const cash = require ( './cash.js' ) ;
1210
1311const config = new Conf ( { projectName : 'cash-cli' } ) ;
1412const argv = process . argv . slice ( 2 ) ;
1513
16- // CLI configuration
17- const cli = meow ( `
18- Usage
19- $ cash <amount> <from> <to>
20- $ cash <options>
21- Options
22- --api -a Configure API source
23- --save -s Save default currencies
24- Examples
25- $ cash --key
26- $ cash 10 usd eur pln
27- $ cash --save usd aud
28- ` , {
29- flags : {
30- api : {
31- type : 'boolean' ,
32- alias : 'a'
33- }
14+ const options = getopts ( argv , {
15+ alias : {
16+ help : 'h' ,
17+ version : 'v' ,
18+ api : 'a' ,
19+ save : 's' ,
20+ json : 'j'
3421 }
3522} ) ;
3623
24+ if ( options . help ) {
25+ console . log ( `
26+ Usage:
27+ $ cash <amount> <from> <to>
28+ $ cash <options>
29+ Options:
30+ --api -a Configure API source
31+ --save -s <from> <to...> Save default currencies
32+ -v, --version Print the version
33+ -h, --help Print this help
34+ Examples:
35+ $ cash --api
36+ $ cash 10 usd eur pln
37+ $ cash --save usd eur pln chf
38+ ` ) ;
39+ process . exit ( 0 ) ;
40+ }
41+
42+ if ( options . version ) {
43+ console . log ( require ( '../package.json' ) . version ) ;
44+ process . exit ( 0 ) ;
45+ }
46+
3747// Handle amount & currencies
3848const command = {
3949 amount : argv [ 0 ] ? Number ( argv [ 0 ] . replace ( ',' , '.' ) ) : 1 ,
@@ -42,7 +52,7 @@ const command = {
4252} ;
4353
4454// Configure API source
45- if ( cli . flags . api ) {
55+ if ( options . api ) {
4656 const questions = [
4757 {
4858 type : 'select' ,
You can’t perform that action at this time.
0 commit comments