4 ms·
I don't have a startup but I did make a useful little Python library while at my previous job to help ease the pain with using argparse to make CLIs. It's call
by shangxiao 5y ago
I don't have a startup but I did make a useful little Python library while at my previous job to help ease the pain with using argparse to make CLIs.
It's called bargeparse [1]. The idea is to define an entry point function and use its signature as a means to declare the CLI arguments & options. I was surprised at how well Python's syntax for function arguments works for this... especially the use of pos-only & keyword-only arguments to force a particular style.
[1] https://github.com/shangxiao/bargeparse https://github.com/shangxiao/bargeparse
- Felk 5y agoWow, that looks extremely useful. I typically use docopt for all my CLI needs, but it looks like this could be really nice as well. I will have to try it the next time I'm building a CLI.
- shezi 5y agoI love that! Argparse is such an old and boring solution to such a simple problem that we need more like this. And I have hope that one of the solutions will make it into the standard library at some point. There are some others like yours: Google's python-fire (1) Docopt (2), which creates the cli from the documentation instead of the other way around Click (3) And my own commandeer (4) Typer (5) (1) https://github.com/google/python-fire https://github.com/google/python-fire (2) http://docopt.org/ http://docopt.org/ (3) https://click.palletsprojects.com/en/8.0.x/ https://click.palletsprojects.com/en/8.0.x/ (4) https://pythonhosted.org/Commandeer/index.html https://pythonhosted.org/Commandeer/index.html (5) https://typer.tiangolo.com/ https://typer.tiangolo.com/
- sebst 5y agoThis is a cool one. I once stumbled upon bargeparse and have used it several times. And, you're right: argparse can cause some pain ;) I've taken the liberty to post your project to my Python news aggregator over here[1]. [1] https://news.python.sc/item/0d111c5d-0eff-41d5-8d5c-ecb18301f06f https://news.python.sc/item/0d111c5d-0eff-41d5-8d5c-ecb18301...
- BiteCode_dev 5y agoWhat's the benefit over well established solutions like typer ?
- nxpnsv 5y agoI’ve done this with my own crappy code, optparse, argparse, hug, fire, click, and typer. For me typer is pretty much perfect…
- BiteCode_dev 5y agoTyper has the wonderful fast api paradigm and the battle tested click foundation. Pretty much a match made in heaven.
- bmn__ 5y agoI can make a guess: GP does not know, he started working on the software and pointlessly duplicated existing projects, but with worse quality, because he neglected to survey the landscape. I have noticed that happening regularly and out of curiousity interviewed those fellow programmers. I found out it's not because of lack of diligence, or because they attribute no value to a survey, but because of a risk-loving psychology trait that expresses itself in staking out ground and claiming it as one's own. (Armchair psychology warning, I am not qualified to make that conclusion; leave the real work confirming this hypothesis to the scientists in the field.) IMO, this behaviour is harmful and we should work together to socially shun it like we already do for compulsive hoarding of physical objects. We have trouble finding a piece of software that works well because we spend so much effort to repeatedly sift through the mountains of published software that is mostly garbage.
- shangxiao 5y agoCouldn't be further from the truth, see my reply.
- shangxiao 5y agoTyper looks neat. I don't think it was well-established when I started on this, there were quite a few offerings but the only one I managed to find was python-fire. It didn't quite do what my team wanted and there were a few behaviours that we didn't quite like so we decided to make this. Having said that bargeparse was meant to rely solely on stdlib as the environment we were operating in was tightly controlled and any 3rd party packages had to go through a lengthy review process to be whitelisted. Additionally, since our team (and others in our organisation) were mostly using argparse, the goal was to provide a way to declaratively interact with it using existing features in the language itself.
- d4rkp4ttern 5y agoPython-fire is a great package for this. Will look into bargeparse https://github.com/google/python-fire https://github.com/google/python-fire