flarer 0.1.0

Rust client and CLI for Cloudflare's Browser Rendering REST API (content, screenshot, PDF, snapshot, markdown, scrape, JSON extraction, links, crawl).
Documentation
//! `clap` argument parsing.

use clap::Parser;

use crate::tool::Tool;

/// Where to send tool output.
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
#[clap(rename_all = "lowercase")]
pub enum OutputMode {
    /// Print to stdout (or, for binary tools, save then print the path).
    Print,
    /// Save to disk (binary tools always do this regardless).
    File,
}

/// Top-level CLI arguments.
#[derive(Debug, Parser)]
#[command(
    name = "flarer",
    author,
    version,
    about = "CLI for Cloudflare Browser Rendering",
    long_about = None,
)]
pub struct Args {
    /// Run the interactive UI.
    #[arg(short, long)]
    pub interactive: bool,

    /// URL to render.
    #[arg(short, long, required_unless_present = "interactive")]
    pub url: Option<String>,

    /// Tool to invoke.
    #[arg(short, long, value_enum, default_value_t = Tool::Markdown)]
    pub tool: Tool,

    /// Output mode for non-binary tools.
    #[arg(short, long, value_enum, default_value_t = OutputMode::Print)]
    pub output: OutputMode,

    /// Optional prompt (only used by `--tool json`).
    #[arg(short, long)]
    pub prompt: Option<String>,

    /// Path to a JSON schema file (only used by `--tool json`).
    #[arg(long)]
    pub schema: Option<std::path::PathBuf>,

    /// Override the output directory.
    #[arg(long, env = "FLARER_OUTPUT_DIR")]
    pub output_dir: Option<std::path::PathBuf>,
}