I'm looking to create a CLI application in Python that can be run directly from the command line:
$ myapp command --flag --argument foo
or can be run as a REPL application:
$ myapp
(context)> command --flag --argument foo
(context)> other --with different --flags
I took a look at Click (including this question) and argparse, which seem to be good for the former but have limited support for the latter, and cmd2, which seems to be good for the latter but have limited support for the former.
Is there a recommendation for what to use in this situation? I have considered simply using two different libraries with their own wrappers to the same core "business logic", but I would prefer to use something built for this purpose, if such a thing exists.
I'm in the same boat. Python Prompt Toolkit looks excellent for creating a REPL type app. In fact the author has created a "better Python REPL" using it as well as full screen apps like VIM clone in pure python. I'm just starting with it but it looks good.
Interestingly, there was a bug filed about command line arg parsing and the author responded that something like click or argparse could do that. So I think you can combine the two libraries to achieve what you're looking for.
Finally, the issue of accepting strings from the REPL and parsing them for args is similar to this question on Stack Overflow and the answers might help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With