epsy / clize

CLIze: Turn Python functions into command-line interfaces
http://clize.readthedocs.io/
MIT License
480 stars 26 forks source link

Any way to give negative number as argument ? #104

Open Derf000 opened 1 year ago

Derf000 commented 1 year ago

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 commented 1 year ago

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