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

Refactor version printing in CLI with Click #159

Closed
alichtman opened this issue Oct 28, 2018 · 4 comments
Closed

Refactor version printing in CLI with Click #159

alichtman opened this issue Oct 28, 2018 · 4 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed refactor

Comments

@alichtman
Copy link
Owner

Here's a good example

def print_version(ctx, param, value):
    if not value or ctx.resilient_parsing:
        return
    click.echo('Version 1.0')
    ctx.exit()

@click.command()
@click.option('--version', is_flag=True, callback=print_version,
              expose_value=False, is_eager=True)
def hello():
    click.echo('Hello World!')
@alichtman alichtman added refactor help wanted Extra attention is needed good first issue Good for newcomers labels Oct 28, 2018
@nunomdc
Copy link
Contributor

nunomdc commented Oct 28, 2018

Here do we want to just duplicate the functionality of the current print_version_info function on a new one specific to Click?
Because it seems that there is a requirement regarding the print_version function arguments.

Or instead make the existing function only return the version string and move it to e.g. utils.py

@alichtman
Copy link
Owner Author

I'm actually not sure this makes sense to change. The way it's engineered at the moment works fine for both the -v arg and the CLI splash screen. Let's just leave this as it is.

@nunomdc
Copy link
Contributor

nunomdc commented Oct 29, 2018

Can we at least make it so both "-v" and "--version" work to print the version information?

@alichtman
Copy link
Owner Author

alichtman commented Oct 29, 2018

Yep, this should be as easy as adding --version to the click option.

Open an Issue (#162)

Open a PR and I'll merge it.

@nunomdc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed refactor
Projects
None yet
Development

No branches or pull requests

2 participants