click-option-group


Nameclick-option-group JSON
Version 0.5.6 PyPI version JSON
download
home_pagehttps://github.com/click-contrib/click-option-group
SummaryOption groups missing in Click
upload_time2023-06-09 22:22:36
maintainer
docs_urlNone
authorEugene Prilepin
requires_python>=3.6,<4
licenseBSD-3-Clause
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # click-option-group

[![PyPI version](https://img.shields.io/pypi/v/click-option-group.svg)](https://pypi.python.org/pypi/click-option-group)
[![Build status](https://travis-ci.org/click-contrib/click-option-group.svg?branch=master)](https://travis-ci.org/click-contrib/click-option-group)
[![Coverage Status](https://coveralls.io/repos/github/click-contrib/click-option-group/badge.svg?branch=master)](https://coveralls.io/github/click-contrib/click-option-group?branch=master)
![Supported Python versions](https://img.shields.io/pypi/pyversions/click-option-group.svg)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)


**click-option-group** is a Click-extension package that adds option groups 
missing in [Click](https://github.com/pallets/click/).

## Aim and Motivation

Click is a package for creating powerful and beautiful command line interfaces (CLI) in Python, 
but it has no the functionality for creating option groups.

Option groups are convenient mechanism for logical structuring CLI, also it allows you to set 
the specific behavior and set the relationship among grouped options (mutually exclusive options for example). 
Moreover, [argparse](https://docs.python.org/3/library/argparse.html) stdlib package contains this 
functionality out of the box.

At the same time, many Click users need this functionality.
You can read interesting discussions about it in the following issues:

* [issue 257](https://github.com/pallets/click/issues/257)
* [issue 373](https://github.com/pallets/click/issues/373)
* [issue 509](https://github.com/pallets/click/issues/509)
* [issue 1137](https://github.com/pallets/click/issues/1137)

The aim of this package is to provide group options with extensible functionality 
using canonical and clean API (Click-like API as far as possible).

## Quickstart

### Installing 

Install and update using pip:

```bash
pip install -U click-option-group
```

### A Simple Example

Here is a simple example how to use option groups in your Click-based CLI.
Just use `optgroup` for declaring option groups by decorating 
your command function in Click-like API style.

```python
# app.py

import click
from click_option_group import optgroup, RequiredMutuallyExclusiveOptionGroup

@click.command()
@optgroup.group('Server configuration', 
                help='The configuration of some server connection')
@optgroup.option('-h', '--host', default='localhost', help='Server host name')
@optgroup.option('-p', '--port', type=int, default=8888, help='Server port')
@optgroup.option('-n', '--attempts', type=int, default=3, help='The number of connection attempts')
@optgroup.option('-t', '--timeout', type=int, default=30, help='The server response timeout')
@optgroup.group('Input data sources', cls=RequiredMutuallyExclusiveOptionGroup, 
                help='The sources of the input data')
@optgroup.option('--tsv-file', type=click.File(), help='CSV/TSV input data file')
@optgroup.option('--json-file', type=click.File(), help='JSON input data file')
@click.option('--debug/--no-debug', default=False, help='Debug flag')
def cli(**params):
    print(params)

if __name__ == '__main__':
    cli()
```

```bash
$ python app.py --help
Usage: app.py [OPTIONS]

Options:
  Server configuration:           The configuration of some server connection
    -h, --host TEXT               Server host name
    -p, --port INTEGER            Server port
    -n, --attempts INTEGER        The number of connection attempts
    -t, --timeout INTEGER         The server response timeout
  Input data sources: [mutually_exclusive, required]
                                  The sources of the input data
    --tsv-file FILENAME           CSV/TSV input data file
    --json-file FILENAME          JSON input data file
  --debug / --no-debug            Debug flag
  --help                          Show this message and exit.
```

## Documentation

https://click-option-group.readthedocs.io

# Changelog

## v0.5.6 (09.06.2023)

* Add `optgroup.help_option` decorator to add help option to the group (PR [#50](https://github.com/click-contrib/click-option-group/pull/50))
* Use GitHub Actions instead of Travis CI for CI
* Delete tox runner
* Add Python 3.11 to the setup classifiers

## v0.5.5 (12.10.2022)

* Add `tests/` directory to tarball
* Add `tests_cov` extra dependencies for testing with coverage

## v0.5.4 (12.10.2022)

* Move frame gathering into error code path (PR [#34](https://github.com/click-contrib/click-option-group/pull/34))
* Fix typos (PR [#37](https://github.com/click-contrib/click-option-group/pull/37))
* PEP 561 support (PR [#42](https://github.com/click-contrib/click-option-group/pull/42))
* Update docs dependencies and Travis CI Python version matrix (PR [#43](https://github.com/click-contrib/click-option-group/pull/43))

## v0.5.3 (14.05.2021)

* Update Click dependency version to `<9` (Issue [#33](https://github.com/click-contrib/click-option-group/issues/33))

## v0.5.2 (28.11.2020)

* Do not use default option group name. An empty group name will not be displayed
* Slightly edited error messages
* All arguments except `name` in `optgroup` decorator must be keyword-only

## v0.5.1 (14.06.2020)

* Fix incompatibility with autocomplete: out of the box Click completion and click-repl (Issue [#14](https://github.com/click-contrib/click-option-group/issues/14))

## v0.5.0 (10.06.2020)

* Add `AllOptionGroup` class: all options from the group must be set or none must be set (PR [#13](https://github.com/click-contrib/click-option-group/pull/13))
* Fix type hints
* Update docs

## v0.4.0 (18.05.2020)

* Support multi-layer wrapped functions (PR [#10](https://github.com/click-contrib/click-option-group/pull/10))
* Fix flake8 issues

## v0.3.1

* Add `hidden=True` to `_GroupTitleFakeOption` as a temporary workaroud for issue [#4](https://github.com/click-contrib/click-option-group/issues/4)

## v0.3.0
* Add support for hidden options inside groups (PR [#2](https://github.com/click-contrib/click-option-group/pull/2))

## v0.2.3
* Transfer the repo to click-contrib organisation

## v0.2.2
* Add true lineno in warning when declaring empty option group
* Update readme

## v0.2.1
* Use RuntimeWarning and stacklevel 2 when declaring empty option group
* Update readme

## v0.2.0
* Implement `RequiredMutuallyExclusiveOptionGroup` class instead of `required` argument for `MutuallyExclusiveOptionGroup`
* Add tests with 100% coverage
* Update readme

## v0.1.0
* First public release

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/click-contrib/click-option-group",
    "name": "click-option-group",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6,<4",
    "maintainer_email": "",
    "keywords": "",
    "author": "Eugene Prilepin",
    "author_email": "esp.home@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e7/b8/91054601a2e05fd9060cb1baf56be5b24145817b059e078669e1099529c7/click-option-group-0.5.6.tar.gz",
    "platform": null,
    "description": "# click-option-group\n\n[![PyPI version](https://img.shields.io/pypi/v/click-option-group.svg)](https://pypi.python.org/pypi/click-option-group)\n[![Build status](https://travis-ci.org/click-contrib/click-option-group.svg?branch=master)](https://travis-ci.org/click-contrib/click-option-group)\n[![Coverage Status](https://coveralls.io/repos/github/click-contrib/click-option-group/badge.svg?branch=master)](https://coveralls.io/github/click-contrib/click-option-group?branch=master)\n![Supported Python versions](https://img.shields.io/pypi/pyversions/click-option-group.svg)\n[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)\n\n\n**click-option-group** is a Click-extension package that adds option groups \nmissing in [Click](https://github.com/pallets/click/).\n\n## Aim and Motivation\n\nClick is a package for creating powerful and beautiful command line interfaces (CLI) in Python, \nbut it has no the functionality for creating option groups.\n\nOption groups are convenient mechanism for logical structuring CLI, also it allows you to set \nthe specific behavior and set the relationship among grouped options (mutually exclusive options for example). \nMoreover, [argparse](https://docs.python.org/3/library/argparse.html) stdlib package contains this \nfunctionality out of the box.\n\nAt the same time, many Click users need this functionality.\nYou can read interesting discussions about it in the following issues:\n\n* [issue 257](https://github.com/pallets/click/issues/257)\n* [issue 373](https://github.com/pallets/click/issues/373)\n* [issue 509](https://github.com/pallets/click/issues/509)\n* [issue 1137](https://github.com/pallets/click/issues/1137)\n\nThe aim of this package is to provide group options with extensible functionality \nusing canonical and clean API (Click-like API as far as possible).\n\n## Quickstart\n\n### Installing \n\nInstall and update using pip:\n\n```bash\npip install -U click-option-group\n```\n\n### A Simple Example\n\nHere is a simple example how to use option groups in your Click-based CLI.\nJust use `optgroup` for declaring option groups by decorating \nyour command function in Click-like API style.\n\n```python\n# app.py\n\nimport click\nfrom click_option_group import optgroup, RequiredMutuallyExclusiveOptionGroup\n\n@click.command()\n@optgroup.group('Server configuration', \n                help='The configuration of some server connection')\n@optgroup.option('-h', '--host', default='localhost', help='Server host name')\n@optgroup.option('-p', '--port', type=int, default=8888, help='Server port')\n@optgroup.option('-n', '--attempts', type=int, default=3, help='The number of connection attempts')\n@optgroup.option('-t', '--timeout', type=int, default=30, help='The server response timeout')\n@optgroup.group('Input data sources', cls=RequiredMutuallyExclusiveOptionGroup, \n                help='The sources of the input data')\n@optgroup.option('--tsv-file', type=click.File(), help='CSV/TSV input data file')\n@optgroup.option('--json-file', type=click.File(), help='JSON input data file')\n@click.option('--debug/--no-debug', default=False, help='Debug flag')\ndef cli(**params):\n    print(params)\n\nif __name__ == '__main__':\n    cli()\n```\n\n```bash\n$ python app.py --help\nUsage: app.py [OPTIONS]\n\nOptions:\n  Server configuration:           The configuration of some server connection\n    -h, --host TEXT               Server host name\n    -p, --port INTEGER            Server port\n    -n, --attempts INTEGER        The number of connection attempts\n    -t, --timeout INTEGER         The server response timeout\n  Input data sources: [mutually_exclusive, required]\n                                  The sources of the input data\n    --tsv-file FILENAME           CSV/TSV input data file\n    --json-file FILENAME          JSON input data file\n  --debug / --no-debug            Debug flag\n  --help                          Show this message and exit.\n```\n\n## Documentation\n\nhttps://click-option-group.readthedocs.io\n\n# Changelog\n\n## v0.5.6 (09.06.2023)\n\n* Add `optgroup.help_option` decorator to add help option to the group (PR [#50](https://github.com/click-contrib/click-option-group/pull/50))\n* Use GitHub Actions instead of Travis CI for CI\n* Delete tox runner\n* Add Python 3.11 to the setup classifiers\n\n## v0.5.5 (12.10.2022)\n\n* Add `tests/` directory to tarball\n* Add `tests_cov` extra dependencies for testing with coverage\n\n## v0.5.4 (12.10.2022)\n\n* Move frame gathering into error code path (PR [#34](https://github.com/click-contrib/click-option-group/pull/34))\n* Fix typos (PR [#37](https://github.com/click-contrib/click-option-group/pull/37))\n* PEP 561 support (PR [#42](https://github.com/click-contrib/click-option-group/pull/42))\n* Update docs dependencies and Travis CI Python version matrix (PR [#43](https://github.com/click-contrib/click-option-group/pull/43))\n\n## v0.5.3 (14.05.2021)\n\n* Update Click dependency version to `<9` (Issue [#33](https://github.com/click-contrib/click-option-group/issues/33))\n\n## v0.5.2 (28.11.2020)\n\n* Do not use default option group name. An empty group name will not be displayed\n* Slightly edited error messages\n* All arguments except `name` in `optgroup` decorator must be keyword-only\n\n## v0.5.1 (14.06.2020)\n\n* Fix incompatibility with autocomplete: out of the box Click completion and click-repl (Issue [#14](https://github.com/click-contrib/click-option-group/issues/14))\n\n## v0.5.0 (10.06.2020)\n\n* Add `AllOptionGroup` class: all options from the group must be set or none must be set (PR [#13](https://github.com/click-contrib/click-option-group/pull/13))\n* Fix type hints\n* Update docs\n\n## v0.4.0 (18.05.2020)\n\n* Support multi-layer wrapped functions (PR [#10](https://github.com/click-contrib/click-option-group/pull/10))\n* Fix flake8 issues\n\n## v0.3.1\n\n* Add `hidden=True` to `_GroupTitleFakeOption` as a temporary workaroud for issue [#4](https://github.com/click-contrib/click-option-group/issues/4)\n\n## v0.3.0\n* Add support for hidden options inside groups (PR [#2](https://github.com/click-contrib/click-option-group/pull/2))\n\n## v0.2.3\n* Transfer the repo to click-contrib organisation\n\n## v0.2.2\n* Add true lineno in warning when declaring empty option group\n* Update readme\n\n## v0.2.1\n* Use RuntimeWarning and stacklevel 2 when declaring empty option group\n* Update readme\n\n## v0.2.0\n* Implement `RequiredMutuallyExclusiveOptionGroup` class instead of `required` argument for `MutuallyExclusiveOptionGroup`\n* Add tests with 100% coverage\n* Update readme\n\n## v0.1.0\n* First public release\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Option groups missing in Click",
    "version": "0.5.6",
    "project_urls": {
        "Code": "https://github.com/click-contrib/click-option-group",
        "Documentation": "https://click-option-group.readthedocs.io",
        "Homepage": "https://github.com/click-contrib/click-option-group",
        "Issue tracker": "https://github.com/click-contrib/click-option-group/issues"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "af7581ea958bc0f7e410257cb2a42531b93a7695a31930cde87192c010a52c50",
                "md5": "7d18e8049b993110894600524d7cb871",
                "sha256": "38a26d963ee3ad93332ddf782f9259c5bdfe405e73408d943ef5e7d0c3767ec7"
            },
            "downloads": -1,
            "filename": "click_option_group-0.5.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7d18e8049b993110894600524d7cb871",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6,<4",
            "size": 12467,
            "upload_time": "2023-06-09T22:22:34",
            "upload_time_iso_8601": "2023-06-09T22:22:34.978391Z",
            "url": "https://files.pythonhosted.org/packages/af/75/81ea958bc0f7e410257cb2a42531b93a7695a31930cde87192c010a52c50/click_option_group-0.5.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e7b891054601a2e05fd9060cb1baf56be5b24145817b059e078669e1099529c7",
                "md5": "6948f452fa3c42101aad04caf1b5b454",
                "sha256": "97d06703873518cc5038509443742b25069a3c7562d1ea72ff08bfadde1ce777"
            },
            "downloads": -1,
            "filename": "click-option-group-0.5.6.tar.gz",
            "has_sig": false,
            "md5_digest": "6948f452fa3c42101aad04caf1b5b454",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6,<4",
            "size": 16517,
            "upload_time": "2023-06-09T22:22:36",
            "upload_time_iso_8601": "2023-06-09T22:22:36.779497Z",
            "url": "https://files.pythonhosted.org/packages/e7/b8/91054601a2e05fd9060cb1baf56be5b24145817b059e078669e1099529c7/click-option-group-0.5.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-09 22:22:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "click-contrib",
    "github_project": "click-option-group",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "click-option-group"
}
        
Elapsed time: 0.39758s