def _delete_cmd_builder(self, handler_function: Callable) -> click.Command: if hasattr(handler_function, '__file_inputs__'): file_inputs = handler_function.__file_inputs__ else: file_inputs = default_file_inputs_handler() print_result = True if hasattr(handler_function, '__print_result__'): print_result = handler_function.__print_result__ @environment_name_option() @file_inputs.option() @ignore_missing_option() @tnco_client_secret_option() @tnco_pwd_option() @click.pass_context def cmd(ctx: click.Context, environment_name: str, file_content: Any, ignore_missing: bool, pwd: str = None, client_secret: str = None, **kwargs): ctl = self._get_controller() with ctl.tnco_client_safety_net(): tnco_client = ctl.get_tnco_client(environment_name, input_pwd=pwd, input_client_secret=client_secret) result = handler_function(tnco_client, ctx=ctx, file_content=file_content, ignore_missing=ignore_missing, **kwargs) if result is not None and print_result: ctl.io.print(f'Removed: {result}') # Add any extra arguments or options decorated on the handler_function if hasattr(handler_function, '__click_params__'): cmd.__click_params__.extend(handler_function.__click_params__) # Build final command cmd_kwargs = {} if not hasattr(handler_function, '__cmd_kwargs__') else handler_function.__cmd_kwargs__ if 'help' not in cmd_kwargs: help = f'Delete {self.display_name}' help += f'\n\n If "-f, --file" option is set then the target {self.display_name} will be discovered from this file' cmd_kwargs['help'] = help if 'short_help' not in cmd_kwargs: cmd_kwargs['short_help'] = f'Delete {self.display_name}' cmd = click.command(**cmd_kwargs)(cmd) return cmd
def _update_cmd_builder(self, handler_function: Callable) -> click.Command: if hasattr(handler_function, '__file_inputs__'): file_inputs = handler_function.__file_inputs__ else: file_inputs = default_file_inputs_handler() print_result = True if hasattr(handler_function, '__print_result__'): print_result = handler_function.__print_result__ @environment_name_option() @file_inputs.option() @set_param_option() @tnco_client_secret_option() @tnco_pwd_option() @click.pass_context def cmd(ctx: click.Context, environment_name: str, file_content: Any, set_values: Any, pwd: str = None, client_secret: str = None, **kwargs): ctl = self._get_controller() with ctl.tnco_client_safety_net(): tnco_client = ctl.get_tnco_client(environment_name, input_pwd=pwd, input_client_secret=client_secret) result = handler_function(tnco_client, ctx=ctx, file_content=file_content, set_values=set_values, **kwargs) if result is not None and print_result: ctl.io.print(f'Updated: {result}') # Add any extra arguments or options decorated on the handler_function if hasattr(handler_function, '__click_params__'): cmd.__click_params__.extend(handler_function.__click_params__) # Build final command cmd_kwargs = {} if not hasattr(handler_function, '__cmd_kwargs__') else handler_function.__cmd_kwargs__ if 'help' not in cmd_kwargs: help = f'Update {self.display_name}' help += f'\n\nUse the "-f, --file" option to parse a file in a supported format: {list(file_inputs.formats.keys())}' help += f'\n\nOtherwise, use "--set" option to set attributes as key=value pairs' cmd_kwargs['help'] = help if 'short_help' not in cmd_kwargs: cmd_kwargs['short_help'] = f'Update {self.display_name}' cmd = click.command(**cmd_kwargs)(cmd) return cmd
class DescriptorTemplatesTable(Table): columns = [ Column('name', header='Name'), Column('description', header='Description', accessor=lambda x: (x.get('description')[:75].strip() + '..') if x.get('description', None) is not None and len( x.get('description')) > 75 else x.get('description')) ] output_formats = common_output_format_handler(table=DescriptorTemplatesTable()) render_output_formats = default_output_format_handler() file_inputs = default_file_inputs_handler() class DescriptorTemplates(TNCOTarget): name = 'descriptortemplate' plural = 'descriptortemplates' display_name = 'Descriptor Template' @LmGen() def genfile(self, ctx: click.Context, name: str): return { 'name': name, 'properties': { 'injected_prop': { 'type': 'string' }