def wrapper(args, nested=False):
        """
        :param args: the argparse arguments
        :param nested: if this command was started from another command
        :return: a decorated function
        """

        success = True
        try:
            _set_authentication(args)
            func(args)
        except ArgumentSyntaxError as error:
            # Some commands have additional argument checks that are evaluated at runtime
            success = False
            if nested:
                # let the encapsulating command deal with the error
                raise error
            else:
                _handle_syntax_error(error)
        except McmdError as error:
            success = False
            if nested:
                # let the encapsulating command deal with the error
                raise error
            else:
                _handle_error(error)
        else:
            io.succeed()
        finally:
            if args.write_to_history:
                history.write(args.arg_string, success=success)
def _wait(wait: Wait, state: _ScriptExecutionState):
    text = '{}: {} {}'.format(bold('Waiting for user'),
                              wait.message.render(state.values),
                              dim('(Press enter to continue)'))
    io.start(text)
    io.wait_for_enter()
    io.succeed()
Example #3
0
def history(args):
    if args.clear:
        io.start('Clearing history')
        hist.clear()
    else:
        lines = hist.read(args.number, include_fails=True)
        if len(lines) == 0:
            log.info('History is empty.')
        for line in lines:
            io.start(line[1])
            if line[0]:
                io.succeed()
            else:
                io.error(None)
def _add_host():
    url = ask.input_("URL", required=True)
    if config.host_exists(url):
        raise McmdError("A host with URL {} already exists.".format(url))

    username = ask.input_("Username (Default: admin)")
    password = ask.password(
        "Password (Leave blank to use command line authentication)")

    username = '******' if len(username) == 0 else username
    password = None if len(password) == 0 else password

    io.start("Adding host {}".format(highlight(url)))
    config.add_host(url, username, password)
    io.succeed()
    return url
def _download_attachment(attachment, issue_num):
    issue_folder = context().get_issues_folder().joinpath(issue_num)
    issue_folder.mkdir(parents=True, exist_ok=True)
    file_path = issue_folder.joinpath(attachment.name)

    if file_path.exists():
        overwrite = mcmd.io.ask.confirm(
            'File %s already exists. Re-download?' % file_path.name)
        if not overwrite:
            return file_path

    io.start('Downloading %s from GitHub issue %s' %
             (highlight(attachment.name), highlight('#' + issue_num)))
    try:
        r = requests.get(attachment.url)
        r.raise_for_status()
        with file_path.open('wb') as f:
            f.write(r.content)
    except (OSError, requests.RequestException, requests.HTTPError) as e:
        raise McmdError('Error downloading GitHub attachment: %s' % str(e))
    io.succeed()
    return file_path
def _wait(message):
    text = '{}: {}   {}'.format(bold('Waiting for user'), message, dim('(Press enter to continue)'))
    io.start(text)
    io.wait_for_enter()
    io.succeed()