Skip to content

Commit

Permalink
Fix issue with ansible-creator --no-overwrite flag (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhikdps authored Dec 19, 2024
1 parent ff8705e commit 8426ada
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
26 changes: 12 additions & 14 deletions src/ansible_creator/subcommands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,12 @@ def _perform_resource_scaffold(self, template_data: TemplateData) -> None:
paths = walker.collect_paths()
copier = Copier(output=self.output)

if self._no_overwrite:
msg = "The flag `--no-overwrite` restricts overwriting."
if paths.has_conflicts():
msg += (
"\nThe destination directory contains files that can be overwritten."
"\nPlease re-run ansible-creator with --overwrite to continue."
)
if self._no_overwrite and paths.has_conflicts():
msg = (
"The flag `--no-overwrite` restricts overwriting."
"\nThe destination directory contains files that can be overwritten."
"\nPlease re-run ansible-creator with --overwrite to continue."
)
raise CreatorError(msg)

if not paths.has_conflicts() or self._force or self._overwrite:
Expand Down Expand Up @@ -206,13 +205,12 @@ def _perform_plugin_scaffold(self, template_data: TemplateData, plugin_path: Pat
paths = walker.collect_paths()
copier = Copier(output=self.output)

if self._no_overwrite:
msg = "The flag `--no-overwrite` restricts overwriting."
if paths.has_conflicts():
msg += (
"\nThe destination directory contains files that can be overwritten."
"\nPlease re-run ansible-creator with --overwrite to continue."
)
if self._no_overwrite and paths.has_conflicts():
msg = (
"The flag `--no-overwrite` restricts overwriting."
"\nThe destination directory contains files that can be overwritten."
"\nPlease re-run ansible-creator with --overwrite to continue."
)
raise CreatorError(msg)

if not paths.has_conflicts() or self._force or self._overwrite:
Expand Down
13 changes: 6 additions & 7 deletions src/ansible_creator/subcommands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,12 @@ def _scaffold(self) -> None:
output=self.output,
)

if self._no_overwrite:
msg = "The flag `--no-overwrite` restricts overwriting."
if paths.has_conflicts():
msg += (
"\nThe destination directory contains files that can be overwritten."
"\nPlease re-run ansible-creator with --overwrite to continue."
)
if self._no_overwrite and paths.has_conflicts():
msg = (
"The flag `--no-overwrite` restricts overwriting."
"\nThe destination directory contains files that can be overwritten."
"\nPlease re-run ansible-creator with --overwrite to continue."
)
raise CreatorError(msg)

if not paths.has_conflicts() or self._force or self._overwrite:
Expand Down

0 comments on commit 8426ada

Please sign in to comment.