Example #1
0
def main(args=None):  # pylint: disable=R0915
    """Process command-line arguments and run the program."""
    from doorstop import CLI, VERSION, DESCRIPTION

    # Shared options
    project = argparse.ArgumentParser(add_help=False)
    project.add_argument('-j', '--project', metavar='PATH',
                         help="path to the root of the project")
    project.add_argument('--no-cache', action='store_true',
                         help=argparse.SUPPRESS)
    server = argparse.ArgumentParser(add_help=False)
    server.add_argument('--server', metavar='HOST',
                        help="IP address or hostname for a running server")
    server.add_argument('--port', metavar='NUMBER', type=int,
                        help="use a custom port for the server")
    server.add_argument('-f', '--force', action='store_true',
                        help="perform the action without the server")
    debug = argparse.ArgumentParser(add_help=False)
    debug.add_argument('-V', '--version', action='version', version=VERSION)
    group = debug.add_mutually_exclusive_group()
    group.add_argument('-v', '--verbose', action='count', default=0,
                       help="enable verbose logging")
    group.add_argument('-q', '--quiet', action='store_const', const=-1,
                       dest='verbose', help="only display errors and prompts")
    shared = {'formatter_class': common.HelpFormatter,
              'parents': [project, server, debug]}

    # Build main parser
    parser = argparse.ArgumentParser(prog=CLI, description=DESCRIPTION,
                                     **shared)
    parser.add_argument('-F', '--no-reformat', action='store_true',
                        help="do not reformat item files during validation")
    parser.add_argument('-r', '--reorder', action='store_true',
                        help="reorder document levels during validation")
    parser.add_argument('-L', '--no-level-check', action='store_true',
                        help="do not validate document levels")
    parser.add_argument('-R', '--no-ref-check', action='store_true',
                        help="do not validate external file references")
    parser.add_argument('-C', '--no-child-check', action='store_true',
                        help="do not validate child (reverse) links")
    parser.add_argument('-S', '--no-suspect-check', action='store_true',
                        help="do not check for suspect links")
    parser.add_argument('-W', '--no-review-check', action='store_true',
                        help="do not check item review status")
    parser.add_argument('-w', '--warn-all', action='store_true',
                        help="display all info-level issues as warnings")
    parser.add_argument('-e', '--error-all', action='store_true',
                        help="display all warning-level issues as errors")

    # Build sub-parsers
    subs = parser.add_subparsers(help="", dest='command', metavar="<command>")
    _create(subs, shared)
    _delete(subs, shared)
    _add(subs, shared)
    _remove(subs, shared)
    _edit(subs, shared)
    _reorder(subs, shared)
    _link(subs, shared)
    _unlink(subs, shared)
    _clear(subs, shared)
    _review(subs, shared)
    _import(subs, shared)
    _export(subs, shared)
    _publish(subs, shared)

    # Parse arguments
    args = parser.parse_args(args=args)

    # Configure logging
    utilities.configure_logging(args.verbose)

    # Configure settings
    utilities.configure_settings(args)

    # Run the program
    function = commands.get(args.command)
    try:
        success = function(args, os.getcwd(), parser.error)
    except KeyboardInterrupt:
        log.debug("command cancelled")
        success = False
    if success:
        log.debug("command succeeded")
    else:
        log.debug("command failed")
        sys.exit(1)
