| 573 | ) |
| 574 | |
| 575 | def print_usage(self, file): |
| 576 | from rich.text import Text |
| 577 | from httpie.output.ui import rich_help |
| 578 | |
| 579 | whitelist = set() |
| 580 | _, exception, _ = sys.exc_info() |
| 581 | if ( |
| 582 | isinstance(exception, argparse.ArgumentError) |
| 583 | and len(exception.args) >= 1 |
| 584 | and isinstance(exception.args[0], argparse.Action) |
| 585 | and exception.args[0].option_strings |
| 586 | ): |
| 587 | # add_usage path is also taken when you pass an invalid option, |
| 588 | # e.g --style=invalid. If something like that happens, we want |
| 589 | # to include to action that caused to the invalid usage into |
| 590 | # the list of actions we are displaying. |
| 591 | whitelist.add(exception.args[0].option_strings[0]) |
| 592 | |
| 593 | usage_text = Text('usage', style='bold') |
| 594 | usage_text.append(':\n ') |
| 595 | usage_text.append(rich_help.to_usage(self.spec, whitelist=whitelist)) |
| 596 | self.env.rich_error_console.print(usage_text) |
| 597 | |
| 598 | def error(self, message): |
| 599 | """Prints a usage message incorporating the message to stderr and |