feat: refactor output filename handling and enhance argument parsing
This commit is contained in:
29
src/main.rs
29
src/main.rs
@@ -2,7 +2,7 @@ use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use codebase_to_prompt::Format;
|
||||
use std::path::PathBuf;
|
||||
use tracing::level_filters::LevelFilter;
|
||||
use tracing::{info, level_filters::LevelFilter};
|
||||
use tracing_subscriber::FmtSubscriber;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
@@ -23,19 +23,19 @@ struct Args {
|
||||
#[arg(long, value_enum, default_value_t = Format::Console)]
|
||||
format: Format,
|
||||
|
||||
#[arg(long)]
|
||||
#[arg(short = 'd', long)]
|
||||
append_date: bool,
|
||||
|
||||
#[arg(long)]
|
||||
#[arg(short = 'g', long)]
|
||||
append_git_hash: bool,
|
||||
|
||||
#[arg(long)]
|
||||
#[arg(short = 'l', long)]
|
||||
line_numbers: bool,
|
||||
|
||||
#[arg(long)]
|
||||
#[arg(short = 'H', long)]
|
||||
ignore_hidden: bool,
|
||||
|
||||
#[arg(long, default_value_t = true)]
|
||||
#[arg(short = 'R', long, default_value_t = true)]
|
||||
respect_gitignore: bool,
|
||||
}
|
||||
|
||||
@@ -47,12 +47,25 @@ fn main() -> Result<()> {
|
||||
|
||||
let args = Args::parse();
|
||||
|
||||
// Automatically detect format if outputting to a .md file
|
||||
let mut format = args.format;
|
||||
if matches!(format, Format::Console) {
|
||||
if let Some(output_path) = &args.output {
|
||||
if output_path.extension().and_then(|s| s.to_str()) == Some("md") {
|
||||
format = Format::Markdown;
|
||||
}
|
||||
if output_path.extension().and_then(|s| s.to_str()) == Some("txt") {
|
||||
format = Format::Text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let config = codebase_to_prompt::Config {
|
||||
directory: args.directory,
|
||||
output: args.output,
|
||||
include: args.include,
|
||||
exclude: args.exclude,
|
||||
format: args.format,
|
||||
format,
|
||||
append_date: args.append_date,
|
||||
append_git_hash: args.append_git_hash,
|
||||
line_numbers: args.line_numbers,
|
||||
@@ -60,5 +73,7 @@ fn main() -> Result<()> {
|
||||
respect_gitignore: args.respect_gitignore,
|
||||
};
|
||||
|
||||
info!("Starting codebase to prompt with config: {:?}", config);
|
||||
|
||||
codebase_to_prompt::run(config)
|
||||
}
|
||||
|
Reference in New Issue
Block a user