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

[Question] Simple version printing #34

Open
Kristinita opened this issue Jan 6, 2018 · 5 comments
Open

[Question] Simple version printing #34

Kristinita opened this issue Jan 6, 2018 · 5 comments

Comments

@Kristinita
Copy link

1. Problem

In most programs, what I use, I can get version, use --version and -v command line arguments without additional parameters.

D:\SashaPythonista>python SashaAscent.py --version
Do Nothing version 0.2

or

D:\SashaPythonista>python SashaAscent.py -v
0.2

I don't understand, how I can to create the same behavior, if I write a program, use Clize.

2. Attempts

1. First

from clize import run

VERSION = "0.2"


def program_version(version):
    print(VERSION)

run(program_version)

That get a version, I need input version, not --version:

D:\SashaPythonista>python SashaAscent.py version
0.2

D:\SashaPythonista>python SashaAscent.py --version
SashaAscent.py: Unknown option '--version'
Usage: SashaAscent.py version

2. Second

from clize import run

VERSION = "0.2"


def program_version(b="VERSION", *, version:'v'=True):
    """Show the version"""
    if version is True:
        b = "0.2"
        print(b)

run(program_version)

I need input -v b, not -v:

D:\SashaPythonista>python SashaAscent.py -v b
0.2

3. Third

from clize import run

VERSION = "0.2"


def do_nothing():
    """Does nothing"""
    return "I did nothing, I swear!"


def version():
    """Show the version"""
    print(VERSION)

run(do_nothing, alt=version)

It works for --version,

D:\SashaPythonista>python SashaAscent.py --version
0.2

but I don't find, how I can to create alias -v.

4. Fourth

It works nice.

from clize import run

VERSION = "0.2"


def do_nothing():
    """Does nothing"""
    return "I did nothing, I swear!"


def version():
    """Show the version"""
    print(VERSION)


def v():
    """Show the version"""
    print(VERSION)

run(do_nothing, alt=[version, v])

But in --help menu -v is not --version alias.

Actual:

D:\SashaPythonista>python SashaAscent.py --help
Usage: SashaAscent.py

Does nothing

Other actions:
  -h, --help   Show the help
  --version    Show the version
  -v           Show the version

Expected:

D:\SashaPythonista>python SashaAscent.py --help
Usage: SashaAscent.py

Does nothing

Other actions:
  -h, --help     Show the help
  -v, --version  Show the version

Thanks.

@epsy
Copy link
Owner

epsy commented Jan 6, 2018

It doesn't look like there is a way to have aliases for an 'alt=' function yet, sorry.

I'll look into it.

@Kristinita
Copy link
Author

Maybe you make, that -v will alias for --version default?

Thanks.

@epsy
Copy link
Owner

epsy commented Jan 17, 2018

I can't really do that, users might use -v for --verbose or anything else, whether or not they use --version

@Kristinita
Copy link
Author

@epsy, any ideas?

If sasha_clize_pylint.py:

"""Clize + Pylint."""
from clize import run

VERSION = "0.2"


def do_nothing():
    """Nothing."""
    return "I did nothing, I swear!"


def version():
    """Show the version."""
    print(VERSION)


def v():
    """Show the version."""
    print(VERSION)


run(do_nothing, alt=[version, v])

pylint output:

D:\SashaDebugging\SashaPython>pylint sasha__clize_pylint.py
************* Module sasha__clize_pylint
sasha__clize_pylint.py:17:0: C0103: Function name "v" doesn't conform to snake_case naming style (invalid-name)

-----------------------------------
Your code has been rated at 8.89/10

Function name must contain more than one symbol.

Thanks.

@epsy
Copy link
Owner

epsy commented Sep 3, 2018

It remains that clize.runner.Clize._process_alt (https://github.com/epsy/clize/blob/master/clize/runner.py#L203) would need to be updated to handle a dict with tuple-like keys like clize.runner.cli_commands and I still haven't gotten around to it, sorry.

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