diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..27ec27c --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ +DO WHAT YOU WANT PUBLIC LICENSE +Version 2, December 2004 + +Copyright (C) 2024 + +Everyone is permitted to copy and distribute verbatim or modified +copies of this license document, and changing it is allowed as long +as the name is changed. + +DO WHAT YOU WANT PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + +0. You just DO WHAT YOU WANT TO. diff --git a/README.md b/README.md new file mode 100644 index 0000000..356fd20 --- /dev/null +++ b/README.md @@ -0,0 +1,123 @@ +# Codebase to Prompt + +`codebase-to-prompt` is a Rust-based CLI tool designed to bundle files from a directory into a single output file. It supports filtering files by extensions, respecting `.gitignore` rules, and formatting the output in Markdown, plain text, or console-friendly formats. + +## Features + +- **File Filtering**: Include or exclude files based on their extensions. +- **Output Formats**: Supports Markdown, plain text, and console-friendly formats. +- **Git Integration**: Optionally append the current Git hash to the output file name. +- **Date Integration**: Optionally append the current date to the output file name. +- **Line Numbers**: Include line numbers in the output. +- **Hidden Files**: Optionally ignore hidden files. +- **`.gitignore` Respect**: Optionally respect `.gitignore` rules. + +## Installation + +1. Ensure you have [Rust](https://www.rust-lang.org/) installed. +2. Clone this repository: + ```bash + git clone + cd codebase-to-prompt + ``` +3. Build the project: + ```bash + cargo build --release + ``` +4. The binary will be available at `target/release/codebase-to-prompt`. + +## Usage + +Run the tool with the following options: + +```bash +codebase-to-prompt [OPTIONS] [DIRECTORY] +``` + +### Options + +- `-o, --output `: Specify the output file. Defaults to stdout if not provided. +- `-i, --include `: Comma-separated list of file extensions to include. +- `-e, --exclude `: Comma-separated list of file extensions to exclude. +- `--format `: Output format (`console`, `markdown`, `text`). Defaults to `console`. +- `-d, --append-date`: Append the current date to the output file name. +- `-g, --append-git-hash`: Append the current Git hash to the output file name. +- `-l, --line-numbers`: Include line numbers in the output. +- `-H, --ignore-hidden`: Ignore hidden files. +- `-R, --respect-gitignore`: Respect `.gitignore` rules. Enabled by default. + +### Examples + +1. Bundle all `.rs` files in the current directory into `output.md` in Markdown format: + + ```bash + codebase-to-prompt -o output.md -i rs --format markdown + ``` + +2. Bundle all files except `.log` files, appending the current date and Git hash to the output file name: + + ```bash + codebase-to-prompt -o output.txt -e log -d -g + ``` + +3. Output all files to the console, including line numbers: + ```bash + codebase-to-prompt -l + ``` + +## Development + +### Prerequisites + +- [Rust](https://www.rust-lang.org/) (latest stable version recommended) + +### Building + +To build the project: + +```bash +cargo build --release +``` + +### Running Tests + +To run tests: + +```bash +cargo test +``` + +### Code Structure + +- `src/lib.rs`: Core logic for file processing and bundling. +- `src/main.rs`: CLI entry point. + +### Adding Dependencies + +To add a new dependency, update `Cargo.toml` and run: + +```bash +cargo build +``` + +### Linting and Formatting + +To lint the code: + +```bash +cargo clippy +``` + +To format the code: + +```bash +cargo fmt +``` + +## License + +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. + +## Contributing + +Contributions are welcome! Feel free to open issues or submit pull requests. diff --git a/src/lib.rs b/src/lib.rs index 4bea666..c22a2cf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -195,7 +195,7 @@ fn process_file_entry(entry: &DirEntry, writer: &mut dyn Write, config: &Config) let extension = path.extension().and_then(|s| s.to_str()).unwrap_or(""); let apply_include_filter = - !config.include.is_empty() && !(config.include.len() == 1 && config.include[0].is_empty()); + !(config.include.is_empty() || config.include.len() == 1 && config.include[0].is_empty()); if apply_include_filter && !config.include.contains(&extension.to_string()) { return Ok(());