from follow_hive_nixpkgs.config import Config
from follow_hive_nixpkgs.lock import loadNixpkgs, writeNixpkgs
from pathlib import Path
import json


def dry_run(c: Config):
    s = loadNixpkgs(c.source_lock, c.source_nixpkgs)
    t = loadNixpkgs(c.target_lock, "nixpkgs")

    print(
        f"Would change {c.target_lock} from:\n{json.dumps(t, indent=2)} to:\n{json.dumps(s, indent=2)}\nWith values from {c.source_lock}"
    )


def main():
    c = Config.load(
        [
            Path.home() / ".config/follow-hive-nixpkgs/config.json",
            Path("/etc/follow-hive-nixpkgs/config.json"),
        ]
    )

    print(c)

    if c.dry:
        dry_run(c)
    else:
        s = loadNixpkgs(c.source_lock, c.source_nixpkgs)
        writeNixpkgs(s, c.target_lock)
