#! /usr/bin/python3 -sP
# -*- coding: utf-8 -*-

import argparse
import os
import sys

here = sys.path[0]
if here != "/usr/bin":
    sys.path.insert(0, os.path.dirname(here))

from compose_utils import symlink


def main(args):
    parser = argparse.ArgumentParser()
    parser.add_argument("COMPOSE")
    g = parser.add_mutually_exclusive_group()
    g.add_argument(
        "--minor-version",
        dest="version",
        action="store_const",
        const=symlink.VersionType.MINOR,
    )
    g.add_argument(
        "--full-version",
        dest="version",
        action="store_const",
        const=symlink.VersionType.FULL,
    )

    args = parser.parse_args()
    version_type = args.version or symlink.VersionType.MAJOR
    if args.COMPOSE.startswith("http://") or args.COMPOSE.startswith("https://"):
        # We can't create a symlink to a URL. Just print what it would be.
        symlink.print_latest_link(args.COMPOSE, version_type=version_type)
    else:
        symlink.create_latest_link(args.COMPOSE, version_type=version_type)


if __name__ == "__main__":
    main(sys.argv[1:])
