markdown-code-runner 0.1.0

Automatically update Markdown files with code block output
Documentation
//! CLI for markdown-code-runner.

use anyhow::Result;
use clap::Parser;
use std::path::PathBuf;

use markdown_code_runner::update_markdown_file;

/// Automatically update Markdown files with code block output.
#[derive(Parser, Debug)]
#[command(name = "markdown-code-runner")]
#[command(author, version, about, long_about = None)]
struct Args {
    /// Path to the input Markdown file
    input: PathBuf,

    /// Path to the output Markdown file (default: overwrite input file)
    #[arg(short, long)]
    output: Option<PathBuf>,

    /// Enable verbose/debug mode
    #[arg(short = 'd', long)]
    verbose: bool,

    /// Disable backtick standardization
    /// (default: enabled for separate output files, disabled for in-place)
    #[arg(long)]
    no_backtick_standardize: bool,

    /// Post-process to standardize ALL code fences,
    /// removing 'markdown-code-runner' modifiers
    #[arg(short, long)]
    standardize: bool,

    /// Skip code execution entirely
    /// (useful with --standardize for compatibility processing only)
    #[arg(short = 'n', long)]
    no_execute: bool,
}

fn main() -> Result<()> {
    let args = Args::parse();

    // Determine output filepath
    let output_filepath = args.output.as_deref();

    // Determine backtick standardization
    // By default, standardize if output file is different from input
    let backtick_standardize = if args.no_backtick_standardize {
        false
    } else {
        args.output.is_some()
    };

    update_markdown_file(
        &args.input,
        output_filepath,
        args.verbose,
        backtick_standardize,
        !args.no_execute,
        args.standardize,
    )
}