Live data from Hacker News

Click – Python library for command-line interfaces

click.pocoo.org

21–30 of 105 posts

Re: Click – Python library for command-line interfaces

#21
post #17

The biggest gripe I have with using Python for rich command-line tool is the startup time. One of the first reason I like to write a nice command-line tool when I start a project, say foo, is to be able to do `foo --help` to quickly see and remember what the project can do (I have a very bad memory and doing this makes it possible for me to jump back faster to a project, even well documented. I can forget what I was…

Hm, it'd be pointless to argue this point (if you think it's slow then it's slow) but I've created many a Python CLI and have never noticed them being slow to start. Perhaps it's a case of importing certain modules globally instead of on a per-function basis?

Re: Click – Python library for command-line interfaces

#22
post #11
post #7

Looks like a nice wrapper around argparse: https://docs.python.org/3/library/argparse.html

It's a wrapper around optparse, as per http://click.pocoo.org/why/ . I'm curious about that decision given that optparse is deprecated. It says it's because argparse doesn't allow nested commands, but I don't really see why that feature is so desirable as to warrant using a deprecated module. I probably need to have a play with it to find out. Looks like a nice module.

Click can be extended lazily which helps execution time a lot when working with many, many plugins. It also can be extended at runtime as per configuraton.

argparse requires the parser to have full knowledge of everything which makes it slow if you add many commands. Biggest problem though is that it's parsing system is a bit broken when it comes to escaping. Options with arguments cannot have values starting with dashes which is problematic for delegating subcommands to other things.

For what I wrote Click for I could not find any alternatives that worked that way besides optparse itself but that is hard to use.

Re: Click – Python library for command-line interfaces

#24
post #3

Gorgeous. This guy has a full time job, a wife, and wrote Flask and Werkzeug, ItsDangerous, Sphinx, Markupsafe, Jinja2 (and Jinja) and that's just some of the well known stuff. Handsome and young too. Bastard. He probably saves the world in a dinner jacket in his spare time.

Sphinx was written by Georg Brandl, not by Armin Ronacher.

Re: Click – Python library for command-line interfaces

#25
post #8

It looks really well done. I still prefer docopt ( https://github.com/docopt/docopt ) . It is so much simpler to use. Click seems to be a bit overengineered.

If you need to parse something as simple as `foo --option spam --option eggs` remembering both spam and eggs, docopt breaks down. You are also unable to compose an interface using docopt, if you want to allow plugins in a plugin system to add their own options for example.

docopt is much simpler because it's only capable of creating very trivial interfaces. That's perfectly fine if that's all what you want to do but it also makes docopt unusable, if that's not the case.

Re: Click – Python library for command-line interfaces

#26
post #24
post #3

Gorgeous. This guy has a full time job, a wife, and wrote Flask and Werkzeug, ItsDangerous, Sphinx, Markupsafe, Jinja2 (and Jinja) and that's just some of the well known stuff. Handsome and young too. Bastard. He probably saves the world in a dinner jacket in his spare time.

Sphinx was written by Georg Brandl, not by Armin Ronacher.

Hmmm. It's listed on his projects page...... https://lucumr.pocoo.org/projects/

Re: Click – Python library for command-line interfaces

#28
On a related note. Which python library would you recommend for text-based interfaces? I have never used ncurses, so I don't know how complex it is. What I would like to achieve is having a user launch my script from the command line, use the text based interface to select a source and destination folder, set a few parameters and show a progress bar.

Re: Click – Python library for command-line interfaces

#30
It seems to me that there are a few projects similar this. Here is another, https://pypi.python.org/pypi/Cogs/ (conceptualized as a "Makefile" replacement).

I'm wondering if there could be a breakout at the next PyCon to see if we could discuss approaches and come up with a unified way to do convert Python libraries into command line scripts?

Post reply on HN