Coverage for src/mars_mcd_helper/cli.py : 100.00%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Why does this file exist, and why not put this in `__main__`?
2#
3# You might be tempted to import things from `__main__` later,
4# but that will cause problems: the code will get executed twice:
5#
6# - When you run `python -m mars_mcd_helper` python will execute
7# `__main__.py` as a script. That means there won't be any
8# `mars_mcd_helper.__main__` in `sys.modules`.
9# - When you import `__main__` it will get executed again (as a module) because
10# there's no `mars_mcd_helper.__main__` in `sys.modules`.
12"""Module that contains the command line application."""
14import argparse
15from typing import List, Optional
18def get_parser() -> argparse.ArgumentParser:
19 """
20 Return the CLI argument parser.
22 Returns:
23 An argparse parser.
24 """
25 return argparse.ArgumentParser(prog="mars-mcd-helper")
28def main(args: Optional[List[str]] = None) -> int:
29 """
30 Run the main program.
32 This function is executed when you type `mars-mcd-helper` or `python -m mars_mcd_helper`.
34 Arguments:
35 args: Arguments passed from the command line.
37 Returns:
38 An exit code.
39 """
40 parser = get_parser()
41 opts = parser.parse_args(args=args)
42 print(opts) # noqa: WPS421 (side-effect in main is fine)
43 return 0