Add an argparse argument to a parse from one option of one :class:`Optionable`

    >>> comp = Optionable()
    >>> comp.add_option("num", Numeric(default=1, max=12, help="An exemple of option"))
    >>> parser = argparse.ArgumentParser(prog="PROG")
    >>> argument_from_option(parser, comp, "num")
    >>> parser.print_help()
    usage: PROG [-h] [--num NUM]
    <BLANKLINE>
    optional arguments:
      -h, --help  show this help message and exit
      --num NUM   An exemple of option
    >>> parser.parse_args(["--num", "2"])
    Namespace(num=2)
    >>> parser.parse_args(["--num", "20"])          # doctest: +SKIP
    Traceback (most recent call last):
    ...
    ValidationError: [u'Ensure this value ("20") is less than or equal to 12.']

def argument_from_option(parser, component, opt_name, prefix=""):
    """ Add an argparse argument to a parse from one option of one :class:`Optionable`

    >>> comp = Optionable()
    >>> comp.add_option("num", Numeric(default=1, max=12, help="An exemple of option"))
    >>> parser = argparse.ArgumentParser(prog="PROG")
    >>> argument_from_option(parser, comp, "num")
    >>> parser.print_help()
    usage: PROG [-h] [--num NUM]
    <BLANKLINE>
    optional arguments:
      -h, --help  show this help message and exit
      --num NUM   An exemple of option
    >>> parser.parse_args(["--num", "2"])
    Namespace(num=2)
    >>> parser.parse_args(["--num", "20"])          # doctest: +SKIP
    Traceback (most recent call last):
    ...
    ValidationError: [u'Ensure this value ("20") is less than or equal to 12.']
    """
    assert component.has_option(opt_name), "'%s' is not an option of the given component" % opt_name
    option = component.options[opt_name]
    argument_name = "%s%s" % (prefix, opt_name)
    otype = option.otype
    config = {}
    config["action"] = "store"
    config["dest"] = argument_name
    config["help"] = otype.help
    config["default"] = otype.default
    if otype.choices is not None:
        config["choices"] = otype.choices

    if isinstance(otype, Boolean):
        config["action"] = "store_true"
        if config["default"]:
            config["action"] = "store_false"
            # ADD a "not" in the name
            argument_name = "%snot-%s" % (prefix, opt_name)
    else:
        # Not boolean
        def check_type(value):
            try:
                value = option.parse(value)
                option.validate(value)
            except ValidationError as err_list:
                raise argparse.ArgumentTypeError("\n".join(err for err in err_list))
            return value
        config["type"] = check_type

    parser.add_argument(
        "--%s" % argument_name,
        **config
    )