Additional utilities for use with Python's click cli library.
Project description
wmul_click_utils
Additional utilities for use with Python's click cli library.
RequiredIf
A click.Option
that is used when a given option is required only when a
specified other option is provided. E.G. A password might be required when a
username is provided.
required_if
is the name of the other option that, if provided, makes this
option required.
Example:
@click.option("--email_address", type=str, multiple=True,
help="The e-mail address to which the report should be sent.")
@click.option("--mail_server", type=str, cls=RequiredIf,
required_if="email_address",
help="The address of the e-mail SMTP server to use.")
@click.option("--mail_username", type=str, cls=RequiredIf,
required_if="email_address",
help="The username to authenticate with the e-mail server.")
@click.option("--mail_password", type=str, cls=RequiredIf,
required_if="email_address",
help="The password to authenticate with the e-mail server.")
RequiredUnless
Another click.Option
. Allows an option to be designated as required only if
some other option is not provided. E.G. An e-mail address and a username.
Either or both might be provided, but at least one is needed.
required_unless
is one or more other options in a list. A single option may be
either a lone string or a string in a list ( "foo"
or ["foo"]
). If none
of the options are present, an error is raised.
Example:
@click.option("--username", type=str cls=RequiredUnless,
required_unless=["email_address"])
@click.option("--email_address", type=str, cls=RequiredUnless,
required_unless=["username"])
MXWith
Another click.Option
. Allows two or more options to be designated as mutually
exclusive. E.G. logging to a logfile or logging to syslog.
mx_with
is one or more other options in a list that are mutually exclusive
with this one. A single option may be either a lone string or a string in a
list ( "foo"
or ["foo"]
).
Example:
@click.option('--syslog', is_flag=True, cls=MXWith, mx_with=['log_file_name'],
help="log to syslog.")
@click.option(
'--log_file_name',
type=click.Path(
file_okay=True,
dir_okay=False,
readable=True,
writable=True
),
cls=MXWith,
mx_with=["syslog"],
help="Log to this filename."
)
RequiredUnless / MXWith Comparison
These two operate similarly. The difference is when multiple options or no options are provided.
RequiredUnless
makes certain that at least one of the options is present.
Multiple or all of the options may be provided without error.
MXWith
makes certain that at most one option is present. If none of the
options are provided, no error is raised.
PairedParamType / PAIRED
A click.ParamType that allows a parameter to accept a list of pairs. The list is in the form of a space-delimited string. E.G. '.wav .mp3' or '.wav .mp3 .doc .docx'.
Example
@click.option('--equivalent', type=PAIRED,
help="Pairs of equivalent extensions.")
--equivalent ".wav .mp3 .doc .docx"
DateParamType / DATE
A click.ParamType that allows a parameter to accept a date in the format YYYY-MM-DD.
Example
@click.option("--cutoff_date", type=DATE)
--cutoff_date 2023-01-17
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file wmul_click_utils-0.1.1.tar.gz
.
File metadata
- Download URL: wmul_click_utils-0.1.1.tar.gz
- Upload date:
- Size: 21.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6cccebff56ebacea740868d69a293801a17133f89a70388135d11b5e4e26018 |
|
MD5 | 7fc8a02611cd4022d4a0319c93edc3d5 |
|
BLAKE2b-256 | 125c74f0fc67da70f858378e2fd66480c7bfc5a5453d3c83877b839c5b39b93a |
File details
Details for the file wmul_click_utils-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: wmul_click_utils-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.28.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b2a2d6e5a932024d86e4e4b720bdd4eb9913e9d42a3438bb1e7eaa5a9165c6a |
|
MD5 | 4b712a51f20d840ebae5625983ce081c |
|
BLAKE2b-256 | 670a42af4b15b3b857b1d60df9577ef4ffbc8f46837d1ce045e065c1ca09e02b |