validate_percentage_or_int

gratools.validate_percentage_or_int(ctx, param, value)[source]

Click callback for validating that an option’s value is either an integer or a float representing a percentage (between 0.0 and 1.0 inclusive).

This function is intended to be used as a callback for a Click option.

Parameters:
  • ctx (click.Context) – The current Click context.

  • param (click.Parameter) – The Click parameter (option) being validated.

  • value (str | int | float) – The input value provided by the user for the option. Click might pass it as str, or already converted if type is set.

Returns:

int | float

The validated value, converted to int if it’s a whole number,

or float if it’s a percentage (0.0-1.0).

Raises:

click.BadParameter – If the value is not a valid integer or a float between 0.0 and 1.0.

Return type:

int | float