Skip to content

Commit a3800b3

Browse files
chore: auto fixes from pre-commit.com hooks
1 parent a90d94f commit a3800b3

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

src/ansible_creator/config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ class Config:
3030
project: The type of project to scaffold.
3131
collection_name: The name of the collection.
3232
namespace: The namespace for the collection.
33+
resource_type: The type of resource to be scaffolded.
34+
path: The file path where the resource should be added.
35+
type: The type of the project for which the resource is being scaffolded.
3336
"""
3437

3538
creator_version: str
3639
output: Output
3740
subcommand: str
3841
type: str = ""
39-
resource_type :str = ""
40-
path :str = ""
42+
resource_type: str = ""
43+
path: str = ""
4144
collection: str = ""
4245
force: bool = False
4346
overwrite: bool = False

src/ansible_creator/subcommands/add.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,29 @@
88
from ansible_creator.exceptions import CreatorError
99
from ansible_creator.templar import Templar
1010
from ansible_creator.types import TemplateData
11-
from ansible_creator.utils import Walker, Copier, ask_yes_no
11+
from ansible_creator.utils import Copier, Walker, ask_yes_no
1212

1313

1414
if TYPE_CHECKING:
1515
from ansible_creator.config import Config
1616
from ansible_creator.output import Output
1717

18+
1819
class Add:
1920
"""Class to handle the add subcommand."""
2021

2122
common_resources = ("common.devfile",)
22-
23-
23+
2424
def __init__(
2525
self: Add,
2626
config: Config,
2727
) -> None:
28-
28+
"""Initialize the add action.
29+
30+
Args:
31+
config: App configuration object.
32+
"""
33+
2934
self._resource_type: str = config.resource_type
3035
self._add_path: Path = Path(config.path)
3136
self._force = config.force
@@ -35,7 +40,7 @@ def __init__(
3540
self._project = config.project
3641
self.output: Output = config.output
3742
self.templar = Templar()
38-
43+
3944
def run(self) -> None:
4045
"""Start scaffolding the resource file."""
4146
self._check_add_path()
@@ -46,7 +51,9 @@ def run(self) -> None:
4651
def _check_add_path(self) -> None:
4752
"""Validate the provided add path."""
4853
if not self._add_path.exists():
49-
raise CreatorError(f"The path {self._add_path} does not exist. Please provide an existing directory.")
54+
raise CreatorError(
55+
f"The path {self._add_path} does not exist. Please provide an existing directory.",
56+
)
5057

5158
def _scaffold(self) -> None:
5259
"""Scaffold the specified resource file."""
@@ -59,8 +66,7 @@ def _scaffold(self) -> None:
5966
)
6067

6168
# Initialize Walker and Copier for file operations
62-
63-
69+
6470
walker = Walker(
6571
resources=self.common_resources,
6672
resource_id="common.devfile",
@@ -71,28 +77,30 @@ def _scaffold(self) -> None:
7177
)
7278
paths = walker.collect_paths()
7379
copier = Copier(output=self.output)
74-
80+
7581
if self._no_overwrite:
82+
msg = "The flag `--no-overwrite` restricts overwriting."
7683
if paths.has_conflicts():
77-
raise CreatorError(
78-
"The destination directory contains files that may be overwritten. "
79-
"Please re-run ansible-creator with --overwrite to proceed."
84+
msg += (
85+
"\nThe destination directory contains files that can be overwritten."
86+
"\nPlease re-run ansible-creator with --overwrite to continue."
8087
)
88+
raise CreatorError(msg)
8189

8290
if not paths.has_conflicts() or self._force or self._overwrite:
8391
copier.copy_containers(paths)
8492
self.output.note(f"Resource added to {self._add_path}")
8593
return
8694

87-
8895
if not self._overwrite:
8996
question = "Some files in the destination directory may be overwritten. Do you want to proceed?"
9097
if ask_yes_no(question):
9198
copier.copy_containers(paths)
9299
else:
93-
raise CreatorError(
94-
"The destination contains files that could be overwritten. "
95-
"Please re-run ansible-creator with --overwrite to continue."
100+
msg = (
101+
"The destination directory contains files that will be overwritten."
102+
" Please re-run ansible-creator with --overwrite to continue."
96103
)
104+
raise CreatorError(msg)
97105

98-
self.output.note(f"Resource added to {self._add_path}")
106+
self.output.note(f"Resource added to {self._add_path}")

0 commit comments

Comments
 (0)