How to use the docopt.DocoptExit function in docopt

To help you get started, we’ve selected a few docopt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github miso-belica / sumy / tests / test_main.py View on Github external
def test_args_none():
    with pytest.raises(DocoptExit):
        docopt(to_string(main_doc), None, version=__version__)
github rachmadaniHaryono / we-get / tests / test_core_we_get.py View on Github external
def test_parse_arguments(argv, exp_res):
    wg = WG()
    if argv is None:
        with pytest.raises(DocoptExit):
            wg.parse_arguments()
        assert vars(wg) == exp_res
        with pytest.raises(DocoptExit):
            wg.parse_arguments(argv)
        assert vars(wg) == exp_res
    else:
        wg.parse_arguments(argv)
        assert vars(wg) == exp_res
github dcos / dcos / packages / winpanda / extra / src / winpanda / bin / winpanda.py View on Github external
default_cmd_target=CLI_CMDTARGET.PKGALL,
            default_root_dpath=storage.DCOS_INST_ROOT_DPATH_DFT,
            default_config_dpath=storage.DCOS_INST_CFG_DPATH_DFT,
            default_state_dpath=storage.DCOS_INST_STATE_DPATH_DFT,
            default_repository_dpath=storage.DCOS_INST_PKGREPO_DPATH_DFT,
            default_var_dpath=storage.DCOS_INST_VAR_DPATH_DFT,
            default_clustercfg_fpath=cm_const.DCOS_CLUSTER_CFG_FNAME_DFT
        )

        cli_args = docopt(cli_argspec)

        # Verify actual command target value
        cmdtarget = cli_args.get('--target')
        if cmdtarget not in VALID_CLI_CMDTARGETS:
            LOG.critical(f'CLI: Invalid option value: --target: {cmdtarget}')
            raise DocoptExit()

        LOG.debug(f'cli_args: {cli_args}')

        return cli_args
github projectcalico / k8s-exec-plugin / calico_kubernetes / policy.py View on Github external
def parse_line(self, policy):
        """
        Takes a single line of policy as defined in the annotations of a
        pod and returns the equivalent libcalico Rule object.
        :param policy: Policy string from annotations.
        :return: A Rule object which represent the given policy.
        """
        _log.info("Parsing policy line: '%s'", policy)
        splits = policy.split()

        try:
            args = docopt.docopt(__doc__, argv=splits)
        except docopt.DocoptExit:
            raise ValueError("Failed to parse policy: %s", policy)

        # Generate a rule object from the arguments.
        rule = self._generate_rule(args)

        return rule
github mgaitan / miau / miau.py View on Github external
raise DocoptExit(
            "Input mismatch: the quantity of inputs and transcriptions differs"
        )

    try:
        return miau(
            media,
            transcripts,
            args['--remix'],
            args['--output'],
            args['--dump'],
            debug=args['--debug'],
            force_language=args['--lang']
        )
    except ValueError as e:
        raise DocoptExit(str(e))
github mgaitan / miau / miau.py View on Github external
#  macri_gato.mp4 macri_gato.txt
    media = []
    transcripts = []
    for filename in chain.from_iterable(glob.iglob(pattern) for pattern in args['']):
        output_extension = os.path.splitext(filename)[1][1:]
        if output_extension in extensions_dict:
            media.append(filename)
        else:
            transcripts.append(filename)

    media_str = '   \n'.join(media)
    transcripts_str = '   \n'.join(transcripts)
    info = "Audio/Video:\n   {}\nTranscripts/subtitle:\n   {}".format(media_str, transcripts_str)
    logging.info(info)
    if not media or len(media) != len(transcripts):
        raise DocoptExit(
            "Input mismatch: the quantity of inputs and transcriptions differs"
        )

    try:
        return miau(
            media,
            transcripts,
            args['--remix'],
            args['--output'],
            args['--dump'],
            debug=args['--debug'],
            force_language=args['--lang']
        )
    except ValueError as e:
        raise DocoptExit(str(e))
github nephila / django-app-helper / app_helper / main.py View on Github external
def _map_argv(argv, application_module):
    try:
        # by default docopt uses sys.argv[1:]; ensure correct args passed
        args = docopt(__doc__, argv=argv[1:], version=application_module.__version__)
        if argv[2] == "help":
            raise DocoptExit()
    except DocoptExit:
        if argv[2] == "help":
            raise
        args = docopt(__doc__, argv[1:3], version=application_module.__version__)
    args["--cms"] = "--cms" in argv
    args["--persistent"] = "--persistent" in argv
    for arg in argv:
        if arg.startswith("--extra-settings="):
            args["--extra-settings"] = arg.split("=")[1]
        if arg.startswith("--runner="):
            args["--runner"] = arg.split("=")[1]
        if arg.startswith("--persistent-path="):
            args["--persistent-path"] = arg.split("=")[1]
            args["--persistent"] = True
    args["options"] = [argv[0]] + argv[2:]
    if args["test"] and "--native" in args["options"]:
github andsens / bootstrap-vz / bootstrapvz / base / main.py View on Github external
Usage: bootstrap-vz [options] MANIFEST

Options:
  --log
github mechboxes / mech / mech / command.py View on Github external
NBSP = '__'

def cmd_usage(doc):
    return doc.replace(NBSP, ' ')

docopt_extras_ref = docopt.extras
def docopt_extras(help, version, options, doc):
    return docopt_extras_ref(help, version, options, cmd_usage(doc))

def DocoptExit____init__(self, message=''):
    SystemExit.__init__(self, (message + '\n' + cmd_usage(self.usage)).strip())

docopt.extras = docopt_extras
docopt.DocoptExit.__init__ = DocoptExit____init__


def spaced(name):
    name = re.sub(r'[ _]+', r' ', name)
    name = re.sub(r'(?<=[^_])([A-Z])', r' \1', name).lower()
    return re.sub(r'^( *)(.*?)( *)$', r'\2', name)


class Command(object):
    """
    Usage: command  [...]
    """

    subcommand_name = ''
    argv_name = ''