MCPcopy
hub / github.com/pallets/click / get_help_extra

Method get_help_extra

src/click/core.py:3251–3333  ·  view source on GitHub ↗
(self, ctx: Context)

Source from the content-addressed store, hash-verified

3249 return ("; " if any_prefix_is_slash else " / ").join(rv), help
3250
3251 def get_help_extra(self, ctx: Context) -> types.OptionHelpExtra:
3252 extra: types.OptionHelpExtra = {}
3253
3254 if self.show_envvar:
3255 envvar = self.envvar
3256
3257 if envvar is None:
3258 if (
3259 self.allow_from_autoenv
3260 and ctx.auto_envvar_prefix is not None
3261 and self.name
3262 ):
3263 envvar = f"{ctx.auto_envvar_prefix}_{self.name.upper()}"
3264
3265 if envvar is not None:
3266 if isinstance(envvar, str):
3267 extra["envvars"] = (envvar,)
3268 else:
3269 extra["envvars"] = tuple(str(d) for d in envvar)
3270
3271 # Temporarily enable resilient parsing to avoid type casting
3272 # failing for the default. Might be possible to extend this to
3273 # help formatting in general.
3274 resilient = ctx.resilient_parsing
3275 ctx.resilient_parsing = True
3276
3277 try:
3278 default_value = self.get_default(ctx, call=False)
3279 finally:
3280 ctx.resilient_parsing = resilient
3281
3282 show_default = False
3283 show_default_is_str = False
3284
3285 if self.show_default is not None:
3286 if isinstance(self.show_default, str):
3287 show_default_is_str = show_default = True
3288 else:
3289 show_default = self.show_default
3290 elif ctx.show_default is not None:
3291 show_default = ctx.show_default
3292
3293 if show_default_is_str or (
3294 show_default and (default_value not in (None, UNSET))
3295 ):
3296 if show_default_is_str:
3297 default_string = f"({self.show_default})"
3298 elif isinstance(default_value, (list, tuple)):
3299 default_string = ", ".join(str(d) for d in default_value)
3300 elif isinstance(default_value, enum.Enum):
3301 default_string = default_value.name
3302 elif inspect.isfunction(default_value):
3303 default_string = _("(dynamic)")
3304 elif self.is_bool_flag and self.secondary_opts:
3305 # For boolean flags that have distinct True/False opts,
3306 # use the opt without prefix instead of the value.
3307 default_string = _split_opt(
3308 (self.opts if default_value else self.secondary_opts)[0]

Calls 3

get_defaultMethod · 0.95
_split_optFunction · 0.85
_describe_rangeMethod · 0.80