def main()

in index-tool/migrationtools/documentdb_index_tool.py [0:0]


def main():
    """
    parse command line arguments and
    """
    parser = argparse.ArgumentParser(
        description='Dump and restore indexes from MongoDB to DocumentDB.')

    parser.add_argument('--debug',
                        required=False,
                        action='store_true',
                        help='output debugging information')

    parser.add_argument(
        '--dry-run',
        required=False,
        action='store_true',
        help='Perform processing, but do not actually restore indexes')

    parser.add_argument('--dir',
                        required=True,
                        type=str,
                        help='dump to or restore from DIR')

    parser.add_argument('--show-compatible',
                        required=False,
                        action='store_true',
                        dest='show_compatible',
                        help='output all compatible indexes (without change)')

    parser.add_argument(
        '--show-issues',
        required=False,
        action='store_true',
        dest='show_issues',
        help='output a detailed structure of compatibility issues')

    parser.add_argument('--dump-indexes',
                        required=False,
                        action='store_true',
                        help='Dump indexes from the specified host/port')

    parser.add_argument(
        '--restore-indexes',
        required=False,
        action='store_true',
        help='Restore indexes found in metadata to the specified host/port')

    parser.add_argument(
        '--skip-incompatible',
        required=False,
        action='store_true',
        help='Skip incompatible indexes while dumping or restoring')

    parser.add_argument('--host',
                        required=False,
                        type=str,
                        default='localhost',
                        help='connect to host HOST (default: localhost)')

    parser.add_argument('--port',
                        required=False,
                        type=int,
                        default=27017,
                        help='connect to port PORT (default: 27017)')

    parser.add_argument('--username',
                        required=False,
                        type=str,
                        help='authenticate with username USERNAME')

    parser.add_argument('--password',
                        required=False,
                        type=str,
                        help='authenticate with password PASSWORD')

    parser.add_argument(
        '--auth-db',
        required=False,
        type=str,
        dest='auth_db',
        help='authenticate using database AUTH_DB (default: admin)')

    parser.add_argument('--tls',
                        required=False,
                        action='store_true',
                        help='connect using TLS')

    parser.add_argument('--tls-ca-file',
                        required=False,
                        type=str,
                        help='path to CA file used for TLS connection')

    args = parser.parse_args()

    if not (args.dump_indexes or args.restore_indexes or args.show_issues
            or args.show_compatible):
        message = "must specify one of [--dump-indexes | --restore-indexes | --show-issues | --show-compatible]"
        parser.error(message)

    if args.dir is not None:
        if not os.path.isdir(args.dir):
            parser.error("--dir must specify a directory")

    if args.dump_indexes is True:
        if args.restore_indexes is True:
            parser.error("cannot dump and restore indexes simultaneously")

    if any([args.username, args.password]):
        if not all([args.username, args.password]):
            parser.error(
                "both --username amd --password are required if providing MongoDB credentials."
            )

    if args.auth_db is not None and not all([args.username, args.password]):
        parser.error("--auth-db requires both --username and --password.")

    if args.auth_db is None and args.username is not None:
        args.auth_db = 'admin'

    indextool = DocumentDbIndexTool(args)
    indextool.run()