Skip to content

Commit 022e2de

Browse files
committed
Use getopts instead of meow & remove v8-compile-cache
1 parent edf3a3d commit 022e2de

File tree

1 file changed

+32
-22
lines changed

1 file changed

+32
-22
lines changed

bin/index.js

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,48 @@
22

33
'use strict';
44

5-
require('v8-compile-cache');
6-
75
const Conf = require('conf');
8-
const meow = require('meow');
6+
const getopts = require('getopts');
97
const chalk = require('chalk');
108
const prompts = require('prompts');
119
const cash = require('./cash.js');
1210

1311
const config = new Conf({projectName: 'cash-cli'});
1412
const 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
3848
const 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',

0 commit comments

Comments
 (0)