#!/usr/bin/env python3
import argparse
import sys

from script_common import dotnet_env, resolve_repo_root, run


DOTNET_SAFE_CMDS = {"restore", "build", "run", "test", "publish", "pack"}


def main() -> int:
    parser = argparse.ArgumentParser(description="Cross-platform minimal dotnet wrapper")
    parser.add_argument("dotnet_args", nargs=argparse.REMAINDER)
    parser.add_argument("--repo-root", default=None)
    args = parser.parse_args()

    if not args.dotnet_args:
        print("Usage: python scripts/dotnet-min.py <dotnet args>", file=sys.stderr)
        return 2

    repo_root = resolve_repo_root(args.repo_root)
    dotnet_args = list(args.dotnet_args)
    cmd = dotnet_args[0].lower()

    if cmd in DOTNET_SAFE_CMDS:
        dotnet_args.extend(["-p:RestoreIgnoreFailedSources=true", "-p:NuGetAudit=false"])
    if cmd == "restore":
        dotnet_args.append("--ignore-failed-sources")

    return run("dotnet", dotnet_args, repo_root, env=dotnet_env(repo_root))


if __name__ == "__main__":
    raise SystemExit(main())
