mod exec;
mod info;
mod log;
mod run;
use anyhow::{anyhow, Result};
use std::ops::Deref;
use structopt::{clap::AppSettings, StructOpt};
pub use self::log::LogOptions;
#[derive(StructOpt, Debug)]
pub enum Command {
Info(info::Options),
#[structopt(setting(AppSettings::Hidden))]
Exec(exec::Options),
Run(run::Options),
}
use crate::backend::{Backend, BACKENDS};
#[derive(StructOpt, Debug)]
pub struct BackendOptions {
#[structopt(long, env = "ENARX_BACKEND")]
backend: Option<String>,
}
impl BackendOptions {
pub fn pick(&self) -> Result<&dyn Backend> {
if let Some(ref name) = self.backend {
BACKENDS
.deref()
.iter()
.find(|b| b.have() && b.name() == name)
.ok_or_else(|| anyhow!("Keep backend {:?} is unsupported", name))
} else {
BACKENDS
.deref()
.iter()
.find(|b| b.have())
.ok_or_else(|| anyhow!("No supported backend found"))
}
.map(|b| &**b)
}
}
use crate::workldr::{Workldr, WORKLDRS};
#[derive(StructOpt, Debug)]
pub struct WorkldrOptions {
}
impl WorkldrOptions {
pub fn pick(&self) -> Result<&dyn Workldr> {
WORKLDRS
.deref()
.iter()
.find(|_| true)
.ok_or_else(|| anyhow!("No supported workldr found"))
.map(|b| &**b)
}
}