Package: click-option-group
click-option-groupclick-option-groupis a Click-extension package that adds option groups
missing inClick.Aim and MotivationClick 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,argparsestdlib 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 257issue 373issue 509issue 1137The aim of this package is to provide group options with extensible functionality
using canonical and clean API (Click-like API as far as possible).QuickstartInstallingInstall and update using pip:pipinstall-Uclick-option-groupA Simple ExampleHere is a simple example how to use option groups in your Click-based CLI.
Just useoptgroupfor declaring option groups by decorating
your command function in Click-like API style.# app.pyimportclickfromclick_option_groupimportoptgroup,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')defcli(**params):print(params)if__name__=='__main__':cli()$pythonapp.py--help
Usage:app.py[OPTIONS]Options:Serverconfiguration:Theconfigurationofsomeserverconnection-h,--hostTEXTServerhostname-p,--portINTEGERServerport-n,--attemptsINTEGERThenumberofconnectionattempts-t,--timeoutINTEGERTheserverresponsetimeoutInputdatasources:[mutually_exclusive,required]Thesourcesoftheinputdata--tsv-fileFILENAMECSV/TSVinputdatafile--json-fileFILENAMEJSONinputdatafile--debug/--no-debugDebugflag--helpShowthismessageandexit.Documentationhttps://click-option-group.readthedocs.ioChangelogv0.5.6 (09.06.2023)Addoptgroup.help_optiondecorator to add help option to the group (PR#50)Use GitHub Actions instead of Travis CI for CIDelete tox runnerAdd Python 3.11 to the setup classifiersv0.5.5 (12.10.2022)Addtests/directory to tarballAddtests_covextra dependencies for testing with coveragev0.5.4 (12.10.2022)Move frame gathering into error code path (PR#34)Fix typos (PR#37)PEP 561 support (PR#42)Update docs dependencies and Travis CI Python version matrix (PR#43)v0.5.3 (14.05.2021)Update Click dependency version to<9(Issue#33)v0.5.2 (28.11.2020)Do not use default option group name. An empty group name will not be displayedSlightly edited error messagesAll arguments exceptnameinoptgroupdecorator must be keyword-onlyv0.5.1 (14.06.2020)Fix incompatibility with autocomplete: out of the box Click completion and click-repl (Issue#14)v0.5.0 (10.06.2020)AddAllOptionGroupclass: all options from the group must be set or none must be set (PR#13)Fix type hintsUpdate docsv0.4.0 (18.05.2020)Support multi-layer wrapped functions (PR#10)Fix flake8 issuesv0.3.1Addhidden=Trueto_GroupTitleFakeOptionas a temporary workaroud for issue#4v0.3.0Add support for hidden options inside groups (PR#2)v0.2.3Transfer the repo to click-contrib organisationv0.2.2Add true lineno in warning when declaring empty option groupUpdate readmev0.2.1Use RuntimeWarning and stacklevel 2 when declaring empty option groupUpdate readmev0.2.0ImplementRequiredMutuallyExclusiveOptionGroupclass instead ofrequiredargument forMutuallyExclusiveOptionGroupAdd tests with 100% coverageUpdate readmev0.1.0First public release