|
| 1 | +# ---------------------------------------------------------------------- |
| 2 | +# | |
| 3 | +# | CommandLineArguments.py |
| 4 | +# | |
| 5 | +# | David Brownell <db@DavidBrownell.com> |
| 6 | +# | 2024-06-12 13:20:05 |
| 7 | +# | |
| 8 | +# ---------------------------------------------------------------------- |
| 9 | +# | |
| 10 | +# | Copyright David Brownell 2024 |
| 11 | +# | Distributed under the MIT License. |
| 12 | +# | |
| 13 | +# ---------------------------------------------------------------------- |
| 14 | + |
| 15 | +import re |
| 16 | + |
| 17 | +from typing import Pattern |
| 18 | + |
| 19 | +import typer |
| 20 | + |
| 21 | + |
| 22 | +# ---------------------------------------------------------------------- |
| 23 | +def ToRegex( |
| 24 | + values: list[str], |
| 25 | +) -> list[Pattern]: |
| 26 | + expressions: list[Pattern] = [] |
| 27 | + |
| 28 | + for value in values: |
| 29 | + try: |
| 30 | + expressions.append(re.compile("^{}$".format(value))) |
| 31 | + except re.error as ex: |
| 32 | + raise typer.BadParameter( |
| 33 | + "The regular expression '{}' is not valid ({}).".format(value, ex) |
| 34 | + ) |
| 35 | + |
| 36 | + return expressions |
| 37 | + |
| 38 | + |
| 39 | +# ---------------------------------------------------------------------- |
| 40 | +input_filename_or_dirs_argument = typer.Argument( |
| 41 | + ..., exists=True, resolve_path=True, help="Input filename or directory." |
| 42 | +) |
| 43 | + |
| 44 | +ssd_option = typer.Option( |
| 45 | + "--ssd", |
| 46 | + help="Processes tasks in parallel to leverage the capabilities of solid-state-drives.", |
| 47 | +) |
| 48 | +ssd_option_default = False |
| 49 | + |
| 50 | +quiet_option = typer.Option("--quiet", help="Reduce the amount of information displayed.") |
| 51 | +quiet_option_default = False |
| 52 | + |
| 53 | +force_option = typer.Option( |
| 54 | + "--force", |
| 55 | + help="Ignore previous backup information and overwrite all data in the destination data store.", |
| 56 | +) |
| 57 | +force_option_default = False |
| 58 | + |
| 59 | +verbose_option = typer.Option("--verbose", help="Write verbose information to the terminal.") |
| 60 | +verbose_option_default = False |
| 61 | + |
| 62 | +debug_option = typer.Option("--debug", help="Write debug information to the terminal.") |
| 63 | +debug_option_default = False |
| 64 | + |
| 65 | +file_include_option = typer.Option( |
| 66 | + "--file-include", |
| 67 | + callback=ToRegex, |
| 68 | + help="Regular expression (based on a posix path) used to include files and/or directories when preserving content.", |
| 69 | +) |
| 70 | +file_include_option_default: list[str] = [] |
| 71 | + |
| 72 | +file_exclude_option = typer.Option( |
| 73 | + "--file-exclude", |
| 74 | + callback=ToRegex, |
| 75 | + help="Regular expression (based on a posix path) used to exclude files and/or directories when preserving content.", |
| 76 | +) |
| 77 | +file_exclude_option_default: list[str] = [] |
0 commit comments