pub mod args;
pub mod bootstrap;
pub mod error;
pub mod explorer;
pub mod fragment;
pub mod generators;
pub mod rest;
use clap::Parser;
pub use error::MjolnirError;
use jortestkit::{load::Monitor, prelude::ProgressBarMode};
use std::error::Error;
#[derive(Parser)]
#[clap(rename_all = "kebab-case")]
pub struct Mjolnir {
#[clap(long = "full-version")]
full_version: bool,
#[clap(long = "source-version")]
source_version: bool,
#[clap(subcommand)]
command: Option<MjolnirCommand>,
}
#[allow(clippy::large_enum_variant)]
#[derive(Parser)]
#[clap(rename_all = "kebab-case")]
pub enum MjolnirCommand {
Passive(bootstrap::ClientLoadCommand),
Explorer(explorer::ExplorerLoadCommand),
#[clap(subcommand)]
Fragment(fragment::FragmentLoadCommand),
Rest(rest::RestLoadCommand),
}
impl Mjolnir {
pub fn exec(self) -> Result<(), Box<dyn Error>> {
use std::io::Write as _;
if self.full_version {
Ok(writeln!(std::io::stdout(), "{}", env!("FULL_VERSION"))?)
} else if self.source_version {
Ok(writeln!(std::io::stdout(), "{}", env!("SOURCE_VERSION"))?)
} else if let Some(cmd) = self.command {
cmd.exec()
} else {
writeln!(std::io::stderr(), "No command, try `--help'")?;
std::process::exit(1);
}
}
}
impl MjolnirCommand {
pub fn exec(self) -> Result<(), Box<dyn Error>> {
use self::MjolnirCommand::*;
match self {
Passive(bootstrap) => bootstrap.exec()?,
Explorer(explorer) => explorer.exec()?,
Fragment(fragment) => fragment.exec()?,
Rest(rest) => rest.exec()?,
};
Ok(())
}
}
pub fn build_monitor(progress_bar_mode: &ProgressBarMode) -> Monitor {
match progress_bar_mode {
ProgressBarMode::Monitor => Monitor::Progress(100),
ProgressBarMode::Standard => Monitor::Standard(100),
ProgressBarMode::None => Monitor::Disabled(10),
}
}