Skip to content

Commit

Permalink
Feat: add option version (closes #19) (#21)
Browse files Browse the repository at this point in the history
* Feat: add new option version

* Test: add tests for new feat

* Docs: add section for option version
  • Loading branch information
aichbauer committed Nov 13, 2017
1 parent 3e2fee8 commit 17bcd6b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 5 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* [Options](#options)
* [sgr recover --backup](#sgr-recover---backup)
* [sgr --help](#sgr---help)
* [sgr --version](#sgr---version)

## Why?

Expand Down Expand Up @@ -124,3 +125,12 @@ With `sgr --help` you can display usage of `semantic-git-release-cli`.
# usage of cli
$ sgr --help
```

### sgr --version

With `sgr --version` you can display the current version of `semantic-git-release-cli`.

```sh
# current version
$ sgr --version
```
9 changes: 8 additions & 1 deletion lib/cmds/recover.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import recoverTasks from '../tasks/recover-tasks';
import { handler as showVersion } from '../cmds/version';

const command = 'recover';

Expand All @@ -7,7 +8,13 @@ const aliases = ['r'];
const desc = 'Recover the complete CHANGELOG.md';

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

return recoverTasks(argv).run();
};

export {
command,
Expand Down
2 changes: 1 addition & 1 deletion lib/cmds/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const command = '*';
const desc = 'Release a new version (run tests, write changelog, tag version, push release)';

/* istanbul ignore next */
const handler = () => release();
const handler = (argv) => release(argv);

export {
command,
Expand Down
2 changes: 2 additions & 0 deletions lib/options/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import backup from './backup';
import version from './version';

export default {
backup,
version,
};
7 changes: 7 additions & 0 deletions lib/options/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const version = {
alias: 'v',
describe: 'Show the current version number',
type: 'boolean',
};

export default version;
4 changes: 2 additions & 2 deletions lib/tasks/recover-tasks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import Listr from 'listr';

import generateCompleteChangelog from '../../helpers/generateCompleteChangelog';

const recoverTasks = (backup) => (
const recoverTasks = (argv) => (
new Listr([
{
title: 'Recover the complete CHANGELOG.md',
task: () => {
generateCompleteChangelog(backup);
generateCompleteChangelog(argv.b);
},
},
])
Expand Down
8 changes: 7 additions & 1 deletion lib/tasks/release-tasks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import generateVersions from '../../helpers/generateVersions';
import getLatestVersion from '../../helpers/getLatestVersion';
import questions from '../../questions/release-questions';

import { handler as showVersion } from '../../cmds/version';

import cleanupTasks from './cleanup';
import releaseTasks from './release';
import testsTasks from './tests';
Expand Down Expand Up @@ -42,7 +44,7 @@ const tasks = (commits, version) => (
])
);

const release = () => {
const release = (argv) => {
const cwd = process.cwd();
const latestTaggedCommits = taggedCommits({ path: cwd });
const latestTaggedCommit = latestTaggedCommits.length === 0 ? '' : latestTaggedCommits[0].commit;
Expand All @@ -63,6 +65,10 @@ const release = () => {
return console.warn(chalk.red('Error: it seems you do not have a package.json... try npm init'));
}

if (argv.v) {
return showVersion();
}

return inquirer
.prompt(questionsList)
.then((answers) => {
Expand Down
13 changes: 13 additions & 0 deletions test/options/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import test from 'ava';

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

test('OPTIONS | VERSION | check alias, describe and type', (t) => {
const expected = {
alias: 'v',
describe: 'Show the current version number',
type: 'boolean',
};

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

0 comments on commit 17bcd6b

Please sign in to comment.