Example #2
0
def main(args=None):  # pylint: disable=R0915
    """Process command-line arguments and run the program."""
    from doorstop import CLI, VERSION, DESCRIPTION

    # Shared options
    project = argparse.ArgumentParser(add_help=False)
    try:
        root = vcs.find_root(os.getcwd())
    except common.DoorstopError:
        root = None
    project.add_argument(
        '-j',
        '--project',
        metavar='PATH',
        help="path to the root of the project",
        default=root,
    )
    project.add_argument('--no-cache',
                         action='store_true',
                         help=argparse.SUPPRESS)
    server = argparse.ArgumentParser(add_help=False)
    server.add_argument(
        '--server',
        metavar='HOST',
        help="IP address or hostname for a running server",
        default=settings.SERVER_HOST,
    )
    server.add_argument(
        '--port',
        metavar='NUMBER',
        type=int,
        help="use a custom port for the server",
        default=settings.SERVER_PORT,
    )
    server.add_argument(
        '-f',
        '--force',
        action='store_true',
        help="perform the action without the server",
    )
    debug = argparse.ArgumentParser(add_help=False)
    debug.add_argument('-V', '--version', action='version', version=VERSION)
    group = debug.add_mutually_exclusive_group()
    group.add_argument('-v',
                       '--verbose',
                       action='count',
                       default=0,
                       help="enable verbose logging")
    group.add_argument(
        '-q',
        '--quiet',
        action='store_const',
        const=-1,
        dest='verbose',
        help="only display errors and prompts",
    )
    shared = {
        'formatter_class': common.HelpFormatter,
        'parents': [project, server, debug],
    }

    # Build main parser
    parser = argparse.ArgumentParser(prog=CLI,
                                     description=DESCRIPTION,
                                     **shared)
    parser.add_argument(
        '-F',
        '--no-reformat',
        action='store_true',
        help="do not reformat item files during validation",
    )
    parser.add_argument(
        '-r',
        '--reorder',
        action='store_true',
        help="reorder document levels during validation",
    )
    parser.add_argument(
        '-L',
        '--no-level-check',
        action='store_true',
        help="do not validate document levels",
    )
    parser.add_argument(
        '-R',
        '--no-ref-check',
        action='store_true',
        help="do not validate external file references",
    )
    parser.add_argument(
        '-C',
        '--no-child-check',
        action='store_true',
        help="do not validate child (reverse) links",
    )
    parser.add_argument(
        '-Z',
        '--strict-child-check',
        action='store_true',
        help="require child (reverse) links from every document",
    )
    parser.add_argument(
        '-S',
        '--no-suspect-check',
        action='store_true',
        help="do not check for suspect links",
    )
    parser.add_argument(
        '-W',
        '--no-review-check',
        action='store_true',
        help="do not check item review status",
    )
    parser.add_argument(
        '-s',
        '--skip',
        metavar='PREFIX',
        action='append',
        help="skip a document during validation",
    )
    parser.add_argument(
        '-w',
        '--warn-all',
        action='store_true',
        help="display all info-level issues as warnings",
    )
    parser.add_argument(
        '-e',
        '--error-all',
        action='store_true',
        help="display all warning-level issues as errors",
    )

    # Build sub-parsers
    subs = parser.add_subparsers(help="", dest='command', metavar="<command>")
    _create(subs, shared)
    _delete(subs, shared)
    _add(subs, shared)
    _remove(subs, shared)
    _edit(subs, shared)
    _reorder(subs, shared)
    _link(subs, shared)
    _unlink(subs, shared)
    _clear(subs, shared)
    _review(subs, shared)
    _import(subs, shared)
    _export(subs, shared)
    _publish(subs, shared)

    # Parse arguments
    args = parser.parse_args(args=args)

    # Configure logging
    utilities.configure_logging(args.verbose)

    # Configure settings
    utilities.configure_settings(args)

    # Run the program
    function = commands.get(args.command)
    try:
        success = function(args, os.getcwd(), parser.error)
    except common.DoorstopFileError as exc:
        log.error(exc)
        success = False
    except KeyboardInterrupt:
        log.debug("command cancelled")
        success = False
    if success:
        log.debug("command succeeded")
    else:
        log.debug("command failed")
        sys.exit(1)
Example #3
0
def main(args=None):  # pylint: disable=R0915
    """Process command-line arguments and run the program."""
    from doorstop import CLI, VERSION, DESCRIPTION

    # Shared options
    debug = argparse.ArgumentParser(add_help=False)
    debug.add_argument('-j', '--project', metavar='PATH',
                       help="path to the root of the project")
    debug.add_argument('-V', '--version', action='version', version=VERSION)
    group = debug.add_mutually_exclusive_group()
    group.add_argument('-v', '--verbose', action='count', default=0,
                       help="enable verbose logging")
    group.add_argument('-q', '--quiet', action='store_const', const=-1,
                       dest='verbose', help="only display errors and prompts")
    shared = {'formatter_class': common.HelpFormatter, 'parents': [debug]}

    # Build main parser
    parser = argparse.ArgumentParser(prog=CLI, description=DESCRIPTION,
                                     **shared)
    parser.add_argument('-F', '--no-reformat', action='store_true',
                        help="do not reformat item files during validation")
    parser.add_argument('-r', '--reorder', action='store_true',
                        help="reorder document levels during validation")
    parser.add_argument('-L', '--no-level-check', action='store_true',
                        help="do not validate document levels")
    parser.add_argument('-R', '--no-ref-check', action='store_true',
                        help="do not validate external file references")
    parser.add_argument('-C', '--no-child-check', action='store_true',
                        help="do not validate child (reverse) links")
    parser.add_argument('-S', '--no-suspect-check', action='store_true',
                        help="do not check for suspect links")
    parser.add_argument('-W', '--no-review-check', action='store_true',
                        help="do not check item review status")

    # Build sub-parsers
    subs = parser.add_subparsers(help="", dest='command', metavar="<command>")
    _create(subs, shared)
    _delete(subs, shared)
    _add(subs, shared)
    _remove(subs, shared)
    _edit(subs, shared)
    _reorder(subs, shared)
    _link(subs, shared)
    _unlink(subs, shared)
    _clear(subs, shared)
    _review(subs, shared)
    _import(subs, shared)
    _export(subs, shared)
    _publish(subs, shared)

    # Parse arguments
    args = parser.parse_args(args=args)

    # Configure logging
    utilities.configure_logging(args.verbose)

    # Configure settings
    utilities.configure_settings(args)

    # Run the program
    function = commands.get(args.command)
    try:
        success = function(args, os.getcwd(), parser.error)
    except KeyboardInterrupt:
        log.debug("command cancelled")
        success = False
    if success:
        log.debug("command succeeded")
    else:
        log.debug("command failed")
        sys.exit(1)