Skip to content

Commit 43bb3e9

Browse files
authored
Feat: change from command options to option flags (#17)
* Feat: change change from command options to option flags * Test: update for new feature
1 parent d3703a9 commit 43bb3e9

File tree

6 files changed

+32
-23
lines changed

6 files changed

+32
-23
lines changed

lib/cli.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

33
import yargs from 'yargs';
44
import updateNotifier from 'update-notifier';
5+
6+
import options from './options';
7+
58
import pkg from '../package.json';
69

710
yargs // eslint-disable-line
811
.commandDir('cmds')
12+
.options(options)
913
.demandCommand()
1014
.help()
1115
.argv;

lib/cmds/recover.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
11
import recoverTasks from '../tasks/recover-tasks';
22

3-
const command = 'recover [backup]';
4-
5-
const builder = {
6-
backup: {
7-
default: false,
8-
},
9-
};
3+
const command = 'recover';
104

115
const aliases = ['r'];
126

137
const desc = 'Recover the complete CHANGELOG.md';
148

159
/* istanbul ignore next */
16-
const handler = (argv) => {
17-
if (argv.backup || argv.b) {
18-
return recoverTasks(true).run();
19-
}
20-
21-
return recoverTasks(false).run();
22-
};
10+
const handler = (argv) => recoverTasks(argv.b).run();
2311

2412
export {
2513
command,
26-
builder,
2714
aliases,
2815
desc,
2916
handler,

lib/options/backup.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const backup = {
2+
alias: 'b',
3+
describe: 'backup CHANGELOG.md when recover',
4+
type: 'boolean',
5+
};
6+
7+
export default backup;

lib/options/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import backup from './backup';
2+
3+
export default {
4+
backup,
5+
};

test/cmds/recover.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,18 @@ import test from 'ava';
22

33
import {
44
command,
5-
builder,
65
aliases,
76
desc,
87
} from '../../lib/cmds/recover';
98

109
test('CMDS | RECOVER | check command name, builder, aliases, and desc', (t) => {
1110
const value = {
1211
command,
13-
builder,
1412
aliases,
1513
desc,
1614
};
1715
const expected = {
18-
command: 'recover [backup]',
19-
builder: {
20-
backup: {
21-
default: false,
22-
},
23-
},
16+
command: 'recover',
2417
aliases: ['r'],
2518
desc: 'Recover the complete CHANGELOG.md',
2619
};

test/options/backup.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import test from 'ava';
2+
3+
import backup from '../../lib/options/backup';
4+
5+
test('OPTIONS | BACKUP | check alias, describe and type', (t) => {
6+
const expected = {
7+
alias: 'b',
8+
describe: 'backup CHANGELOG.md when recover',
9+
type: 'boolean',
10+
};
11+
12+
t.deepEqual(backup, expected);
13+
});

0 commit comments

Comments
 (0)