Skip to content

Commit 4d2905c

Browse files
committed
Refactor cli for inclusion
1 parent 8cc101e commit 4d2905c

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

precicecasegenerate/cli.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from .generation_utils.file_generator import FileGenerator
22
import argparse
3-
import os
3+
import sys
44
from pathlib import Path
55

66

7-
def parse_args():
7+
def makeGenerateParser(add_help: bool = True):
88
parser = argparse.ArgumentParser(
9-
description="Takes topology.yaml files as input and writes out needed files to start the precice."
9+
description="Takes topology.yaml files as input and writes out needed files to start the precice.",
10+
add_help=add_help,
1011
)
1112
parser.add_argument(
1213
"-f",
@@ -35,29 +36,37 @@ def parse_args():
3536
default=True,
3637
help="Whether to validate the input topology.yaml file against the preCICE topology schema.",
3738
)
38-
return parser.parse_args()
39+
return parser
3940

4041

41-
def main():
42-
args = parse_args()
42+
def runGenerate(ns):
43+
try:
44+
file_generator = FileGenerator(ns.input_file, ns.output_path)
45+
46+
# Clear any previous log state
47+
file_generator.logger.clear_log_state()
4348

44-
file_generator = FileGenerator(args.input_file, args.output_path)
49+
# Generate precice-config.xml, README.md, clean.sh
50+
file_generator.generate_level_0()
51+
# Generate configuration for the solvers
52+
file_generator.generate_level_1()
4553

46-
# Clear any previous log state
47-
file_generator.logger.clear_log_state()
54+
# Format the generated preCICE configuration
55+
file_generator.format_precice_config()
4856

49-
# Generate precice-config.xml, README.md, clean.sh
50-
file_generator.generate_level_0()
51-
# Generate configuration for the solvers
52-
file_generator.generate_level_1()
57+
file_generator.handle_output(ns)
5358

54-
# Format the generated preCICE configuration
55-
file_generator.format_precice_config()
59+
file_generator.validate_topology(ns)
5660

57-
file_generator.handle_output(args)
61+
return 0
62+
except:
63+
return 1
5864

59-
file_generator.validate_topology(args)
65+
66+
def main():
67+
args = makeGenerateParser().parse_args()
68+
return runGenerate(args)
6069

6170

6271
if __name__ == "__main__":
63-
main()
72+
sys.exit(main())

0 commit comments

Comments
 (0)