vmexec 0.7.0

Run a single command in a speedy virtual machine with zero-setup
Documentation
use std::time::Duration;

use color_eyre::Result;

use vmexec::{
    runner,
    types::{Interactive, Io, OsType, OsTypeOrImagePath, Pull},
    utils::{VmexecDirs, find_required_tools},
    vms::reserve_vm,
};

#[tokio::main]
async fn main() -> Result<()> {
    let dirs = VmexecDirs::new()?;
    let tool_paths = find_required_tools()?;

    let reservation = reserve_vm(&dirs, None)?;

    let run_opts = runner::RunOptions {
        image_source: OsTypeOrImagePath::OsType(OsType::Archlinux),
        pull: Pull::Missing,
        ssh_timeout: Duration::from_secs(20),
        memory: 4,
        disable_kvm: false,
        show_vm_window: false,
        tty: false,
        interactive: Interactive::Never,
        env_vars: vec![],
        workdir: None,
        args: vec!["echo".to_string(), "hello from inside the VM".to_string()],
        volumes: vec![],
        pmems: vec![],
        published_ports: vec![],
        // Capture the command's output instead of inheriting our stdout/stderr.
        stdout: Io::Piped,
        stderr: Io::Piped,
        rm: true,
    };
    let output = runner::prepare_and_run(&dirs, reservation, tool_paths, run_opts).await?;

    if let Some(output) = output {
        println!("exit code: {}", output.exit_code);
        println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
    }

    Ok(())
}