Skip to content

Commit

Permalink
Merge pull request #79 from jviereck/cli-flags
Browse files Browse the repository at this point in the history
bin: Add -v/--version and -f/--flags options
  • Loading branch information
jviereck committed May 24, 2016
2 parents 1d0b86a + 3913a06 commit 4e65386
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions bin/parser
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
(function() {

var fs = require('fs');
var path = require('path');
var parse = require('../parser').parse;
var jsesc = require('jsesc');
var regexes = process.argv.splice(2);
var first = regexes[0];
var data;
var log = console.log;
var flags = '';
var main = function() {
if (/^(?:-h|--help|undefined)$/.test(first)) {
log([
'\nUsage:\n',
'\tregjsparser [regex ...]',
'\tregjsparser [-f | --flags] u [regex ...]',
'\tregjsparser [-v | --version]',
'\tregjsparser [-h | --help]',
'\nExamples:\n',
'\tregjsparser \'^foo.bar$\'',
Expand All @@ -21,10 +25,19 @@
return process.exit(1);
}

if (/^(?:-v|--version)$/.test(first)) {
log('v%s', require(path.resolve(__dirname, '../package.json')).version);
return process.exit(1);
}

if (/^(?:-f|--flags)$/.test(first)) {
flags = regexes[1];
regexes = regexes.slice(2);
}

regexes.forEach(function(snippet) {
var result;
try {
result = parse(snippet, 'u');
result = parse(snippet, flags);
log(jsesc(result, {
'json': true,
'compact': false,
Expand Down

0 comments on commit 4e65386

Please sign in to comment.