import argparse
import importlib.metadata
from .utils import parse, copy_devenv

def main() -> None:
  parser = argparse.ArgumentParser(
    prog='devenvcp',
    description='Template init tool for devenv inspired by nix flake init'
  )
  parser.add_argument("path", type=str, help="Path to directory containing devenvcp.toml")
  parser.add_argument("template", type=str, help="Devenv template to copy")
  parser.add_argument("-v", "--version", action="store_true", help="Print version")
  parser.add_argument("-f", "--force", action="store_true", default=False, help="Force copy when there's conflicting files")
  args = parser.parse_args()

  if None not in (args.path, args.template):
    rel_path = parse(args.path, args.template)
    copy_devenv(args.path, rel_path, args.force)
  elif args.version:
    print(f"devenv v{importlib.metadata.version("devenv")}")
