Skip to content

Commit 1f9f10b

Browse files
committed
Add bare init option
1 parent 01d3853 commit 1f9f10b

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

contentctl/actions/initialize.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,36 @@ def execute(self, config: test) -> None:
1717

1818
YmlWriter.writeYmlFile(str(config.path/'contentctl.yml'), config.model_dump())
1919

20-
#Create the following empty directories:
21-
for emptyDir in ['lookups', 'baselines', 'docs', 'reporting', 'investigations']:
20+
if config.bare:
21+
#Create the following empty directories:
22+
for emptyDir in ['lookups', 'baselines', 'docs', 'reporting', 'investigations', 'app_template',
23+
'deployments', 'detections', 'data_sources', 'macros', 'stories']:
2224
#Throw an error if this directory already exists
23-
(config.path/emptyDir).mkdir(exist_ok=False)
25+
(config.path/emptyDir).mkdir(exist_ok=False)
2426

25-
26-
#copy the contents of all template directories
27-
for templateDir, targetDir in [
28-
('../templates/app_template/', 'app_template'),
29-
('../templates/deployments/', 'deployments'),
30-
('../templates/detections/', 'detections'),
31-
('../templates/data_sources/', 'data_sources'),
32-
('../templates/macros/','macros'),
33-
('../templates/stories/', 'stories'),
34-
]:
35-
source_directory = pathlib.Path(os.path.dirname(__file__))/templateDir
36-
target_directory = config.path/targetDir
37-
#Throw an exception if the target exists
38-
shutil.copytree(source_directory, target_directory, dirs_exist_ok=False)
27+
else:
28+
#Create the following empty directories:
29+
for emptyDir in ['lookups', 'baselines', 'docs', 'reporting', 'investigations']:
30+
#Throw an error if this directory already exists
31+
(config.path/emptyDir).mkdir(exist_ok=False)
32+
33+
#copy the contents of all template directories
34+
for templateDir, targetDir in [
35+
('../templates/app_template/', 'app_template'),
36+
('../templates/deployments/', 'deployments'),
37+
('../templates/detections/', 'detections'),
38+
('../templates/data_sources/', 'data_sources'),
39+
('../templates/macros/','macros'),
40+
('../templates/stories/', 'stories'),
41+
]:
42+
source_directory = pathlib.Path(os.path.dirname(__file__))/templateDir
43+
target_directory = config.path/targetDir
44+
#Throw an exception if the target exists
45+
shutil.copytree(source_directory, target_directory, dirs_exist_ok=False)
3946

40-
# Create a README.md file. Note that this is the README.md for the repository, not the
41-
# one which will actually be packaged into the app. That is located in the app_template folder.
42-
shutil.copyfile(pathlib.Path(os.path.dirname(__file__))/'../templates/README.md','README.md')
47+
# Create a README.md file. Note that this is the README.md for the repository, not the
48+
# one which will actually be packaged into the app. That is located in the app_template folder.
49+
shutil.copyfile(pathlib.Path(os.path.dirname(__file__))/'../templates/README.md','README.md')
4350

4451

4552
print(f"The app '{config.app.title}' has been initialized. "

contentctl/objects/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ def serialize_path(path: DirectoryPath)->str:
164164
return str(path)
165165

166166
class init(Config_Base):
167-
pass
167+
model_config = ConfigDict(use_enum_values=True,validate_default=True, arbitrary_types_allowed=True)
168+
bare: bool = Field(default=False, description="Initialize with empty directory structure")
168169

169170

170171
class validate(Config_Base):

0 commit comments

Comments
 (0)