Some checks failed
Continuous Integration / Build and Test on ubuntu-latest (push) Failing after 1m27s
82 lines
2.2 KiB
Rust
82 lines
2.2 KiB
Rust
use anyhow::Result;
|
|
use clap::Parser;
|
|
use codebase_to_prompt::Format;
|
|
use std::path::PathBuf;
|
|
use tracing::{debug, level_filters::LevelFilter};
|
|
use tracing_subscriber::FmtSubscriber;
|
|
|
|
#[derive(Parser, Debug)]
|
|
#[command(author, version, about, long_about = None)]
|
|
struct Args {
|
|
#[arg(default_value = ".", value_delimiter = ' ', num_args=1..)]
|
|
directory: Vec<PathBuf>,
|
|
|
|
#[arg(short, long)]
|
|
output: Option<PathBuf>,
|
|
|
|
#[arg(short, long, value_delimiter = ',', num_args = 0..)]
|
|
include: Vec<String>,
|
|
|
|
#[arg(short, long, value_delimiter = ',', num_args = 0..)]
|
|
exclude: Vec<String>,
|
|
|
|
#[arg(long, value_enum, default_value_t = Format::Console)]
|
|
format: Format,
|
|
|
|
#[arg(short = 'd', long)]
|
|
append_date: bool,
|
|
|
|
#[arg(short = 'g', long)]
|
|
append_git_hash: bool,
|
|
|
|
#[arg(short = 'l', long)]
|
|
line_numbers: bool,
|
|
|
|
#[arg(short = 'H', long, default_value_t = true)]
|
|
ignore_hidden: bool,
|
|
|
|
#[arg(short = 'R', long, default_value_t = true)]
|
|
respect_gitignore: bool,
|
|
|
|
#[arg(long, default_value_t = false)]
|
|
relative_path: bool,
|
|
}
|
|
|
|
fn main() -> Result<()> {
|
|
let subscriber = FmtSubscriber::builder()
|
|
.with_max_level(LevelFilter::DEBUG)
|
|
.finish();
|
|
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
|
|
|
|
let args = Args::parse();
|
|
|
|
let mut format = args.format;
|
|
if matches!(format, Format::Console)
|
|
&& let Some(output_path) = &args.output
|
|
{
|
|
match output_path.extension().and_then(|s| s.to_str()) {
|
|
Some("md") => format = Format::Markdown,
|
|
Some("txt") => format = Format::Text,
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
let config = codebase_to_prompt::Config {
|
|
directory: args.directory,
|
|
output: args.output,
|
|
include: args.include,
|
|
exclude: args.exclude,
|
|
format,
|
|
append_date: args.append_date,
|
|
append_git_hash: args.append_git_hash,
|
|
line_numbers: args.line_numbers,
|
|
ignore_hidden: args.ignore_hidden,
|
|
respect_gitignore: args.respect_gitignore,
|
|
relative_path: args.relative_path,
|
|
};
|
|
|
|
debug!("Starting codebase to prompt with config: {:?}", config);
|
|
|
|
codebase_to_prompt::run(config)
|
|
}
|