use clap::Parser;
use nix::unistd;
use podmod::config;
use std::env;
use std::path;
pub mod cli;
fn main() {
if env::consts::OS != "linux" {
panic!("Must run on Linux");
}
let args = cli::CLI::parse();
let config: config::Config = config::parse(&args.config);
let module_config = match args.command {
cli::Command::Build { ref module, .. } |
cli::Command::Load { ref module, .. } |
cli::Command::Run { ref module, .. } |
cli::Command::Shell { ref module, .. } |
cli::Command::Unload { ref module, .. } => {
Some(config::module(&config.tree, &module))
}
_ => None,
};
if !unistd::Uid::effective().is_root() {
panic!("Must be run as root");
}
if !path::Path::new(&config.data_dir).is_dir() {
panic!("Data directory does not exist")
}
match args.command {
cli::Command::Build { idempotent, no_prune, .. } => {
podmod::build(&config, &module_config.unwrap(), idempotent, no_prune)
},
cli::Command::Load { idempotent, .. } => {
podmod::load(&module_config.unwrap(), idempotent)
},
cli::Command::Modules {} => {
podmod::modules(&config)
},
cli::Command::Run { command, .. } => {
podmod::run(&module_config.unwrap(), &command);
},
cli::Command::Shell { shell, .. } => {
podmod::shell(&module_config.unwrap(), &shell);
}
cli::Command::Unload { idempotent, .. } => {
podmod::unload(&module_config.unwrap(), idempotent)
}
};
}