Skip to main content

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

Release files for wmul_click_utils 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wmul_click_utils 0.1.1
File Size Uploaded
wmul_click_utils-0.1.1.tar.gz 21.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wmul_click_utils 0.1.1
File Interpreter ABI Platform
wmul_click_utils-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 38.0 kB

Release files / wmul_click_utils-0.1.1.tar.gz

Download URL wmul_click_utils-0.1.1.tar.gz
Size 21.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d6cccebff56ebacea740868d69a293801a17133f89a70388135d11b5e4e26018
BLAKE2b-256 checksum
How to use checksums
125c74f0fc67da70f858378e2fd66480c7bfc5a5453d3c83877b839c5b39b93a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.2

Release files / wmul_click_utils-0.1.1-py3-none-any.whl

Download URL wmul_click_utils-0.1.1-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8b2a2d6e5a932024d86e4e4b720bdd4eb9913e9d42a3438bb1e7eaa5a9165c6a
BLAKE2b-256 checksum
How to use checksums
670a42af4b15b3b857b1d60df9577ef4ffbc8f46837d1ce045e065c1ca09e02b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.2

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page