Skip to content

Commit

Permalink
add --docstring/--no-docstring option to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
mcflugen committed Jan 15, 2024
1 parent 9fd975b commit 41e620c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/bmipy/_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,29 @@
from bmipy._version import __version__


def main(args: tuple[str, ...] | None = None) -> int:
def main(argv: tuple[str, ...] | None = None) -> int:
"""Render a template BMI implementation in Python for class NAME."""
parser = argparse.ArgumentParser()
parser.add_argument("--version", action="version", version=f"bmipy {__version__}")
parser.add_argument("name")

parsed_args = parser.parse_args(args)
group = parser.add_mutually_exclusive_group()
group.add_argument(
"--docstring",
action="store_true",
dest="docstring",
default=True,
help="Add docstrings to the generated methods",
)
group.add_argument("--no-docstring", action="store_false", dest="docstring")

if parsed_args.name.isidentifier() and not keyword.iskeyword(parsed_args.name):
print(Template(parsed_args.name).render())
args = parser.parse_args(argv)

if args.name.isidentifier() and not keyword.iskeyword(args.name):
print(Template(args.name).render(with_docstring=args.docstring))
else:
print(
f"πŸ’₯ πŸ’” πŸ’₯ {parsed_args.name!r} is not a valid class name in Python",
f"πŸ’₯ πŸ’” πŸ’₯ {args.name!r} is not a valid class name in Python",
file=sys.stderr,
)
return 1
Expand Down

0 comments on commit 41e620c

Please sign in to comment.