profile-inspect 0.1.2

Analyze V8 CPU and heap profiles from Node.js/Chrome DevTools
Documentation
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;

/// Top-level command enum
#[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(),
        }
    }
}

/// Build the CLI parser
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"))
}