Python Fire: a library for automatically generating command line interfaces
opensource.googleblog.com
opensource.googleblog.com
The docs seem to go to great lengths to not state this clearly, but it works fine on bare functions too:
example.py:
import fire
def test(a="yes"):
print "a: " + a
fire.Fire(test)
cli:
$ python example.py
a: yes
$ python example.py no
a: no
$ python example.py --a maybe
a: maybeI have a handful of scripts with miniscule CLI handling (usually len(sys.argv) is enough) - so it's 3 loc instead of 5?
Then I have a moderate amount of scripts where using click or optparse makes sense. Just looked up one tool, there's exactly 12 lines (including import, ignoring linebreaks) to handle 6 different CLI args. I could use fire. Less code, more "magic", less self-documenting excplicit code
Then there's this application with 15 @click.option() lines (don't ask, ran out of sensible single-char argument shorthands). Yes, it has an ugly main() with 15 keyword arguments, but I'd also have that with fire I guess. but here at least it's explicit again.
TLDR: Sounds absolutely nice on first skim, but I don't see why I would ever use this. Have I been writing so many CLI apps in python already that I exhibit stockholm syndrome towards click AND optparse? :)
But if your code is changing, that's when you'll start to see larger time savings. With Fire, your CLI will stay up to date without you having to update any parsing code.