optparse.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Source code: https://github.com/hamdanal/rich-argparse
  2. # MIT license: Copyright (c) Ali Hamdan <ali.hamdan.dev@gmail.com>
  3. from __future__ import annotations
  4. from rich_argparse._optparse import (
  5. GENERATE_USAGE,
  6. IndentedRichHelpFormatter,
  7. RichHelpFormatter,
  8. TitledRichHelpFormatter,
  9. )
  10. __all__ = [
  11. "RichHelpFormatter",
  12. "IndentedRichHelpFormatter",
  13. "TitledRichHelpFormatter",
  14. "GENERATE_USAGE",
  15. ]
  16. if __name__ == "__main__":
  17. import optparse
  18. IndentedRichHelpFormatter.highlights.append(r"(?P<metavar>\bregexes\b)")
  19. parser = optparse.OptionParser(
  20. description="I [link https://pypi.org/project/rich]rich[/]ify:trade_mark: optparse help.",
  21. formatter=IndentedRichHelpFormatter(),
  22. prog="python -m rich_arparse.optparse",
  23. epilog=":link: https://github.com/hamdanal/rich-argparse#optparse-support.",
  24. usage=GENERATE_USAGE,
  25. )
  26. parser.add_option("--formatter", metavar="rich", help="A piece of :cake: isn't it? :wink:")
  27. parser.add_option(
  28. "--styles", metavar="yours", help="Not your style? No biggie, change it :sunglasses:"
  29. )
  30. parser.add_option(
  31. "--highlights",
  32. action="store_true",
  33. help=":clap: --highlight :clap: all :clap: the :clap: regexes :clap:",
  34. )
  35. parser.add_option(
  36. "--syntax", action="store_true", help="`backquotes` may be bold, but they are :muscle:"
  37. )
  38. parser.add_option(
  39. "-s", "--long", metavar="METAVAR", help="That's a lot of metavars for an option!"
  40. )
  41. group = parser.add_option_group("Magic", description=":sparkles: :sparkles: :sparkles:")
  42. group.add_option(
  43. "--treasure", action="store_false", help="Mmm, did you find the --hidden :gem:?"
  44. )
  45. group.add_option("--hidden", action="store_false", dest="treasure", help=optparse.SUPPRESS_HELP)
  46. parser.print_help()