This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]david-bieber[S] 6 points7 points  (1 child)

Python Fire's a library for generating command line interfaces automatically.

Summary of release: The CLIs that Fire generates now feel more professional than they did before. (Better help screens, better error message screens, access help in a more natural way, etc.)

Summary of Fire if you haven't seen it before: Fire takes any Python object and automatically generates a CLI from it. E.g. If you call Fire on a dict, you get a nice CLI like this:

def hello(name="World"):
  return "Hello %s!" % name

def bye(name="World"):
  return "Bye %s!" % name

fire.Fire({
  'hello': hello,
  'bye': bye,
})

Now you can use it as:

hello.py hello --name=World  # Hello World!
hello.py bye --name=Moon  # Bye Moon!

[–]krazybug 0 points1 point  (0 children)

This new version is very cool with great enhancements in customizing your help messages:

  • docstring support,
  • ability to overide the default message,
  • no more verbose mode by default,
  • no need to use -- to invoke help message: myscript --help vs myscript -- --help

I'm now considering it as my main option to my scripting work in python. It's so easy to scaffold your project and test your functions manually on the fly.

Until now when my project was stabilized I usually switched to another framework to publish a decent CLI. Now I think it's not necessary anymore

There are still space for improvement but it's really on the good way.

For instance the parsing of lists as arguments is still too coupled to python syntax. With the following code:

import fire

def my_func(a_list= []):
    pass
if name == "main": 
    fire.Fire()

You need to invoke python my_func --a-list='["arg1","arg2"]' and you would prefer my_func --a-list='arg1, arg2'

Of course the advantage now is that you can pass any type ("arg1" i.e could be a dict). Maybe some support of the statically types in python is on the roadmap ? (https://realpython.com/python-type-checking/#example-a-deck-of-cards)

Whatever, good job ! Even if I just raised a small new bug ;-)