Consider a less ad-hoc approach to CLI arguments
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.
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.
Though. Do we actually need to change the CLI?
Real issues:
- Wrong helptext
- No CLI argument validation. For instance, bad input to --entrypoint will simply try, and crash if something goes wrong.
Hypothetical issues:
- We don't respond to
hotload -h- in that case, hotload looks for a python file called-h. - We don't support
--entrypoint=PYTHON_FUNCTION - We don't support short options
Perhaps trying to fix the real issues directly is better than redoing the whole CLI.
Potential new stuff:
- Allow disabling the "MODULE RELOADED" text
- Allow opting into "reload took x time" with CLI option
GNU CLI conventions: https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html
Nice argparse guide: https://realpython.com/command-line-interfaces-python-argparse/