Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] short flags/arguments does not work with **kwargs #454

Open
Diogo-Rossi opened this issue May 10, 2023 · 1 comment
Open

[bug] short flags/arguments does not work with **kwargs #454

Diogo-Rossi opened this issue May 10, 2023 · 1 comment

Comments

@Diogo-Rossi
Copy link

Diogo-Rossi commented May 10, 2023

Description:

Short flags/arguments (e.g. -u for --username) does not work with **kwargs

Example that works OK:

The following example works ok:

import fire

def cli(first_arg="left", second_arg="right"):
    """Prints the 2 arguments separated by bar
       
    Parameters
    ----------
    first_arg : str
        the first arg
    second_arg : str
        the second arg
    """
    print(f"{first_arg} | {second_arg}" )

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

Help output

❯ python .\example.py -- --help
NAME
    example.py - Prints the 2 arguments separated by bar

SYNOPSIS
    example.py <flags>

DESCRIPTION
    Prints the 2 arguments separated by bar

FLAGS
    -f, --first_arg=FIRST_ARG
        Default: 'left'
        the first arg
    -s, --second_arg=SECOND_ARG
        Default: 'right'
        the second arg

Usage with short flags

❯ python .\example.py -f="hello" -s="word"
hello | word

Example that does not work:

The following next example does not work with short flags, even when they are showing on the help output.
It is using **kwargs. It seems the short flags are going to the **kwargs dictionary.

import fire

def cli(first_arg="left", second_arg="right", **kwargs):
    """Prints the 2 arguments separated by bar
       
    Parameters
    ----------
    first_arg : str
        the first arg
    second_arg : str
        the second arg
    kwargs : str
        additional args
    """
    print(f"{first_arg} | {second_arg}" )
    print(kwargs)

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

Help output

❯ python .\example2.py -- --help
NAME
    example2.py - Prints the 2 arguments separated by bar

SYNOPSIS
    example2.py <flags>

DESCRIPTION
    Prints the 2 arguments separated by bar

FLAGS
    -f, --first_arg=FIRST_ARG
        Default: 'left'
        the first arg
    -s, --second_arg=SECOND_ARG
        Default: 'right'
        the second arg
    Additional flags are accepted.
        additional args

Usage with short flags

❯ python .\example2.py -f="hello" -s="word"
left | right
{'f': 'hello', 's': 'word'}

In summary: the -f and -s arguments should be parsing to --first_arg and --second_arg but they are parsing to kwargs

@Diogo-Rossi Diogo-Rossi changed the title [bug] short arguments does not work with **kwargs [bug] short flags/arguments does not work with **kwargs May 10, 2023
@parthosa
Copy link

parthosa commented Dec 4, 2023

Do we have any updates on this bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants