Skip to content

Commit

Permalink
Feat: change from command options to option flags (#17)
Browse files Browse the repository at this point in the history
* Feat: change change from command options to option flags

* Test: update for new feature
  • Loading branch information
aichbauer committed Oct 23, 2017
1 parent d3703a9 commit 43bb3e9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 deletions.
4 changes: 4 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import yargs from 'yargs';
import updateNotifier from 'update-notifier';

import options from './options';

import pkg from '../package.json';

yargs // eslint-disable-line
.commandDir('cmds')
.options(options)
.demandCommand()
.help()
.argv;
Expand Down
17 changes: 2 additions & 15 deletions lib/cmds/recover.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,16 @@
import recoverTasks from '../tasks/recover-tasks';

const command = 'recover [backup]';

const builder = {
backup: {
default: false,
},
};
const command = 'recover';

const aliases = ['r'];

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

/* istanbul ignore next */
const handler = (argv) => {
if (argv.backup || argv.b) {
return recoverTasks(true).run();
}

return recoverTasks(false).run();
};
const handler = (argv) => recoverTasks(argv.b).run();

export {
command,
builder,
aliases,
desc,
handler,
Expand Down
7 changes: 7 additions & 0 deletions lib/options/backup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const backup = {
alias: 'b',
describe: 'backup CHANGELOG.md when recover',
type: 'boolean',
};

export default backup;
5 changes: 5 additions & 0 deletions lib/options/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import backup from './backup';

export default {
backup,
};
9 changes: 1 addition & 8 deletions test/cmds/recover.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,18 @@ import test from 'ava';

import {
command,
builder,
aliases,
desc,
} from '../../lib/cmds/recover';

test('CMDS | RECOVER | check command name, builder, aliases, and desc', (t) => {
const value = {
command,
builder,
aliases,
desc,
};
const expected = {
command: 'recover [backup]',
builder: {
backup: {
default: false,
},
},
command: 'recover',
aliases: ['r'],
desc: 'Recover the complete CHANGELOG.md',
};
Expand Down
13 changes: 13 additions & 0 deletions test/options/backup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import test from 'ava';

import backup from '../../lib/options/backup';

test('OPTIONS | BACKUP | check alias, describe and type', (t) => {
const expected = {
alias: 'b',
describe: 'backup CHANGELOG.md when recover',
type: 'boolean',
};

t.deepEqual(backup, expected);
});

0 comments on commit 43bb3e9

Please sign in to comment.