feat: Allow to pass entry point to clipstick parse function#57
feat: Allow to pass entry point to clipstick parse function#57playpauseandstop wants to merge 1 commit intosander76:mainfrom
Conversation
This is helpful, when list of CLI args comes not from `sys.argv` and, as result, entry point cannot be parsed from `sys.argv[0]`. This is also might be helpful for cases, when some CLI called via `python3 -m ...` and `sys.argv[0]` as result contain meaningless value of `something/__main__.py` (however, looks like, the proper fix for that case is out of scope of current change).
|
Adding some context to my PR. I needed to provide a CLI utilities which at same time will be called from CLI as from path.to import cli
cli.main(...)To achieving that I'm doing little dances with main function, def main(*argv: str) -> int:
args = clipstick.parse(CliArgs, argv or sys.argv[1:])
...and all works perfectly fine, but little perfectionist in myself want to see real tool name in help output instead of Cause of that I've come up with such PR. Please let me know, if it seems reasonable for you or you have other ideas here. |
| def parse( | ||
| model: type[TPydanticModel], | ||
| args: list[str] | None = None, | ||
| entry_point: str | None = None, |
There was a problem hiding this comment.
Hi @playpauseandstop thanks for the pr! Much appreciated!
My use of the DUMMY_ENTRYPOINT has always bugged me a bit.
Your pr makes me think about this a bit more.
Would it be an alternative that the args: list[str] should always have the entrypoint as a first item, just like sys.argv?
This removes the entry_point parameter, the DUMMY_ENTRY_POINT and is consistent with sys.argv.
I am not sure I completely understand your usecase as you describe below. But I guess you can then use the above solution too ?
def main(*argv: str) -> int:
args = clipstick.parse(CliArgs, argv or sys.argv[1:])
...There was a problem hiding this comment.
Forget about my above comment. I have been reading up on this on how other libs do this. for example:
https://docs.python.org/3/library/argparse.html#prog
I guess your suggestions is the proper approach.
|
Hi @playpauseandstop. I think have not documented this properly, but can you point your pr to my |
|
also thank for your remark about |
This is helpful, when list of CLI args comes not from
sys.argvand, as result, entry point cannot be parsed fromsys.argv[0].This is also might be helpful for cases, when some CLI called via
python3 -m ...andsys.argv[0]as result contain meaningless value ofsomething/__main__.py(however, looks like, the proper fix for that case is out of scope of current change).ps. Thanks a lot for
clipsticklibrary 🙏 Very appreciate your work, as it makes my life much more easier 🙇