Skip to content

Commit

Permalink
Merge pull request #2 from masnagam/feat-opts-boolean
Browse files Browse the repository at this point in the history
feat: Added the 'boolean' option
  • Loading branch information
mattallty authored Sep 17, 2018
2 parents c8d6618 + 2fe50de commit 1ff6f58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/micromist.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function parseValue(name, val, opts) {
* @param args
* @param {Object} opts
* @param {String|String[]} opts.string - A string or array of strings argument names to always treat as strings
* @param {String|String[]} opts.boolean - A string or array of strings argument names to always treat as true values
*
* @returns {{_: Array}}
*/
Expand All @@ -53,6 +54,9 @@ function micromist(args, opts) {
if (typeof opts.string === 'string') {
opts.string = [opts.string];
}
if (typeof opts.boolean === 'string') {
opts.boolean = [opts.boolean];
}

const r = {_:[]};
let pointer = 0;
Expand All @@ -75,6 +79,8 @@ function micromist(args, opts) {

if (parts.length > 1) {
compute(r, parts[0], parts[1]);
} else if (opts.boolean !== undefined && opts.boolean.includes(parts[0])) {
compute(r, parts[0], true);
} else {
const next = args[pointer+1];
isNextOpt = isOption(next);
Expand All @@ -87,4 +93,4 @@ function micromist(args, opts) {
return r;
}

module.exports = micromist;
module.exports = micromist;
4 changes: 2 additions & 2 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
const micromist = require('../');
const minimist = require('minimist');

const args2 = minimist(process.argv.slice(2));
const args2 = minimist(process.argv.slice(2), {boolean:'b'});

console.log("minimist");
console.log(args2);


const args = micromist(process.argv, {string:'-l'});
const args = micromist(process.argv, {string:'-l', boolean:'-b'});

console.log("micromist");
console.log(args);
Expand Down

0 comments on commit 1ff6f58

Please sign in to comment.