use agentic_navigation_guide::dumper::Dumper;
use agentic_navigation_guide::errors::Result;
use agentic_navigation_guide::types::Config;
use clap::Args;
use std::io::Write;
use std::path::PathBuf;
#[derive(Args, Debug)]
pub struct DumpArgs {
#[arg(short, long)]
pub output: Option<PathBuf>,
#[arg(short, long)]
pub depth: Option<usize>,
#[arg(short, long)]
pub exclude: Vec<String>,
#[arg(short, long, default_value = "2")]
pub indent: usize,
#[arg(long)]
pub omit_xml_wrapper: bool,
#[arg(short, long, env = "AGENTIC_NAVIGATION_GUIDE_ROOT")]
pub root: Option<PathBuf>,
}
impl DumpArgs {
pub fn execute(self, _config: &Config) -> Result<()> {
let root_path = self
.root
.unwrap_or_else(|| std::env::current_dir().expect("Failed to get current directory"));
log::debug!("Dumping directory: {}", root_path.display());
let dumper = Dumper::new(&root_path)
.with_max_depth(self.depth)
.with_exclude_patterns(&self.exclude)?
.with_indent_size(self.indent);
let output = if self.omit_xml_wrapper {
dumper.dump()?
} else {
dumper.dump_with_wrapper()?
};
if let Some(output_path) = self.output {
log::info!("Writing output to: {}", output_path.display());
std::fs::write(&output_path, output)?;
} else {
print!("{output}");
std::io::stdout().flush()?;
}
Ok(())
}
}