improve option parsing in bin/marked.
This commit is contained in:
parent
5a1c7a5871
commit
2b688ac505
25
bin/marked
25
bin/marked
@ -38,7 +38,8 @@ function main(argv, callback) {
|
|||||||
, input
|
, input
|
||||||
, output
|
, output
|
||||||
, arg
|
, arg
|
||||||
, tokens;
|
, tokens
|
||||||
|
, opt;
|
||||||
|
|
||||||
function getarg() {
|
function getarg() {
|
||||||
var arg = argv.shift();
|
var arg = argv.shift();
|
||||||
@ -88,12 +89,18 @@ function main(argv, callback) {
|
|||||||
return help();
|
return help();
|
||||||
default:
|
default:
|
||||||
if (arg.indexOf('--') === 0) {
|
if (arg.indexOf('--') === 0) {
|
||||||
arg = arg.substring(2);
|
opt = camelize(arg.replace(/^--(no-)?/, ''));
|
||||||
if (arg.indexOf('no-') === 0) {
|
if (!marked.defaults.hasOwnProperty(opt)) {
|
||||||
arg = arg.substring(3);
|
continue;
|
||||||
options[arg] = false;
|
}
|
||||||
|
if (arg.indexOf('--no-') === 0) {
|
||||||
|
options[opt] = typeof marked.defaults[opt] !== 'boolean'
|
||||||
|
? null
|
||||||
|
: false;
|
||||||
} else {
|
} else {
|
||||||
options[arg] = true;
|
options[opt] = typeof marked.defaults[opt] !== 'boolean'
|
||||||
|
? argv.shift()
|
||||||
|
: true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
files.push(arg);
|
files.push(arg);
|
||||||
@ -157,6 +164,12 @@ function getStdin(callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function camelize(text) {
|
||||||
|
return text.replace(/(\w)-(\w)/g, function(_, a, b) {
|
||||||
|
return a + b.toUpperCase();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expose / Entry Point
|
* Expose / Entry Point
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user