teodorlu / hotload

25 stars 3 forks source link

Consider a less ad-hoc approach to CLI arguments #10

Open teodorlu opened 2 years ago

teodorlu commented 2 years ago

Right now, we hand roll CLI arguments. We allow something like:

hotload PYTHON_MODULE_OR_SCRIPT [--entrypoint ENTRYPOINT_FUNCTION] [--recursive] [--no-clear]

But this isn't reflected in the helptext.

I know we have argparse -- but argparse can feel a bit heavy. I've used https://github.com/babashka/cli a bit recently, and I love how lightweight it is. Essentially, you specify the type of each option. The CLI lib can then return a map of all the options. Argparse might still be the way to go, not sure.

Current helptext output:

$ hotload
Running hotload ...
Usage: hotload SCRIPT
Hotload python script when files on standard input change

Example usage:

    find . -name '*.py' | hotload init.py

.py extension for script may be omitted.
teodorlu commented 2 years ago

A different CLI option:

hotload [OPTION...] [--] PYTHON_MODULE_OR_SCRIPT...

There's not really anything special with reloading one module.


Though perhap's it's normal? Use one python module as an entrypoint into your app, and consider other modules dependencies?

@tingstad's new feature of "also reload watched files if they are a module and have been changed since last time" is really something a bit different. It's an ergonomic solution if the user writes a main module and other modules.

teodorlu commented 2 years ago

Though. Do we actually need to change the CLI?

Real issues:

Hypothetical issues:

Perhaps trying to fix the real issues directly is better than redoing the whole CLI.

Potential new stuff:

teodorlu commented 2 years ago

GNU CLI conventions: https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html

teodorlu commented 2 years ago

Nice argparse guide: https://realpython.com/command-line-interfaces-python-argparse/