{"id":15893412,"url":"https://github.com/multimeric/argparseprompt","last_synced_at":"2025-03-20T12:34:20.723Z","repository":{"id":57411465,"uuid":"91532073","full_name":"multimeric/ArgparsePrompt","owner":"multimeric","description":"Wrapper for the built-in Argparse, allowing missing command-line arguments to be filled in by the user via interactive prompts","archived":false,"fork":false,"pushed_at":"2020-06-19T08:31:52.000Z","size":38,"stargazers_count":11,"open_issues_count":5,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-01T00:17:21.330Z","etag":null,"topics":["argparse","command-line","python"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/multimeric.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-17T04:02:43.000Z","updated_at":"2023-02-24T20:48:36.000Z","dependencies_parsed_at":"2022-08-27T19:11:50.464Z","dependency_job_id":null,"html_url":"https://github.com/multimeric/ArgparsePrompt","commit_stats":null,"previous_names":["melbournegenomics/argparseprompt"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FArgparsePrompt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FArgparsePrompt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FArgparsePrompt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FArgparsePrompt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/multimeric","download_url":"https://codeload.github.com/multimeric/ArgparsePrompt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244075567,"owners_count":20393979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["argparse","command-line","python"],"created_at":"2024-10-06T08:10:26.679Z","updated_at":"2025-03-20T12:34:20.441Z","avatar_url":"https://github.com/multimeric.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ArgparsePrompt\nArgparsePrompt is a wrapper for the built-in Argparse, allowing missing command-line arguments to be filled in by the\nuser via interactive prompts\n\n# Installation\nArgparsePrompt can be installed using pip:\n```bash\npip install argparse_prompt\n```\n\nNote that ArgparsePrompt is only compatible with Python 3.6 and higher, and does not support Python 2.X\n\n# Usage\n\n## Basic Usage\nThe only public interface of this module is the `PromptParser` class, which is a subclass of Python's \n[ArgumentParser](https://docs.python.org/3/library/argparse.html). Use this class in exactly the same way that you would\nuse ArgumentParser, except that, if any argument does not have a specified `default` value, and a value is not provided\nfor it on the commandline, the `PromptParser` will prompt for a value for this argument using `input()`, which is read \nfrom stdin.\n\nConsider the code below (taken from one of the unit tests):\n\n```python\nfrom argparse_prompt import PromptParser\n\nparser = PromptParser()\nparser.add_argument('--argument', '-a', help='An argument you could provide', default='foo')\nprint(parser.parse_args().argument)\n```\n\nIf you run this script with a value for `argument`, the parsing will run as normal:\n```\n$ python test/default_parser.py --argument 12\n12\n```\n\nHowever if you don't specify a value for `arg`, the parser will prompt you for one\n```\n$ python test/default_parser.py\nargument: An argument you could provide\n\u003e (foo) car\ncar\n```\n\n## Default Values\nSince this argument has a default value, you can also just hit enter and this value will be used automatically:\n```\npython test/default_parser.py\nargument: An argument you could provide\n\u003e (foo) \nfoo\n```\n\n## Type Checking\nYou can also specify a type for the argument in the normal way:\n\n```python\nfrom argparse_prompt import PromptParser\n\nparser = PromptParser()\nparser.add_argument('--argument', '-a', help='An argument you could provide', type=int)\nprint(parser.parse_args().argument)\n```\n\nIf you do, this type checking will be used for the value you enter at the prompt:\n```\n$ python test/typed_parser.py  \nargument: An argument you could provide\nabc\nArgument \"argument\" was given a value not of type \u003cclass 'int'\u003e\n```\n\n## Secure Values\nFor arguments that need to be secure, such as passwords, secret keys etc, you can use `secure=True` when defining your\nargument. This will cause whatever the user inputs for that field to be hidden from the terminal, in the same way that \n`git`, or `ssh` hides the password input.\n\nFor example:\n```python\nparser.add_argument('--password', '-p', help='A very secret password', secure=True)\n```\n\n\n## Situationally Disabling the Prompt\nIf you use the `prompt` argument to `add_argument`, parsing will be disabled:\n\n```python\nparser.add_argument('--argument', '-a', help='An argument you could provide', default='foo', prompt=False)\n```\n\nAlso, if you want to disable all prompting (for an automated script, for example), just set the `ARGPARSE_PROMPT_AUTO` to\na truthy value:\n```bash\nARGPARSE_PROMPT_AUTO=1 python test/default_parser.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultimeric%2Fargparseprompt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmultimeric%2Fargparseprompt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultimeric%2Fargparseprompt/lists"}