def get_option_help_info(self, args, kwargs): """Returns an OptionHelpInfo for the option registered with the given (args, kwargs).""" display_args = [] scoped_cmd_line_args = [] unscoped_cmd_line_args = [] for arg in args: is_short_arg = len(arg) == 2 unscoped_cmd_line_args.append(arg) if self._scope_prefix: scoped_arg = "--{}-{}".format(self._scope_prefix, arg.lstrip("-")) else: scoped_arg = arg scoped_cmd_line_args.append(scoped_arg) if kwargs.get("type") == bool: if is_short_arg: display_args.append(scoped_arg) else: unscoped_cmd_line_args.append("--no-{}".format(arg[2:])) scoped_cmd_line_args.append("--no-{}".format( scoped_arg[2:])) display_args.append("--[no-]{}".format(scoped_arg[2:])) else: metavar = self.compute_metavar(kwargs) display_args.append(f"{scoped_arg}={metavar}") typ = kwargs.get("type", str) default = self.compute_default(kwargs) help_msg = kwargs.get("help", "No help available.") removal_version = kwargs.get("removal_version") deprecated_message = None if removal_version: deprecated_tense = deprecated.get_deprecated_tense(removal_version) deprecated_message = "DEPRECATED. {} removed in version: {}".format( deprecated_tense, removal_version) removal_hint = kwargs.get("removal_hint") choices = self.compute_choices(kwargs) ret = OptionHelpInfo( registering_class=kwargs.get("registering_class", type(None)), display_args=display_args, comma_separated_display_args=", ".join(display_args), scoped_cmd_line_args=scoped_cmd_line_args, unscoped_cmd_line_args=unscoped_cmd_line_args, typ=typ, default=default, help=help_msg, deprecated_message=deprecated_message, removal_version=removal_version, removal_hint=removal_hint, choices=choices, ) return ret
def get_option_help_info(self, args, kwargs): """Returns an OptionHelpInfo for the option registered with the given (args, kwargs).""" display_args = [] scoped_cmd_line_args = [] unscoped_cmd_line_args = [] for arg in args: is_short_arg = len(arg) == 2 unscoped_cmd_line_args.append(arg) if self._scope_prefix: scoped_arg = '--{}-{}'.format(self._scope_prefix, arg.lstrip('-')) else: scoped_arg = arg scoped_cmd_line_args.append(scoped_arg) if kwargs.get('type') == bool: if is_short_arg: display_args.append(scoped_arg) else: unscoped_cmd_line_args.append('--no-{}'.format(arg[2:])) scoped_cmd_line_args.append('--no-{}'.format( scoped_arg[2:])) display_args.append('--[no-]{}'.format(scoped_arg[2:])) else: metavar = self.compute_metavar(kwargs) display_arg = '{}={}'.format(scoped_arg, metavar) if is_list_option(kwargs): # Show the multi-arg append form. display_args.append('{arg_str} ({arg_str}) ...'.format( arg_str=display_arg)) # Also show the list literal form, both with and without the append operator. if metavar.startswith('"') and metavar.endswith('"'): # We quote the entire list literal, so we shouldn't quote the individual members. metavar = metavar[1:-1] display_args.append( '{arg}="[{metavar}, {metavar}, ...]"'.format( arg=scoped_arg, metavar=metavar)) display_args.append( '{arg}="+[{metavar}, {metavar}, ...]"'.format( arg=scoped_arg, metavar=metavar)) else: display_args.append(display_arg) typ = kwargs.get('type', str) default = self.compute_default(kwargs) help_msg = kwargs.get('help', 'No help available.') removal_version = kwargs.get('removal_version') deprecated_message = None if removal_version: deprecated_tense = deprecated.get_deprecated_tense(removal_version) deprecated_message = 'DEPRECATED. {} removed in version: {}'.format( deprecated_tense, removal_version) removal_hint = kwargs.get('removal_hint') choices = ', '.join( str(choice) for choice in kwargs.get('choices', [])) or None ret = OptionHelpInfo(registering_class=kwargs.get( 'registering_class', type(None)), display_args=display_args, scoped_cmd_line_args=scoped_cmd_line_args, unscoped_cmd_line_args=unscoped_cmd_line_args, typ=typ, default=default, help=help_msg, deprecated_message=deprecated_message, removal_version=removal_version, removal_hint=removal_hint, choices=choices) return ret
def get_option_help_info(self, args, kwargs): """Returns an OptionHelpInfo for the option registered with the given (args, kwargs).""" display_args = [] scoped_cmd_line_args = [] unscoped_cmd_line_args = [] for arg in args: is_short_arg = len(arg) == 2 unscoped_cmd_line_args.append(arg) if self._scope_prefix: scoped_arg = f"--{self._scope_prefix}-{arg.lstrip('-')}" else: scoped_arg = arg scoped_cmd_line_args.append(scoped_arg) if Parser.is_bool(kwargs): if is_short_arg: display_args.append(scoped_arg) else: unscoped_cmd_line_args.append(f"--no-{arg[2:]}") sa_2 = scoped_arg[2:] scoped_cmd_line_args.append(f"--no-{sa_2}") display_args.append(f"--[no-]{sa_2}") else: metavar = self.compute_metavar(kwargs) display_args.append(f"{scoped_arg}={metavar}") if kwargs.get("passthrough"): type_str = self.stringify_type(kwargs.get("member_type", str)) display_args.append(f"... -- [{type_str} [{type_str} [...]]]") typ = kwargs.get("type", str) default = self.compute_default(**kwargs) help_msg = kwargs.get("help", "No help available.") deprecation_start_version = kwargs.get("deprecation_start_version") removal_version = kwargs.get("removal_version") deprecation_active = removal_version is not None and deprecated.is_deprecation_active( deprecation_start_version ) deprecated_message = None if removal_version: deprecated_tense = deprecated.get_deprecated_tense(removal_version) message_start = ( "Deprecated" if deprecation_active else f"Upcoming deprecation in version: {deprecation_start_version}" ) deprecated_message = ( f"{message_start}, {deprecated_tense} removed in version: {removal_version}." ) removal_hint = kwargs.get("removal_hint") choices = self.compute_choices(kwargs) dest = Parser.parse_dest(*args, **kwargs) # Global options have three env var variants. The last one is the most human-friendly. env_var = Parser.get_env_var_names(self._scope, dest)[-1] ret = OptionHelpInfo( display_args=tuple(display_args), comma_separated_display_args=", ".join(display_args), scoped_cmd_line_args=tuple(scoped_cmd_line_args), unscoped_cmd_line_args=tuple(unscoped_cmd_line_args), env_var=env_var, config_key=dest, typ=typ, default=default, help=help_msg, deprecation_active=deprecation_active, deprecated_message=deprecated_message, removal_version=removal_version, removal_hint=removal_hint, choices=choices, comma_separated_choices=None if choices is None else ", ".join(choices), value_history=None, ) return ret
def get_option_help_info(self, args, kwargs): """Returns an OptionHelpInfo for the option registered with the given (args, kwargs).""" display_args = [] scoped_cmd_line_args = [] unscoped_cmd_line_args = [] for arg in args: is_short_arg = len(arg) == 2 unscoped_cmd_line_args.append(arg) if self._scope_prefix: scoped_arg = '--{}-{}'.format(self._scope_prefix, arg.lstrip('-')) else: scoped_arg = arg scoped_cmd_line_args.append(scoped_arg) if kwargs.get('type') == bool: if is_short_arg: display_args.append(scoped_arg) else: unscoped_cmd_line_args.append('--no-{}'.format(arg[2:])) scoped_cmd_line_args.append('--no-{}'.format(scoped_arg[2:])) display_args.append('--[no-]{}'.format(scoped_arg[2:])) else: metavar = self.compute_metavar(kwargs) display_arg = '{}={}'.format(scoped_arg, metavar) if is_list_option(kwargs): # Show the multi-arg append form. display_args.append('{arg_str} ({arg_str}) ...'.format(arg_str=display_arg)) # Also show the list literal form, both with and without the append operator. if metavar.startswith('"') and metavar.endswith('"'): # We quote the entire list literal, so we shouldn't quote the individual members. metavar = metavar[1:-1] display_args.append('{arg}="[{metavar}, {metavar}, ...]"'.format(arg=scoped_arg, metavar=metavar)) display_args.append('{arg}="+[{metavar}, {metavar}, ...]"'.format(arg=scoped_arg, metavar=metavar)) else: display_args.append(display_arg) typ = kwargs.get('type', str) default = self.compute_default(kwargs) help_msg = kwargs.get('help', 'No help available.') removal_version = kwargs.get('removal_version') deprecated_message = None if removal_version: deprecated_tense = deprecated.get_deprecated_tense(removal_version) deprecated_message = 'DEPRECATED. {} removed in version: {}'.format(deprecated_tense, removal_version) removal_hint = kwargs.get('removal_hint') choices = ', '.join(kwargs.get('choices')) if kwargs.get('choices') else None ret = OptionHelpInfo(registering_class=kwargs.get('registering_class', type(None)), display_args=display_args, scoped_cmd_line_args=scoped_cmd_line_args, unscoped_cmd_line_args=unscoped_cmd_line_args, typ=typ, fromfile=kwargs.get('fromfile', False), default=default, help=help_msg, deprecated_message=deprecated_message, removal_version=removal_version, removal_hint=removal_hint, choices=choices) return ret