Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Commit

Permalink
feat(cli): add aliases, more help details and tests
Browse files Browse the repository at this point in the history
Cli help is more complete. Aliases are added to make it easier to set options. Tests for cli options are added
  • Loading branch information
stevemao committed Mar 9, 2015
1 parent 2e108e4 commit b3a5e81
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
22 changes: 19 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,32 @@ var separator = '\n\n\n';

var cli = meow({
help: [
'Practice writing commit messages or test from a file.',
'If used without specifying a text file path, you will enter an interactive shell.',
'Parsed results are printed to stdout',
'By default, commits will be split by three newlines (`\\n\\n\\n`) or you can specify a separator.',
'',
'Usage',
' conventional-commits-parser [<commit-separator>] [<path>...]',
' If used without specifying a text file path, you will enter an interactive shell',
' By default, commits will be split by three newlines (`\\n\\n\\n`) or you can specify a separator',
'',
'Example',
' conventional-commits-parser',
' conventional-commits-parser log.txt',
' conventional-commits-parser log2.txt \'===\''
' conventional-commits-parser log2.txt \'===\' >> output.txt',
'',
'Options',
'-m, --max-subject-length Maximum subject length',
'-p, --header-pattern Regex to match header pattern',
'-c, --close-keywords Comma separated keywords that used to close issues',
'-b, --break-keywords Comma separated keywords for breaking changes'
].join('\n')
}, {
alias: {
m: 'maxSubjectLength',
p: 'headerPattern',
c: 'closeKeywords',
b: 'breakKeywords'
}
});

forEach(cli.input, function(arg) {
Expand Down
16 changes: 13 additions & 3 deletions test/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var through = require('through2');
var cliPath = './cli.js';
var output1 = readFileSync('test/expected/output1.txt', 'utf-8');
var output2 = readFileSync('test/expected/output2.txt', 'utf-8');
var output3 = readFileSync('test/expected/output3.txt', 'utf-8');

describe('cli', function() {
it('should parse commits in a file', function(done) {
Expand Down Expand Up @@ -40,18 +41,27 @@ describe('cli', function() {

it('should error if files cannot be found', function(done) {
var i = 0;
var cp = spawn(cliPath, ['test/fixtures/log.txt', 'test/fixtures/log3.txt', 'test/fixtures/log2.txt', 'test/fixtures/log4.txt', '===']);
var cp = spawn(cliPath, ['test/fixtures/log.txt', 'test/fixtures/log4.txt', 'test/fixtures/log2.txt', 'test/fixtures/log5.txt', '===']);
cp.stderr
.pipe(through(function(chunk, enc, cb) {
if (i === 0) {
expect(chunk.toString()).to.contain('Failed to read file test/fixtures/log3.txt');
} else {
expect(chunk.toString()).to.contain('Failed to read file test/fixtures/log4.txt');
} else {
expect(chunk.toString()).to.contain('Failed to read file test/fixtures/log5.txt');
}
i++;
cb();
}, function() {
done();
}));
});

it('should work with options', function(done) {
var cp = spawn(cliPath, ['test/fixtures/log3.txt', '--max-subject-length', '5', '-p', '^(\\w*)(?:\\(([:\\w\\$\\.\\-\\* ]*)\\))?\\: (.*)$', '--close-keywords', 'close, fix', '-b', 'BREAKING NEWS']);
cp.stdout
.pipe(concat(function(chunk) {
expect(chunk.toString()).to.equal(output3);
done();
}));
});
});
3 changes: 3 additions & 0 deletions test/expected/output3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
{"hash":"9b1aff905b638aa274a5fc8f88662df446d374bd","header":"fix(category:subcategory): My subject","body":"This is my commit body.\nFixed #13233","footer":"BREAKING NEWS: A lot of changes!\nClose #10036, Closes #10000\nfix #9338","breaks":{"BREAKING NEWS":"A lot of changes!"},"closes":[10036,9338],"type":"fix","scope":"category:subcategory","subject":"My su"}
]
11 changes: 11 additions & 0 deletions test/fixtures/log3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
9b1aff905b638aa274a5fc8f88662df446d374bd

fix(category:subcategory): My subject

This is my commit body.

BREAKING NEWS: A lot of changes!

Close #10036, Closes #10000
Fixed #13233
fix #9338

0 comments on commit b3a5e81

Please sign in to comment.