Python click.BOOL Examples
The following are 2
code examples of click.BOOL().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
click
, or try the search function
.
Example #1
Source File: cli.py From veros with MIT License | 6 votes |
def convert(self, value, param, ctx): assert param.nargs == 2 if self.current_key is None: if value not in SETTINGS: self.fail('Unknown setting %s' % value) self.current_key = value return value assert self.current_key in SETTINGS setting = SETTINGS[self.current_key] self.current_key = None if setting.type is bool: return click.BOOL(value) return setting.type(value)
Example #2
Source File: dynamic_click.py From notifiers with MIT License | 4 votes |
def params_factory(schema: dict, add_message: bool) -> list: """ Generates list of :class:`click.Option` based on a JSON schema :param schema: JSON schema to operate on :return: Lists of created :class:`click.Option` object to be added to a :class:`click.Command` """ # Immediately create message as an argument params = [] if add_message: params.append(click.Argument(["message"], required=False)) for property, prpty_schema in schema.items(): multiple = False choices = None if any(char in property for char in ["@"]): continue if prpty_schema.get("type") in COMPLEX_TYPES: continue if prpty_schema.get("duplicate"): continue if property == "message": continue elif not prpty_schema.get("oneOf"): click_type, description, choices = json_schema_to_click_type(prpty_schema) else: click_type, multiple, description = handle_oneof(prpty_schema["oneOf"]) # Not all oneOf schema can be handled by click if not click_type: continue # Convert bool values into flags if click_type == click.BOOL: param_decls = [get_flag_param_decals_from_bool(property)] click_type = None else: param_decls = [get_param_decals_from_name(property)] if description: description = description.capitalize() if multiple: if not description.endswith("."): description += "." description += " Multiple usages of this option are allowed" # Construct the base command options option = partial( click.Option, param_decls=param_decls, help=description, multiple=multiple ) if choices: option = option(type=choices) elif click_type: option = option(type=click_type) else: option = option() params.append(option) return params