Example #1
0
def main(args=None):
    if args is None:
        args = sys.argv[1:]
    import argparse
    parser = ConfigBackedParser(
        'hg-nbdiff',
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )

    add_diff_args(parser)
    add_diff_cli_args(parser)
    add_prettyprint_args(parser)
    add_filename_args(parser, ('base', 'remote'))

    opts = parser.parse_args(args)

    # TODO: Filter base/remote: If directories, find all modified notebooks
    # If files that are not notebooks, ensure a decent error is printed.
    if not os.path.isfile(opts.base) or not os.path.isfile(opts.remote):
        base, remote = opts.base, opts.remote
        for a, b in diff_directories(base, remote):
            opts.base, opts.remote = a, b
            ret = nbdiffapp.main_diff(opts)
            if ret != 0:
                return ret
        return ret
    else:
        return nbdiffapp.main_diff(opts)
Example #2
0
def _build_arg_parser():
    """Creates an argument parser for the nbdiff command."""
    parser = ConfigBackedParser(description=_description, add_help=True)
    from nbdime.args import (
        add_generic_args,
        add_diff_args,
        add_merge_args,
        filename_help,
        add_filename_args,
        add_prettyprint_args,
    )

    add_generic_args(parser)
    add_diff_args(parser)
    add_merge_args(parser)
    add_prettyprint_args(parser)

    parser.add_argument(
        "base",
        type=Path,
        help=filename_help["base"],
        nargs="?",
        default=EXPLICIT_MISSING_FILE,
    )
    add_filename_args(parser, ["local", "remote"])

    parser.add_argument(
        "--out",
        default=None,
        type=Path,
        help="if supplied, the merged notebook is written "
        "to this file. Otherwise it is printed to the "
        "terminal.",
    )
    parser.add_argument(
        "--decisions",
        action="store_true",
        help="print a human-readable summary of conflicted "
        "merge decisions instead of merging the notebook.",
    )

    return parser
def _build_arg_parser():
    import argparse
    parser = ConfigBackedParser(
        'git-nbdiffdriver',
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )
    add_generic_args(parser)

    subparsers = parser.add_subparsers(dest='subcommand')

    diff_parser = subparsers.add_parser(
        'diff',
        description=
        "The actual entrypoint for the diff tool. Git will call this.")
    add_git_diff_driver_args(diff_parser)
    add_diff_args(diff_parser)
    add_diff_cli_args(diff_parser)
    add_prettyprint_args(diff_parser)

    webdiff_parser = subparsers.add_parser(
        'webdiff',
        description=
        "The actual entrypoint for the webdiff tool. Git will call this.")
    add_git_diff_driver_args(webdiff_parser)
    add_diff_args(webdiff_parser)
    add_web_args(webdiff_parser, 0)

    # TODO: From git docs: "For a path that is unmerged, GIT_EXTERNAL_DIFF is called with 1 parameter, <path>."
    add_git_config_subcommand(
        subparsers,
        enable,
        disable,
        subparser_help=
        "Configure git to use nbdime for notebooks in `git diff`",
        enable_help="enable nbdime diff driver via git config",
        disable_help="disable nbdime diff driver via git config")

    return parser