![Lines of code](https://sloc.xyz/github/sandialabs/reverse_argparse/?category=code)
[![codecov](https://codecov.io/gh/sandialabs/reverse_argparse/branch/master/graph/badge.svg?token=FmDStZ6FVR)](https://codecov.io/gh/sandialabs/reverse_argparse)
[![CodeFactor](https://www.codefactor.io/repository/github/sandialabs/reverse_argparse/badge/master)](https://www.codefactor.io/repository/github/sandialabs/reverse_argparse/overview/master)
[![CodeQL](https://github.com/sandialabs/reverse_argparse/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/sandialabs/reverse_argparse/actions/workflows/github-code-scanning/codeql)
[![Conda Version](https://img.shields.io/conda/v/conda-forge/reverse-argparse?label=conda-forge)](https://anaconda.org/conda-forge/reverse-argparse)
![Conda Downloads](https://img.shields.io/conda/d/conda-forge/reverse-argparse?label=conda-forge%20downloads)
[![Continuous Integration](https://github.com/sandialabs/reverse_argparse/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/sandialabs/reverse_argparse/actions/workflows/continuous-integration.yml)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
[![GitHub contributors](https://img.shields.io/github/contributors/sandialabs/reverse_argparse.svg)](https://github.com/sandialabs/reverse_argparse/graphs/contributors)
[![Documentation Status](https://readthedocs.org/projects/reverse-argparse/badge/?version=latest)](https://reverse-argparse.readthedocs.io/en/latest/?badge=latest)
[![License](https://anaconda.org/conda-forge/reverse-argparse/badges/license.svg)](LICENSE.md)
[![Merged PRs](https://img.shields.io/github/issues-pr-closed-raw/sandialabs/reverse_argparse.svg?label=merged+PRs)](https://github.com/sandialabs/reverse_argparse/pulls?q=is:pr+is:merged)
[![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/7632/badge)](https://bestpractices.coreinfrastructure.org/projects/7632)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/sandialabs/reverse_argparse/badge)](https://securityscorecards.dev/viewer/?uri=github.com/sandialabs/reverse_argparse)
![Platforms](https://anaconda.org/conda-forge/reverse-argparse/badges/platforms.svg)
[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)
[![pre-commit.ci Status](https://results.pre-commit.ci/badge/github/sandialabs/reverse_argparse/master.svg)](https://results.pre-commit.ci/latest/github/sandialabs/reverse_argparse/master)
[![PyPI - Version](https://img.shields.io/pypi/v/reverse-argparse?label=PyPI)](https://pypi.org/project/reverse-argparse/)
![PyPI - Downloads](https://img.shields.io/pypi/dm/reverse-argparse?label=PyPI%20downloads)
![Python Version](https://img.shields.io/badge/Python-3.9|3.10|3.11|3.12|3.13-blue.svg)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
# reverse_argparse
Whereas [`argparse`][argparse] is concerned with taking a bunch of command line
arguments and parsing them, this package is intended to do the opposite; that
is, it'll take the parsed arguments and create the effective command line
invocation of the script that generated them. The motivation is to be able to
tell users exactly what was used for all of the options, taking into
consideration any defaults and other transformations that might've been applied
in the midst of parsing, such that users are able to reproduce a prior run of a
script exactly.
[argparse]: https://docs.python.org/3/library/argparse.html
## Installation
To get up and running with `reverse_argparse`, simply:
```bash
python3 -m pip install reverse-argparse
```
## Usage
Once the package is installed, you can simply
```python
from argparse import ArgumentParser
from reverse_argparse import ReverseArgumentParser
# Parse the command line arguments.
parser = ArgumentParser()
# Build out the parser however you like.
args = parser.parse_args()
# Optionally post-process any `args`, as needed.
# Do whatever you need to in the script.
# Wrap things up.
print("This script executed the following:")
unparser = ReverseArgumentParser(parser, args)
print(unparser.get_pretty_command_line_invocation())
```
For more detailed usage and API information, please see
[our documentation][readthedocs].
[readthedocs]: https://reverse-argparse.readthedocs.io
## Where to Get Help
If you're having trouble with `reverse_argparse`, or just want to ask a
question, head on over to [our issue board][issues]. If a quick search doesn't
yield what you're looking for, feel free to file an issue.
[issues]: https://github.com/sandialabs/reverse_argparse/issues
## Contributing
If you're interested in contributing to the development of `reverse_argparse`,
we'd love to have your help :grinning: Check out our
[contributing guidelines](CONTRIBUTING.md) for how to get started.
[Past contributors][contributors] include:
* [@jmgate](https://github.com/jmgate)
[contributors]: https://github.com/sandialabs/reverse_argparse/graphs/contributors
## License & Copyright
See [LICENSE.md](LICENSE.md) and [COPYRIGHT.md](COPYRIGHT.md).
## Credits
Special thanks to [@mjsumpter][mjsumpter] for contributing to a prior iteration
of this concept, and to [the GMS project][gms] for investing in the development
of this package.
[mjsumpter]: https://github.com/mjsumpter
[gms]: https://github.com/SNL-GMS/GMS-PI25
Raw data
{
"_id": null,
"home_page": "https://github.com/sandialabs/reverse_argparse",
"name": "reverse-argparse",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "argparse, argument, parse, parsing, command line",
"author": "Jason M. Gates",
"author_email": "jmgate@sandia.gov",
"download_url": "https://files.pythonhosted.org/packages/d1/19/34eae915a3e443209dd061c7e6500e563017ab8aa106e8c82484bfce3891/reverse_argparse-2.0.2.tar.gz",
"platform": null,
"description": "![Lines of code](https://sloc.xyz/github/sandialabs/reverse_argparse/?category=code)\n[![codecov](https://codecov.io/gh/sandialabs/reverse_argparse/branch/master/graph/badge.svg?token=FmDStZ6FVR)](https://codecov.io/gh/sandialabs/reverse_argparse)\n[![CodeFactor](https://www.codefactor.io/repository/github/sandialabs/reverse_argparse/badge/master)](https://www.codefactor.io/repository/github/sandialabs/reverse_argparse/overview/master)\n[![CodeQL](https://github.com/sandialabs/reverse_argparse/actions/workflows/github-code-scanning/codeql/badge.svg)](https://github.com/sandialabs/reverse_argparse/actions/workflows/github-code-scanning/codeql)\n[![Conda Version](https://img.shields.io/conda/v/conda-forge/reverse-argparse?label=conda-forge)](https://anaconda.org/conda-forge/reverse-argparse)\n![Conda Downloads](https://img.shields.io/conda/d/conda-forge/reverse-argparse?label=conda-forge%20downloads)\n[![Continuous Integration](https://github.com/sandialabs/reverse_argparse/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/sandialabs/reverse_argparse/actions/workflows/continuous-integration.yml)\n[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)\n[![GitHub contributors](https://img.shields.io/github/contributors/sandialabs/reverse_argparse.svg)](https://github.com/sandialabs/reverse_argparse/graphs/contributors)\n[![Documentation Status](https://readthedocs.org/projects/reverse-argparse/badge/?version=latest)](https://reverse-argparse.readthedocs.io/en/latest/?badge=latest)\n[![License](https://anaconda.org/conda-forge/reverse-argparse/badges/license.svg)](LICENSE.md)\n[![Merged PRs](https://img.shields.io/github/issues-pr-closed-raw/sandialabs/reverse_argparse.svg?label=merged+PRs)](https://github.com/sandialabs/reverse_argparse/pulls?q=is:pr+is:merged)\n[![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/7632/badge)](https://bestpractices.coreinfrastructure.org/projects/7632)\n[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/sandialabs/reverse_argparse/badge)](https://securityscorecards.dev/viewer/?uri=github.com/sandialabs/reverse_argparse)\n![Platforms](https://anaconda.org/conda-forge/reverse-argparse/badges/platforms.svg)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)\n[![pre-commit.ci Status](https://results.pre-commit.ci/badge/github/sandialabs/reverse_argparse/master.svg)](https://results.pre-commit.ci/latest/github/sandialabs/reverse_argparse/master)\n[![PyPI - Version](https://img.shields.io/pypi/v/reverse-argparse?label=PyPI)](https://pypi.org/project/reverse-argparse/)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/reverse-argparse?label=PyPI%20downloads)\n![Python Version](https://img.shields.io/badge/Python-3.9|3.10|3.11|3.12|3.13-blue.svg)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n\n# reverse_argparse\n\nWhereas [`argparse`][argparse] is concerned with taking a bunch of command line\narguments and parsing them, this package is intended to do the opposite; that\nis, it'll take the parsed arguments and create the effective command line\ninvocation of the script that generated them. The motivation is to be able to\ntell users exactly what was used for all of the options, taking into\nconsideration any defaults and other transformations that might've been applied\nin the midst of parsing, such that users are able to reproduce a prior run of a\nscript exactly.\n\n[argparse]: https://docs.python.org/3/library/argparse.html\n\n## Installation\n\nTo get up and running with `reverse_argparse`, simply:\n```bash\npython3 -m pip install reverse-argparse\n```\n\n## Usage\n\nOnce the package is installed, you can simply\n```python\nfrom argparse import ArgumentParser\n\nfrom reverse_argparse import ReverseArgumentParser\n\n# Parse the command line arguments.\nparser = ArgumentParser()\n# Build out the parser however you like.\nargs = parser.parse_args()\n# Optionally post-process any `args`, as needed.\n\n# Do whatever you need to in the script.\n\n# Wrap things up.\nprint(\"This script executed the following:\")\nunparser = ReverseArgumentParser(parser, args)\nprint(unparser.get_pretty_command_line_invocation())\n```\n\nFor more detailed usage and API information, please see\n[our documentation][readthedocs].\n\n[readthedocs]: https://reverse-argparse.readthedocs.io\n\n## Where to Get Help\n\nIf you're having trouble with `reverse_argparse`, or just want to ask a\nquestion, head on over to [our issue board][issues]. If a quick search doesn't\nyield what you're looking for, feel free to file an issue.\n\n[issues]: https://github.com/sandialabs/reverse_argparse/issues\n\n## Contributing\n\nIf you're interested in contributing to the development of `reverse_argparse`,\nwe'd love to have your help :grinning: Check out our\n[contributing guidelines](CONTRIBUTING.md) for how to get started.\n[Past contributors][contributors] include:\n* [@jmgate](https://github.com/jmgate)\n\n[contributors]: https://github.com/sandialabs/reverse_argparse/graphs/contributors\n\n## License & Copyright\n\nSee [LICENSE.md](LICENSE.md) and [COPYRIGHT.md](COPYRIGHT.md).\n\n## Credits\n\nSpecial thanks to [@mjsumpter][mjsumpter] for contributing to a prior iteration\nof this concept, and to [the GMS project][gms] for investing in the development\nof this package.\n\n[mjsumpter]: https://github.com/mjsumpter\n[gms]: https://github.com/SNL-GMS/GMS-PI25\n\n",
"bugtrack_url": null,
"license": "LICENSE.md",
"summary": "Generate the effective command line invocation for a script.",
"version": "2.0.2",
"project_urls": {
"CI": "https://github.com/sandialabs/reverse_argparse/actions",
"Documentation": "https://reverse-argparse.readthedocs.io",
"Homepage": "https://github.com/sandialabs/reverse_argparse",
"Issues": "https://github.com/sandialabs/reverse_argparse/issues",
"Repository": "https://github.com/sandialabs/reverse_argparse"
},
"split_keywords": [
"argparse",
" argument",
" parse",
" parsing",
" command line"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b1fade3e7c3be67c7b6a48a3d1a4c51706212127699e099d09d749d1879b3a58",
"md5": "bfec93829810304af591477b28dcc753",
"sha256": "e0045208f123367671224455a3bac050bf76ad1f0e3475e6877c3338e2b6837a"
},
"downloads": -1,
"filename": "reverse_argparse-2.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bfec93829810304af591477b28dcc753",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 9479,
"upload_time": "2024-12-17T17:49:30",
"upload_time_iso_8601": "2024-12-17T17:49:30.182809Z",
"url": "https://files.pythonhosted.org/packages/b1/fa/de3e7c3be67c7b6a48a3d1a4c51706212127699e099d09d749d1879b3a58/reverse_argparse-2.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d11934eae915a3e443209dd061c7e6500e563017ab8aa106e8c82484bfce3891",
"md5": "8218db036b8572d281516f0c90a59cb0",
"sha256": "0a78032d488ca05a5a2682635067132a90a373d841808c2dae82de0411a9e2aa"
},
"downloads": -1,
"filename": "reverse_argparse-2.0.2.tar.gz",
"has_sig": false,
"md5_digest": "8218db036b8572d281516f0c90a59cb0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 10407,
"upload_time": "2024-12-17T17:49:32",
"upload_time_iso_8601": "2024-12-17T17:49:32.825029Z",
"url": "https://files.pythonhosted.org/packages/d1/19/34eae915a3e443209dd061c7e6500e563017ab8aa106e8c82484bfce3891/reverse_argparse-2.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-17 17:49:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sandialabs",
"github_project": "reverse_argparse",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [],
"lcname": "reverse-argparse"
}