Skip to main content

hardpass/
lib.rs

1mod api;
2pub mod cli;
3mod cloud_init;
4mod images;
5mod instance;
6mod lock;
7mod ports;
8mod qemu;
9mod ssh;
10mod ssh_config;
11mod state;
12
13use anyhow::Result;
14
15pub use api::{Hardpass, RunningVm, Vm, VmSpec};
16use cli::{Args, Command, SshConfigCommand};
17use instance::InstanceManager;
18pub use instance::{VmInfo, VmSshInfo};
19pub use ssh::ExecOutput;
20use state::HardpassState;
21pub use state::{AccelMode, GuestArch, InstanceStatus, PortForward};
22
23pub async fn run(args: Args) -> Result<()> {
24    let state = HardpassState::load().await?;
25    let manager = InstanceManager::new(state);
26    match args.command {
27        Command::Doctor => manager.doctor().await,
28        Command::Create(args) => manager.create(args).await,
29        Command::Start(args) => manager.start(&args.name).await,
30        Command::Stop(args) => manager.stop(&args.name).await,
31        Command::Delete(args) => manager.delete(&args.name).await,
32        Command::List => manager.list().await,
33        Command::Info(args) => manager.info(&args.name, args.json).await,
34        Command::SshConfig(args) => match args.command {
35            SshConfigCommand::Install => manager.install_ssh_config().await,
36            SshConfigCommand::Sync => manager.sync_ssh_config().await,
37        },
38        Command::Ssh(args) => manager.ssh(&args.name, &args.ssh_args).await,
39        Command::Exec(args) => manager.exec(&args.name, &args.command).await,
40    }
41}