Skip to content

Do not execute anything if command line is invalid #222

Closed
@MaxG87

Description

@MaxG87

In certain circumstances Fire will execute python code albeit the command line is not valid. Consider the following MWE:

#!/usr/bin/env python

import fire


def yet_another_function(*, argument: bool = False) -> None:
    print(f"Executing yet_another_function() with argument={argument}.")


if __name__ == "__main__":
    fire.Fire({"yaf": yet_another_function})

If I execute it with

./mwe.py yaf yet-another-argument

I get

Executing yet_another_function() with argument=False.
ERROR: Could not consume arg: yet-another-argument
Usage: mwe.py yaf

For detailed information on this command, run:
  mwe.py yaf --help

Note that the function is executed anyways.

In my case this behaviour let a bug manifest in a CI pipeline. I would have preferred to see the step break directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions