Skip to content

Commit

Permalink
Started to add a CLI to the package
Browse files Browse the repository at this point in the history
  • Loading branch information
eisDNV committed Nov 5, 2024
1 parent c1acadb commit 7a0e186
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
39 changes: 39 additions & 0 deletions case_study/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import argparse
import importlib.metadata
from case_study.case import Cases, Case, Results


def cli_main():
"""Provide a Command Line Interface for sim-explorer.
`see Python tutorial for working with argparse <https://docs.python.org/3/howto/argparse.html>`_
"""
__version__ = importlib.metadata.version("case_study")
parser = argparse.ArgumentParser(prog="case_study")
parser.add_argument("-V", "--version", action="version", version=__version__)
parser.add_argument("cases", type=str, help="The sim-explorer specification file.")
parser.add_argument("--info", action="store_true", help="Display the structure of the defined cases.")
parser.add_argument("--run", type=str, help="Run a single case.")
parser.add_argument("--Run", type=str, help="Run a case and all its sub-cases.")
args = parser.parse_args()
cases = Cases( args.cases)
print("ARGS", args)
if not isinstance(case, Cases):
print(f"Instantiation of {args.cases} not successfull")
if args.info is not None:
print(cases.info())
elif args.run is not None:
case = cases.case_by_name( args.run)
if not isinstance(case, Case):
print(f"Case {args.case} not found in {args.cases}")
case.run()
elif args.Run is not None:
case = cases.case_by_name( args.Run)
if not isinstance(case, Case):
print(f"Case {args.case} not found in {args.cases}")
for c in case.iter():
c.run()


if __name__ == "__main__":
cli_main()
5 changes: 5 additions & 0 deletions docs/source/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Change log
==========

v.0.1:
Basic version published on dnv-opensource

0 comments on commit 7a0e186

Please sign in to comment.