Skip to content

Commit

Permalink
feat: add --no-clobber option to CLI (#3025)
Browse files Browse the repository at this point in the history
Co-authored-by: skoriop <karthikp.ivy@gmail.com>
Co-authored-by: Steven <steven@ceriously.com>
  • Loading branch information
3 people committed Oct 5, 2023
1 parent c9ffa64 commit b8adee7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions bin/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export async function main(nodeProcess) {
let tokens;
let config;
let opt;
let noclobber;

function getArg() {
let arg = argv.shift();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 4 additions & 1 deletion man/marked.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down

1 comment on commit b8adee7

@vercel
Copy link

@vercel vercel bot commented on b8adee7 Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.