feat: add --no-clobber option to CLI (#3025)

Co-authored-by: skoriop <karthikp.ivy@gmail.com>
Co-authored-by: Steven <steven@ceriously.com>
This commit is contained in:
Karthik Prakash 2023-10-05 07:35:55 +05:30 committed by GitHub
parent c9ffa649a4
commit b8adee7f7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View File

@ -62,6 +62,7 @@ export async function main(nodeProcess) {
let tokens;
let config;
let opt;
let noclobber;
function getArg() {
let arg = argv.shift();
@ -114,6 +115,10 @@ export async function main(nodeProcess) {
case '--config':
config = argv.shift();
break;
case '-n':
case '--no-clobber':
noclobber = true;
break;
case '-h':
case '--help':
return await help();
@ -216,6 +221,10 @@ export async function main(nodeProcess) {
: await marked.parse(data, options);
if (output) {
if (noclobber && await fileExists(output)) {
nodeProcess.stderr.write('marked: output file \'' + output + '\' already exists, disable the \'-n\' / \'--no-clobber\' flag to overwrite\n');
nodeProcess.exit(1);
}
return await writeFile(output, html);
}

View File

@ -2,7 +2,7 @@
## SYNOPSIS
`marked` [`-o` <output file>] [`-i` <input file>] [`-s` <markdown string>] [`-c` <config file>] [`--help`] [`--version`] [`--tokens`] [`--pedantic`] [`--gfm`] [`--breaks`] [`--no-etc...`] [`--silent`] [filename]
`marked` [`-o` <output file>] [`-i` <input file>] [`-s` <markdown string>] [`-c` <config file>] [`--help`] [`--version`] [`--tokens`] [`--no-clobber`] [`--pedantic`] [`--gfm`] [`--breaks`] [`--no-etc...`] [`--silent`] [filename]
## DESCRIPTION
@ -45,6 +45,9 @@ Specify config file to use instead of the default `~/.marked.json` or `~/.marked
* -t, --tokens
Output a token list instead of html.
* -n, --no-clobber
Do not overwrite `output` if it exists.
* --pedantic
Conform to obscure parts of markdown.pl as much as possible.
Don't fix original markdown bugs.