Constructs and returns the argument parser.
(prog_name)
| 14 | |
| 15 | |
| 16 | def get_parser(prog_name): |
| 17 | """Constructs and returns the argument parser.""" |
| 18 | parser = argparse.ArgumentParser( |
| 19 | prog=prog_name, |
| 20 | description="Translate strings in JSON using the DeepL API " |
| 21 | "(https://www.deepl.com/docs-api).", |
| 22 | epilog="If you encounter issues while using this example, please " |
| 23 | "report them at https://github.com/DeepLcom/deepl-python/issues", |
| 24 | ) |
| 25 | |
| 26 | parser.add_argument( |
| 27 | "--auth-key", |
| 28 | default=None, |
| 29 | help="authentication key as given in your DeepL account; the " |
| 30 | f"{env_auth_key} environment variable is used as secondary fallback", |
| 31 | ) |
| 32 | parser.add_argument( |
| 33 | "--server-url", |
| 34 | default=None, |
| 35 | metavar="URL", |
| 36 | help=f"alternative server URL for testing; the {env_server_url} " |
| 37 | f"environment variable may be used as secondary fallback", |
| 38 | ) |
| 39 | parser.add_argument( |
| 40 | "--to", |
| 41 | "--target-lang", |
| 42 | dest="target_lang", |
| 43 | required=True, |
| 44 | help="language into which the JSON strings should be translated", |
| 45 | ) |
| 46 | parser.add_argument( |
| 47 | "--from", |
| 48 | "--source-lang", |
| 49 | dest="source_lang", |
| 50 | help="language of the JSON strings to be translated", |
| 51 | ) |
| 52 | parser.add_argument( |
| 53 | "json", |
| 54 | nargs="+", |
| 55 | type=str, |
| 56 | help="JSON to be translated. Wrap JSON in quotes to prevent " |
| 57 | "the shell from splitting on whitespace.", |
| 58 | ) |
| 59 | |
| 60 | return parser |
| 61 | |
| 62 | |
| 63 | def main(): |