-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinit.py
More file actions
52 lines (40 loc) · 1.41 KB
/
Copy pathinit.py
File metadata and controls
52 lines (40 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from struct_module.commands import Command
import os
import textwrap
BASIC_STRUCT_YAML = textwrap.dedent(
"""
# Generated by `struct init`
# Edit as needed to customize your project bootstrap
pre_hooks:
- echo "Starting struct generation"
post_hooks:
- echo "Struct generation completed"
files:
- README.md: |
# Project
Initialized with struct.
folders:
- ./:
struct:
- github/workflows/run-struct
"""
).lstrip()
class InitCommand(Command):
def __init__(self, parser):
super().__init__(parser)
parser.description = "Initialize a basic .struct.yaml in the target directory"
parser.add_argument('path', nargs='?', default='.', help='Directory to initialize (default: current directory)')
parser.set_defaults(func=self.execute)
def execute(self, args):
base_path = os.path.abspath(args.path or '.')
target = os.path.join(base_path, '.struct.yaml')
os.makedirs(base_path, exist_ok=True)
# If file exists, do not overwrite without explicit confirmation behavior (keep simple: skip)
if os.path.exists(target):
self.logger.info(f".struct.yaml already exists at {target}, skipping creation")
print(f"⚠️ .struct.yaml already exists at: {target}")
return
with open(target, 'w') as f:
f.write(BASIC_STRUCT_YAML)
print("✅ Created .struct.yaml")
print(f" - {target}")