Skip to content

Commit b1d0371

Browse files
author
Tjaz Erzen
committed
WIP handle dry run and full plain inputs
1 parent 4b8586c commit b1d0371

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

plain2code.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,43 @@ def render(args, run_state: RunState, event_bus: EventBus): # noqa: C901
242242
def main(): # noqa: C901
243243
args = parse_arguments()
244244

245+
# Handle early-exit flags before heavy initialization
246+
if args.dry_run or args.full_plain:
247+
template_dirs = file_utils.get_template_directories(args.filename, args.template_dir, DEFAULT_TEMPLATE_DIRS)
248+
249+
try:
250+
if args.full_plain:
251+
# Read the raw plain source file
252+
with open(args.filename, 'r') as f:
253+
plain_source = f.read()
254+
255+
[full_plain_source, _] = file_utils.get_loaded_templates(template_dirs, plain_source)
256+
257+
if args.verbose:
258+
console.info("Full plain text:\n")
259+
260+
console.info(full_plain_source)
261+
return
262+
263+
if args.dry_run:
264+
console.info("Printing dry run output...\n")
265+
_, plain_source_tree, _ = plain_file.plain_file_parser(args.filename, template_dirs)
266+
267+
render_range = None
268+
if args.render_range or args.render_from:
269+
if args.render_range:
270+
render_range = get_render_range(args.render_range, plain_source_tree)
271+
elif args.render_from:
272+
render_range = get_render_range_from(args.render_from, plain_source_tree)
273+
274+
from plain2code_utils import print_dry_run_output
275+
276+
print_dry_run_output(plain_source_tree, render_range)
277+
return
278+
except Exception as e:
279+
console.error(f"Error: {str(e)}")
280+
return
281+
245282
event_bus = EventBus()
246283

247284
if not args.api:

plain2code_arguments.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,9 @@ def parse_arguments():
301301
if not args.log_to_file and args.log_file_name != DEFAULT_LOG_FILE_NAME:
302302
parser.error("--log-file-name cannot be used when --log-to-file is False.")
303303

304+
if args.full_plain and args.dry_run:
305+
parser.error("--full-plain and --dry-run are mutually exclusive")
306+
304307
script_arg_names = [UNIT_TESTS_SCRIPT_NAME, CONFORMANCE_TESTS_SCRIPT_NAME]
305308
for script_name in script_arg_names:
306309
args = process_test_script_path(script_name, args)

plain2code_utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ def print_dry_run_output(plain_source_tree: dict, render_range: Optional[list[st
2222
specifications, _ = plain_spec.get_specifications_for_frid(plain_source_tree, frid)
2323
functional_requirement_text = specifications[plain_spec.FUNCTIONAL_REQUIREMENTS][-1]
2424
console.info(
25-
"-------------------------------------"
26-
f"Rendering functional requirement {frid}"
27-
f"{functional_requirement_text}"
28-
"-------------------------------------"
25+
"-------------------------------------\n"
26+
f"Rendering functional requirement {frid}\n"
27+
f"{functional_requirement_text}\n"
28+
"-------------------------------------\n"
2929
)
3030
if plain_spec.ACCEPTANCE_TESTS in specifications:
3131
for i, acceptance_test in enumerate(specifications[plain_spec.ACCEPTANCE_TESTS], 1):
32-
console.info(f"Generating acceptance test #{i}:\n\n{acceptance_test}")
32+
console.info(f"Generating acceptance test #{i}:\n\n{acceptance_test}\n")
3333
else:
3434
console.info(
3535
"-------------------------------------\n"

0 commit comments

Comments
 (0)