Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
teodorlu opened this issue Jul 3, 2022 · 4 comments
Open

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

teodorlu opened this issue Jul 3, 2022 · 4 comments

Comments

@teodorlu
Copy link
Owner

teodorlu commented Jul 3, 2022

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
Copy link
Owner Author

teodorlu commented Jul 3, 2022

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
Copy link
Owner Author

teodorlu commented Jul 3, 2022

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

@teodorlu
Copy link
Owner Author

teodorlu commented Jul 3, 2022

@teodorlu
Copy link
Owner Author

teodorlu commented Jul 3, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant