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

Any way to give negative number as argument ? #104

Open
Derf000 opened this issue Jul 13, 2023 · 1 comment
Open

Any way to give negative number as argument ? #104

Derf000 opened this issue Jul 13, 2023 · 1 comment

Comments

@Derf000
Copy link

Derf000 commented Jul 13, 2023

Hi,
is there any way to set negative number as argument ?

# -*- coding: utf-8 -*-

from clize import ArgumentError, Parameter, run

def cli_main(arg:float, *, debug:'d'=False):
    """cli_main
    
    :param arg: arg parameter
    :param debug: debug flag
    """
    return (arg,debug)

if __name__ == '__main__' :
    run (cli_main)
    
>python cli.py --help
Usage: cli.py [OPTIONS] arg

cli_main

Arguments:
  arg           arg paramter (type: FLOAT)

Options:
  -d, --debug   debug flag

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

>python cli.py -10.0
cli.py: Unknown option '-1'
Usage: cli.py [OPTIONS] arg

@epsy
Copy link
Owner

epsy commented Jul 17, 2023

Hello!

For positional parameters, I think the one way to pass along negative numbers would be to use the -- argument. After --, Clize and other parsers no longer treat - as a special character:

> python cli.py -- -10.0

If arg was an option rather than a positional argument, Clize would also pick it up because it occurs in a spot where it is not expecting an option:

def cli_main(*, arg: float, debug: 'd' = false):
    ...
> python cli.py --arg -10.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants