Comments (8)
So I tested a bit and found a workaround (The try/except is "unnecessary")
try:
import rich_click as click
from rich_click import RichCommand as Command, RichGroup as Group
except ImportError:
import click
from click import Command, Group
class MyTyper(typer.Typer):
"""A custom subclassed version of typer.Typer to allow rich help"""
def __init__(self, *args, cls=Group, **kwargs) -> None:
super().__init__(*args, cls=cls, **kwargs)
def command(self, *args, cls=Command, **kwargs) -> typer.Typer.command:
return super().command(*args, cls=cls, **kwargs)
Now this may not be the best solution but it works I guess.
And I've also published it with pypi-command-line version 1.6.12
from rich-click.
I was just wondering what API you were envisioning, but what that suggestion, I think it's now all clear. I can definitely do that, yes.
from rich-click.
So I used click-help-colors in my pypi-command-line project before and although click-help-colors officially wasn't supported for Typer. I found a workaround by searching for open issues in the Typer repository. tiangolo/typer#47
I am not sure if the same solution could be used here, but if it works, then great.
from rich-click.
Super nice!
I guess then you need to use the custom class name MyTyper
in your code.. I wonder if we can do the same trick for Typer that we do for Click and have a drop-in import rich_click.typer as typer
🤔
I'm on holiday this week but will have a play when I'm back. Need to learn Typer first and get a minimal example to play with 😅
from rich-click.
This worked for me! Thanks @wasi-master for the workaround.
from rich-click.
Thanks for the snippet @wasi-master I tweaked it a bit to integrate it in my project: https://github.com/browniebroke/deezer-oauth-cli/pull/30/files
from rich-click.
@browniebroke Well done!
from rich-click.
@browniebroke - this looks great! Do you fancy prepping a PR to this repo with that, or are you happy if I pinch your code? I'm thinking that we can then have something like:
import rich_click.typer as typer
from rich-click.
Related Issues (20)
- Test help output in `rich-click` CLI is robust to lazy loading of modules. HOT 3
- Add `pytest-snapshot` or `syrupy` or similar HOT 1
- Expose a way to send usage information to stderr HOT 9
- Rich-Click does not translate the ascii codes into colors on windows 64 cmd.exe anymore HOT 3
- support providing a default/global `option_groups` config to apply to all commands HOT 7
- Unit tests should assert output to stderr on errors
- Either update or deprecate MacPorts install HOT 1
- `text_markup: Literal["rich", "markdown", "rst", None]` config option HOT 1
- Additional style options HOT 1
- `rich-click` CLI for version `1.8.0dev1` breaks backwards compatibility in edge case
- 1.9 wishlist
- 2.0 roadmap
- 'RichGroup' object has no attribute 'isolation' HOT 2
- Bugs (a) generating svg/html with decorator. (b) with root directory scripts HOT 1
- Interim blog post - "5 cool pre-made styles for your CLI" (title tentative)
- Color part of the help massage HOT 8
- OptionHighlighter is deprecated and will be removed in a future version. HOT 6
- Invalid MRO when importing rich_click HOT 4
- Continuting to receive "DeprecationWarning: OptionHighlighter is deprecated" as of 1.8.1 HOT 1
- Fix warning (again)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rich-click.