Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions struct_module/commands/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import argparse
from struct_module.file_item import FileItem
from struct_module.completers import file_strategy_completer
from struct_module.utils import project_path

# Generate command class
class GenerateCommand(Command):
def __init__(self, parser):
super().__init__(parser)
parser.add_argument('structure_definition', type=str, help='Path to the YAML configuration file')
parser.add_argument('base_path', type=str, help='Base path where the structure will be created')
parser.add_argument('-s', '--structures-path', type=str, help='Path to structure definitions', default='contribs')
parser.add_argument('-s', '--structures-path', type=str, help='Path to structure definitions')
parser.add_argument('-d', '--dry-run', action='store_true', help='Perform a dry run without creating any files or directories')
parser.add_argument('-v', '--vars', type=str, help='Template variables in the format KEY1=value1,KEY2=value2')
parser.add_argument('-b', '--backup', type=str, help='Path to the backup folder')
Expand Down Expand Up @@ -39,7 +40,11 @@ def _create_structure(self, args):
with open(args.structure_definition[7:], 'r') as f:
config = yaml.safe_load(f)
else:
file_path = os.path.join(args.structures_path, f"{args.structure_definition}.yaml")
if args.structures_path is None:
this_file = os.path.dirname(os.path.realpath(__file__))
file_path = os.path.join(project_path, "contribs", f"{args.structure_definition}.yaml")
else:
file_path = os.path.join(args.structures_path, f"{args.structure_definition}.yaml")
# show error if file is not found
if not os.path.exists(file_path):
self.logger.error(f"File not found: {file_path}")
Expand Down
15 changes: 12 additions & 3 deletions struct_module/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@
import os
import yaml
from struct_module.file_item import FileItem
from struct_module.utils import project_path

# List command class
class ListCommand(Command):
def __init__(self, parser):
super().__init__(parser)
parser.add_argument('-s', '--structures-path', type=str, help='Path to structure definitions')
parser.set_defaults(func=self.execute)

def execute(self, args):
self.logger.info(f"Listing available structures")
self._list_structures()
self._list_structures(args)

def _list_structures(self, args):

if args.structures_path is None:
this_file = os.path.dirname(os.path.realpath(__file__))
final_path = os.path.join(project_path, "contribs")
else:
final_path = os.path.join(args.structures_path)

def _list_structures(self):
print("Listing available structures")
sorted_list = [structure for structure in os.listdir('contribs') if structure.endswith('.yaml')]
sorted_list = [structure for structure in os.listdir(final_path) if structure.endswith('.yaml')]
sorted_list.sort()
for structure in sorted_list:
print(f" - {structure[:-5]}")
4 changes: 3 additions & 1 deletion struct_module/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import yaml

import os

def read_config_file(file_path):
with open(file_path, 'r') as f:
Expand All @@ -12,3 +12,5 @@ def merge_configs(file_config, args):
if key in args_dict and args_dict[key] is None:
args_dict[key] = value
return args_dict

project_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")