Return 2-tuple of ``(flag-spec, help-string)`` for given ``flag``. .. versionadded:: 1.0
(self, flag: str)
| 178 | return list(set([flag] + self.flags.aliases_of(flag))) |
| 179 | |
| 180 | def help_for(self, flag: str) -> Tuple[str, str]: |
| 181 | """ |
| 182 | Return 2-tuple of ``(flag-spec, help-string)`` for given ``flag``. |
| 183 | |
| 184 | .. versionadded:: 1.0 |
| 185 | """ |
| 186 | # Obtain arg obj |
| 187 | if flag not in self.flags: |
| 188 | err = "{!r} is not a valid flag for this context! Valid flags are: {!r}" # noqa |
| 189 | raise ValueError(err.format(flag, self.flags.keys())) |
| 190 | arg = self.flags[flag] |
| 191 | # Determine expected value type, if any |
| 192 | value = {str: "STRING", int: "INT"}.get(arg.kind) |
| 193 | # Format & go |
| 194 | full_names = [] |
| 195 | for name in self.names_for(flag): |
| 196 | if value: |
| 197 | # Short flags are -f VAL, long are --foo=VAL |
| 198 | # When optional, also, -f [VAL] and --foo[=VAL] |
| 199 | if len(name.strip("-")) == 1: |
| 200 | value_ = ("[{}]".format(value)) if arg.optional else value |
| 201 | valuestr = " {}".format(value_) |
| 202 | else: |
| 203 | valuestr = "={}".format(value) |
| 204 | if arg.optional: |
| 205 | valuestr = "[{}]".format(valuestr) |
| 206 | else: |
| 207 | # no value => boolean |
| 208 | # check for inverse |
| 209 | if name in self.inverse_flags.values(): |
| 210 | name = "--[no-]{}".format(name[2:]) |
| 211 | |
| 212 | valuestr = "" |
| 213 | # Tack together |
| 214 | full_names.append(name + valuestr) |
| 215 | namestr = ", ".join(sorted(full_names, key=len)) |
| 216 | helpstr = arg.help or "" |
| 217 | return namestr, helpstr |
| 218 | |
| 219 | def help_tuples(self) -> List[Tuple[str, Optional[str]]]: |
| 220 | """ |
no test coverage detected