Skip to content

Commit b8adee7

Browse files
skoriopstyfle
andauthored
feat: add --no-clobber option to CLI (#3025)
Co-authored-by: skoriop <[email protected]> Co-authored-by: Steven <[email protected]>
1 parent c9ffa64 commit b8adee7

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

bin/main.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export async function main(nodeProcess) {
6262
let tokens;
6363
let config;
6464
let opt;
65+
let noclobber;
6566

6667
function getArg() {
6768
let arg = argv.shift();
@@ -114,6 +115,10 @@ export async function main(nodeProcess) {
114115
case '--config':
115116
config = argv.shift();
116117
break;
118+
case '-n':
119+
case '--no-clobber':
120+
noclobber = true;
121+
break;
117122
case '-h':
118123
case '--help':
119124
return await help();
@@ -216,6 +221,10 @@ export async function main(nodeProcess) {
216221
: await marked.parse(data, options);
217222

218223
if (output) {
224+
if (noclobber && await fileExists(output)) {
225+
nodeProcess.stderr.write('marked: output file \'' + output + '\' already exists, disable the \'-n\' / \'--no-clobber\' flag to overwrite\n');
226+
nodeProcess.exit(1);
227+
}
219228
return await writeFile(output, html);
220229
}
221230

man/marked.1.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## SYNOPSIS
44

5-
`marked` [`-o` <output file>] [`-i` <input file>] [`-s` <markdown string>] [`-c` <config file>] [`--help`] [`--version`] [`--tokens`] [`--pedantic`] [`--gfm`] [`--breaks`] [`--no-etc...`] [`--silent`] [filename]
5+
`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]
66

77
## DESCRIPTION
88

@@ -45,6 +45,9 @@ Specify config file to use instead of the default `~/.marked.json` or `~/.marked
4545
* -t, --tokens
4646
Output a token list instead of html.
4747

48+
* -n, --no-clobber
49+
Do not overwrite `output` if it exists.
50+
4851
* --pedantic
4952
Conform to obscure parts of markdown.pl as much as possible.
5053
Don't fix original markdown bugs.

0 commit comments

Comments
 (0)