Hide keyboard shortcuts

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`. 

11 

12"""Module that contains the command line application.""" 

13 

14import argparse 

15from typing import List, Optional 

16 

17 

18def get_parser() -> argparse.ArgumentParser: 

19 """ 

20 Return the CLI argument parser. 

21 

22 Returns: 

23 An argparse parser. 

24 """ 

25 return argparse.ArgumentParser(prog="mars-mcd-helper") 

26 

27 

28def main(args: Optional[List[str]] = None) -> int: 

29 """ 

30 Run the main program. 

31 

32 This function is executed when you type `mars-mcd-helper` or `python -m mars_mcd_helper`. 

33 

34 Arguments: 

35 args: Arguments passed from the command line. 

36 

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