Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions src/towncrier/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@
metavar="FILE_PATH",
help=config_option_help,
)
@click.option(
"--overwrite",
is_flag=True,
help="Overwrite existing fragements",
)
@click.option(
"--edit/--no-edit",
default=None,
Expand All @@ -59,6 +64,7 @@ def _main(
ctx: click.Context,
directory: str | None,
config: str | None,
overwrite: bool | False,
filename: str,
edit: bool | None,
content: str,
Expand All @@ -83,13 +89,14 @@ def _main(
If the FILENAME base is just '+' (to create a fragment not tied to an
issue), it will be appended with a random hex string.
"""
__main(ctx, directory, config, filename, edit, content, section)
__main(ctx, directory, config, overwrite, filename, edit, content, section)


def __main(
ctx: click.Context,
directory: str | None,
config_path: str | None,
overwrite: bool | False,
filename: str,
edit: bool | None,
content: str,
Expand Down Expand Up @@ -198,16 +205,17 @@ def __main(

segment_file = os.path.join(fragments_directory, filename)

retry = 0
if filename.split(".")[-1] not in config.types:
filename, extra_ext = os.path.splitext(filename)
else:
extra_ext = ""
while os.path.exists(segment_file):
retry += 1
segment_file = os.path.join(
fragments_directory, f"{filename}.{retry}{extra_ext}"
)
if not overwrite:
retry = 0
if filename.split(".")[-1] not in config.types:
filename, extra_ext = os.path.splitext(filename)
else:
extra_ext = ""
while os.path.exists(segment_file):
retry += 1
segment_file = os.path.join(
fragments_directory, f"{filename}.{retry}{extra_ext}"
)

if edit:
if content == DEFAULT_CONTENT:
Expand Down
Loading