breakmancer 0.1.1

Drop a breakpoint into any shell.
//! Command line entry point.

#![warn(clippy::all)]
#![warn(clippy::pedantic)]

use std::process;

use clap::{Parser, Subcommand};

mod breakpoint;
mod debug_utils;
mod listen;
mod protocol;
mod sigint;
mod test_utils;
mod util;

#[derive(Debug, Parser)]
#[command(name = "breakmancer")]
#[command(about = "Drop a breakpoint into any shell.")]
#[command(version, arg_required_else_help = true)]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand, Debug)]
enum Commands {
    /// Start a new session.
    ///
    /// When `listen` is called, it will give you a command to run on
    /// the breakpoint host. The breakpoint end will try to open a connection
    /// to the callback address, at which point a secure handshake
    /// will occur and a debugging session can start.
    #[command()]
    Listen(listen::Cli),

    /// Break for debugging.
    ///
    /// Call back to a `listen` session so that the developer can run
    /// commands in this environment. This command and its parameters
    /// will be provided by the output of the `listen` command.
    #[command()]
    Break(breakpoint::Cli),
}

#[tokio::main]
async fn main() {
    let args = Cli::parse();

    let outcome = match args.command {
        Commands::Listen(args) => listen::run(&args).await,
        Commands::Break(args) => breakpoint::run(&args).await,
    };
    if let Err(err) = outcome {
        eprintln!("{err}");
        process::exit(1)
    }
}