Skip to content

Commit

Permalink
build(retrocookie): reflect updates to source template from generated…
Browse files Browse the repository at this point in the history
… project 'science-institute_brain-lab'
  • Loading branch information
Joseph Burling committed Apr 22, 2022
1 parent a1c0f47 commit aecdc6a
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""Module-level command-line interface
This serves as an example command-line interface for the main package module.
Example:
Usage as a console entrypoint:
{{cookiecutter.__pkg_import_name}} --help
{{cookiecutter.__pkg_import_name}} --version
Usage as a script:
python -m {{cookiecutter.__pkg_import_name}}
Usage from python:
from {{cookiecutter.__pkg_import_name}} import main; main(...)
"""

import argparse
import sys
from typing import Any, Sequence

from {{cookiecutter.__pkg_import_name}} import version


def parse_args(args: Sequence[str]) -> argparse.Namespace:
"""_Parse command line parameters_
Args:
args (list[str]):
Command line parameters as list of strings.
(example `["--help"]`)
Returns:
A Namespace of command line parameters.
"""

class ArgumentDefaultsRawDescriptionHelpFormatter(
argparse.ArgumentDefaultsHelpFormatter,
argparse.RawDescriptionHelpFormatter,
argparse.MetavarTypeHelpFormatter,
):
"""Combination of different formatters"""

pass

parser = argparse.ArgumentParser(
prog="{{cookiecutter.__pkg_import_name}}",
epilog=__doc__,
formatter_class=ArgumentDefaultsRawDescriptionHelpFormatter,
)

parser.add_argument(
"--version",
action="version",
version=f"%(prog)s v{version}",
)

parsed_args = parser.parse_args(args)

return parsed_args


def main(**kwargs: Any) -> None:
"""_Operate on cli args_."""
print("main module operations here.")


def cli() -> None:
"""_Calls [`__main__.main`][{{cookiecutter.__pkg_import_name}}.__main__.main], passing the cli
arguments extracted from `sys.argv`_.
This function can be used as entry point to create console scripts on package
install.
"""

args = parse_args(sys.argv[1:])
main(**vars(args))


if __name__ == "__main__":
cli()
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@
"-i",
"'!src/{{cookiecutter.__pkg_import_name}}/__init__.py'",
"-i",
"'!src/{{cookiecutter.__pkg_import_name}}/__main__.py'",
"-i",
"'!src/{{cookiecutter.__pkg_import_name}}/entrypoint.py'",
"${workspaceFolder}"
],
Expand Down

0 comments on commit aecdc6a

Please sign in to comment.