use std::path::PathBuf;
use clap::Parser;
use ignore::gitignore::GitignoreBuilder;
use crate::RenderMode;
const LONG_HELP: &str = r"Examples:
# Bundle selected files with H1 path labels
textcon src/main.rs src/lib.rs
# Bundle a directory with deterministic discovery
textcon src --exclude '*.generated.rs'
# Concatenate exact operand bytes
textcon --render raw src/*.rs
# Expand a template from a file or stdin
textcon --template context.md
printf '{{ @README.md }}' | textcon --template -
References:
{{ @file }} Include one file
{{ @directory }} Include selected descendants without labels
{{ @directory | markdown }} Include descendants with H1 path labels
{{ @path | raw }} Disable Markdown adaptation for this reference";
#[derive(Debug, Parser)]
#[command(
name = "textcon",
version,
about = "Stream files and template references into one predictable output",
after_long_help = LONG_HELP
)]
pub struct Cli {
#[arg(
value_name = "INPUT",
required_unless_present = "template",
conflicts_with = "template"
)]
pub inputs: Vec<PathBuf>,
#[arg(short, long, value_name = "FILE", conflicts_with = "inputs")]
pub template: Option<PathBuf>,
#[arg(long, value_enum, default_value_t = RenderMode::Markdown)]
pub render: RenderMode,
#[arg(short, long, value_name = "DIR", requires = "template")]
pub base_dir: Option<PathBuf>,
#[arg(long, requires = "template")]
pub sandbox: bool,
#[arg(short = 'd', long, value_name = "N")]
pub max_depth: Option<usize>,
#[arg(
short = 'x',
long = "exclude",
value_name = "PATTERN",
action = clap::ArgAction::Append,
value_parser = validate_exclude
)]
pub excludes: Vec<String>,
#[arg(long)]
pub no_gitignore: bool,
#[arg(long)]
pub hidden: bool,
}
fn validate_exclude(value: &str) -> Result<String, String> {
let mut builder = GitignoreBuilder::new(".");
builder
.add_line(None, value)
.map_err(|error| error.to_string())?;
builder.build().map_err(|error| error.to_string())?;
Ok(value.to_owned())
}