mirror of
https://github.com/markedjs/marked
synced 2024-11-23 09:48:17 +00:00
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
|
||||
, output
|
||||
, arg
|
||||
, tokens;
|
||||
, tokens
|
||||
, opt;
|
||||
|
||||
function getarg() {
|
||||
var arg = argv.shift();
|
||||
@ -88,12 +89,18 @@ function main(argv, callback) {
|
||||
return help();
|
||||
default:
|
||||
if (arg.indexOf('--') === 0) {
|
||||
arg = arg.substring(2);
|
||||
if (arg.indexOf('no-') === 0) {
|
||||
arg = arg.substring(3);
|
||||
options[arg] = false;
|
||||
opt = camelize(arg.replace(/^--(no-)?/, ''));
|
||||
if (!marked.defaults.hasOwnProperty(opt)) {
|
||||
continue;
|
||||
}
|
||||
if (arg.indexOf('--no-') === 0) {
|
||||
options[opt] = typeof marked.defaults[opt] !== 'boolean'
|
||||
? null
|
||||
: false;
|
||||
} else {
|
||||
options[arg] = true;
|
||||
options[opt] = typeof marked.defaults[opt] !== 'boolean'
|
||||
? argv.shift()
|
||||
: true;
|
||||
}
|
||||
} else {
|
||||
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
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user