| Total Complexity | 5 |
| Total Lines | 67 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import argparse |
||
| 2 | import functools |
||
| 3 | |||
| 4 | from verboselib.version import VERSION |
||
| 5 | |||
| 6 | from .utils import print_out |
||
| 7 | |||
| 8 | from .command_compile import CompileCommand |
||
| 9 | from .command_extract import ExtractCommand |
||
| 10 | |||
| 11 | |||
| 12 | def show_version() -> None: |
||
| 13 | print_out(f"verboselib {VERSION}") |
||
| 14 | |||
| 15 | |||
| 16 | def make_parser() -> argparse.Namespace: |
||
| 17 | parser = argparse.ArgumentParser( |
||
| 18 | description="run a verboselib command", |
||
| 19 | add_help=True, |
||
| 20 | ) |
||
| 21 | parser.add_argument( |
||
| 22 | "-V", "--version", |
||
| 23 | dest="show_version", |
||
| 24 | action="store_true", |
||
| 25 | help="show version of verboselib and exit" |
||
| 26 | ) |
||
| 27 | |||
| 28 | subparsers = parser.add_subparsers( |
||
| 29 | title="subcommands", |
||
| 30 | dest="command_name", |
||
| 31 | ) |
||
| 32 | |||
| 33 | extract_cmd_parser = ExtractCommand.make_parser( |
||
| 34 | factory=functools.partial( |
||
| 35 | subparsers.add_parser, |
||
| 36 | name=ExtractCommand.name, |
||
| 37 | aliases=ExtractCommand.aliases, |
||
| 38 | ), |
||
| 39 | ) |
||
| 40 | extract_cmd_parser.set_defaults(executor_factory=ExtractCommand.make_executor) |
||
| 41 | |||
| 42 | compile_cmd_parser = CompileCommand.make_parser( |
||
| 43 | factory=functools.partial( |
||
| 44 | subparsers.add_parser, |
||
| 45 | name=CompileCommand.name, |
||
| 46 | aliases=CompileCommand.aliases, |
||
| 47 | ), |
||
| 48 | ) |
||
| 49 | compile_cmd_parser.set_defaults(executor_factory=CompileCommand.make_executor) |
||
| 50 | |||
| 51 | return parser |
||
| 52 | |||
| 53 | |||
| 54 | def main(): |
||
| 55 | parser = make_parser() |
||
| 56 | args = parser.parse_args() |
||
| 57 | |||
| 58 | if args.show_version: |
||
| 59 | show_version() |
||
| 60 | return |
||
| 61 | |||
| 62 | if hasattr(args, "executor_factory"): |
||
| 63 | executor = args.executor_factory(args) |
||
| 64 | executor() |
||
| 65 | else: |
||
| 66 | parser.print_help() |
||
| 67 |