piccolo icon indicating copy to clipboard operation
piccolo copied to clipboard

[Enhancement] use Typer and questionary for the CLI

Open kareemmahlees opened this issue 3 years ago • 4 comments

Why

below I created a mock application with typer to illustrate my point of view:

  • better information display
Screenshot 2022-12-27 214307 Screenshot 2022-12-27 214336
  • better error display :
Screenshot 2022-12-27 214423 Screenshot 2022-12-27 214442
  • type checking everywhere
  • modularity
  • shell completion
  • all the powerful stuff that rich provides ( i.e tables, spinners, progress bars,...)

using questionary provides a much more intuitive user experience:

Screenshot 2022-12-27 215253 Screenshot 2022-12-27 215905

If any of the maintainers finds this interesting, you can assign it to me and I will work on it 🙂

kareemmahlees avatar Dec 27 '22 20:12 kareemmahlees

@kareemmahlees Thanks for this 👍

It's an interesting idea. It's quite a big change, and I'm not sure if we can do it in a backwards compatible way. It's because we allow users to register their own commands:

https://piccolo-orm.readthedocs.io/en/latest/piccolo/projects_and_apps/piccolo_apps.html#commands

It's a tricky one. I wonder if we could somehow enhance the CLI without changing libraries.

dantownsend avatar Dec 30 '22 07:12 dantownsend

@dantownsend Thank you

regarding the issue of registering commands, typer allows that:

- cli.register(sum)
+ app.command()(sum)

But since targ does it it is unnecessary to change it. I think what can be improved here is to update the print statements to use rich instead and questionary for asking for input so we are not changing the libraries we are just using some new tools.

kareemmahlees avatar Dec 30 '22 08:12 kareemmahlees

Sorry for the slow reply.

I'm kind of torn on it. I've been through the docs, and it is does offer some nice features.

The way argument are documented is a bit different in targ - it's all in the docstring. I'm not sure how easy that would be to convert over 🤔

dantownsend avatar Jan 03 '23 22:01 dantownsend

@dantownsend No Worries. Typer, plus being apple to use typer.Argument or typer.Option, can also provide help text from docstring

But I suggest, if this was approved, using typer.Argument and typer.Option because it offers an extensive set of features. Also, adding new features and maintenance, in my opinion, would be much better using typer's arguments and options instead of parsing docstrings!
I think it is worth the effort.

P.S.:- If this was approved I would like to work on it.

kareemmahlees avatar Jan 05 '23 19:01 kareemmahlees