cloup._option_groups

Implements support to option group.

Classes summary

OptionGroup(name[, help, constraint])

GroupedOption(*args[, group])

A click.Option with an extra field group of type OptionGroup

OptionGroupMixin(*args[, align_option_groups])

Implements support to option groups.

Functions Summary

has_option_group(param)

get_option_group_of(param[, default])

option(*param_decls[, group, cls])

option_group(name, *args, **kwargs)

Attaches an option group to the command. This decorator is overloaded with two signatures::.

Contents

cloup._option_groups.C
cloup._option_groups.OptionDecorator
cloup._option_groups.OptionGroupDecorator
class cloup._option_groups.OptionGroup(name: str, help: Optional[str] = None, constraint: Optional[Constraint] = None)[source]
Parameters
get_help_records(self, ctx: click.Context)[source]
option(self, *param_decls, **attrs)[source]
__iter__(self)[source]
__getitem__(self, i: int)click.Option[source]
__len__(self)int[source]
__repr__(self)str[source]

Return repr(self).

__str__(self)str[source]

Return str(self).

class cloup._option_groups.GroupedOption(*args, group: Optional[OptionGroup] = None, **attrs)[source]

Bases: click.Option

A click.Option with an extra field group of type OptionGroup

Parameters

group (Optional[cloup._option_groups.OptionGroup]) –

cloup._option_groups.has_option_group(param)bool[source]
Return type

bool

cloup._option_groups.get_option_group_of(param, default=None)[source]
class cloup._option_groups.OptionGroupMixin(*args, align_option_groups: bool = True, **kwargs)[source]

Implements support to option groups.

New in version 0.5.0.

Important

In order to check the constraints defined on the option groups, a command must inherits from cloup.ConstraintMixin too!

Parameters

align_option_groups (bool) –

get_ungrouped_options(self, ctx: click.Context)Sequence[click.Option][source]
get_option_group_title(self, ctx: click.Context, opt_group: cloup._option_groups.OptionGroup)str[source]
format_option_group(self, ctx: click.Context, formatter: click.HelpFormatter, opt_group: cloup._option_groups.OptionGroup, help_records: Optional[Sequence] = None)[source]
format_options(self, ctx: click.Context, formatter: click.HelpFormatter, max_option_width: int = 30)[source]
cloup._option_groups.option(*param_decls, group: Optional[OptionGroup] = None, cls: Type[click.Option] = GroupedOption, **attrs)OptionGroupDecorator[source]
Parameters
Return type

Callable[[C], C]

cloup._option_groups.option_group(name: str, help: str, *options: OptionDecorator, constraint: Optional[Constraint] = None)OptionGroupDecorator[source]
cloup._option_groups.option_group(name: str, *options: OptionDecorator, help: Optional[str] = None, constraint: Optional[Constraint] = None)OptionGroupDecorator

Attaches an option group to the command. This decorator is overloaded with two signatures:

@option_group(name: str, *options, help: Optional[str] = None)
@option_group(name: str, help: str, *options)

In other words, if the second position argument is a string, it is interpreted as the “help” argument. Otherwise, it is interpreted as the first option; in this case, you can still pass the help as keyword argument.

Parameters
  • name – a mandatory name/title for the group

  • help – an optional help string for the group

  • options – option decorators like click.option

  • constraint – a Constraint to validate on this option group

Returns

a decorator that attaches the contained options to the decorated function