google/python-fire

cli for function created on the fly

tschm opened this issue · 1 comments

I have a function

def outer(strategy, default):
    """outer cli interface"""

    def inner(filename=default, output=Path.home() / "data"):
          # Do something with strategy

    expose inner as cli
    return fire.Fire(inner)

I was hoping fire works for this situation, too. Fire seems to try to execute the inner function.

The fire.Fire function always "fires off" / executes the command passed to it. If no command is passed, then sys.argv is used as the command (that's what lets it produce CLIs so easily). That's what's happening here.

If you want to get a new input from the user, you could do that before calling Fire, e.g.:

def outer(strategy, default):
    """outer cli interface"""

    def inner(filename=default, output=Path.home() / "data"):
          # Do something with strategy

    # expose inner as cli
    command = input()  # Get a new input from the user
    return fire.Fire(inner, command=command)