google/python-fire

Defaults for kwonly arguments don't show in help

melsabagh opened this issue · 2 comments

Fire (v0.4.0, master) does not seem to show default values for keyword-only arguments. Consider the following example:

#!/usr/bin/env python3

import fire


def foo(*, bar=True):
    print(bar)


if __name__ == '__main__':
    fire.Fire(foo)

Save it as foo.py and run python3 foo.py --help.

Expected Output:

INFO: Showing help with the command 'foo.py -- --help'.

NAME
    foo.py

SYNOPSIS
    foo.py <flags>

FLAGS
    --bar=BAR
        Default: True

Actual Output:

INFO: Showing help with the command 'foo.py -- --help'.

NAME
    foo.py

SYNOPSIS
    foo.py <flags>

FLAGS
    --bar=BAR

Looks like a one line change could fix this: change the return statement here

return ''
to:

    return repr(spec.kwonlydefaults.get(flag, ''))

Hi I would like to work on this issue.

Thanks!

return repr(spec.kwonlydefaults.get(flag, ''))

Thanks for identifying the fix. Quick note - repr('') doesn't evaluate to '', so that one-liner is quite right, but it gets the idea across. Let's include this improvement in the next release 👍