mod common;
mod cpu;
mod diff;
mod explain;
mod heap;
mod run;
use bpaf::{OptionParser, Parser, construct};
pub use cpu::CpuCommand;
pub use diff::DiffCommand;
pub use explain::ExplainCommand;
pub use heap::HeapCommand;
pub use run::RunCommand;
#[derive(Debug, Clone)]
pub enum Command {
Cpu(CpuCommand),
Heap(HeapCommand),
Diff(DiffCommand),
Explain(ExplainCommand),
Run(RunCommand),
}
impl Command {
pub fn run(self) -> Result<(), Box<dyn std::error::Error>> {
match self {
Self::Cpu(cmd) => cmd.run(),
Self::Heap(cmd) => cmd.run(),
Self::Diff(cmd) => cmd.run(),
Self::Explain(cmd) => cmd.run(),
Self::Run(cmd) => cmd.run(),
}
}
}
pub fn command() -> OptionParser<Command> {
let cpu = cpu::cpu_command().map(Command::Cpu);
let heap = heap::heap_command().map(Command::Heap);
let diff = diff::diff_command().map(Command::Diff);
let explain = explain::explain_command().map(Command::Explain);
let run = run::run_command().map(Command::Run);
construct!([cpu, heap, diff, explain, run])
.to_options()
.descr("Analyze V8 CPU and heap profiles")
.version(env!("CARGO_PKG_VERSION"))
}