8
8
from ansible_creator .exceptions import CreatorError
9
9
from ansible_creator .templar import Templar
10
10
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
12
12
13
13
14
14
if TYPE_CHECKING :
15
15
from ansible_creator .config import Config
16
16
from ansible_creator .output import Output
17
17
18
+
18
19
class Add :
19
20
"""Class to handle the add subcommand."""
20
21
21
22
common_resources = ("common.devfile" ,)
22
-
23
-
23
+
24
24
def __init__ (
25
25
self : Add ,
26
26
config : Config ,
27
27
) -> None :
28
-
28
+
29
29
self ._resource_type : str = config .resource_type
30
30
self ._add_path : Path = Path (config .path )
31
31
self ._force = config .force
@@ -35,7 +35,7 @@ def __init__(
35
35
self ._project = config .project
36
36
self .output : Output = config .output
37
37
self .templar = Templar ()
38
-
38
+
39
39
def run (self ) -> None :
40
40
"""Start scaffolding the resource file."""
41
41
self ._check_add_path ()
@@ -46,7 +46,9 @@ def run(self) -> None:
46
46
def _check_add_path (self ) -> None :
47
47
"""Validate the provided add path."""
48
48
if not self ._add_path .exists ():
49
- raise CreatorError (f"The path { self ._add_path } does not exist. Please provide an existing directory." )
49
+ raise CreatorError (
50
+ f"The path { self ._add_path } does not exist. Please provide an existing directory." ,
51
+ )
50
52
51
53
def _scaffold (self ) -> None :
52
54
"""Scaffold the specified resource file."""
@@ -59,8 +61,7 @@ def _scaffold(self) -> None:
59
61
)
60
62
61
63
# Initialize Walker and Copier for file operations
62
-
63
-
64
+
64
65
walker = Walker (
65
66
resources = self .common_resources ,
66
67
resource_id = "common.devfile" ,
@@ -71,28 +72,27 @@ def _scaffold(self) -> None:
71
72
)
72
73
paths = walker .collect_paths ()
73
74
copier = Copier (output = self .output )
74
-
75
+
75
76
if self ._no_overwrite :
76
77
if paths .has_conflicts ():
77
78
raise CreatorError (
78
79
"The destination directory contains files that may be overwritten. "
79
- "Please re-run ansible-creator with --overwrite to proceed."
80
+ "Please re-run ansible-creator with --overwrite to proceed." ,
80
81
)
81
82
82
83
if not paths .has_conflicts () or self ._force or self ._overwrite :
83
84
copier .copy_containers (paths )
84
85
self .output .note (f"Resource added to { self ._add_path } " )
85
86
return
86
87
87
-
88
88
if not self ._overwrite :
89
89
question = "Some files in the destination directory may be overwritten. Do you want to proceed?"
90
90
if ask_yes_no (question ):
91
91
copier .copy_containers (paths )
92
92
else :
93
93
raise CreatorError (
94
94
"The destination contains files that could be overwritten. "
95
- "Please re-run ansible-creator with --overwrite to continue."
95
+ "Please re-run ansible-creator with --overwrite to continue." ,
96
96
)
97
97
98
- self .output .note (f"Resource added to { self ._add_path } " )
98
+ self .output .note (f"Resource added to { self ._add_path } " )
0 commit comments