from cutekit import cli, model, shell, builder

@cli.command(None, "boot", "Boot the kernel inside of Qemu")
def _(args: model.RegistryArgs):
    registry = model.Registry.use(args)

    target = registry.lookup('kernel-riscv32', model.Target)
    assert target is not None

    component = registry.lookup('core', model.Component)
    assert component is not None

    scope = builder.TargetScope(registry, target)
    kernelProduct = builder.build(scope, component)[0]

    shell.exec(*[
        "qemu-system-riscv32",
        "-machine", "virt",
        "-bios", "default",
        "-nographic",
        "-serial", "mon:stdio",
        "-kernel", str(kernelProduct.path),
        "--no-reboot",
    ])