file_cat

Crates.iofile_cat
lib.rsfile_cat
version0.3.0
sourcesrc
created_at2024-03-07 09:17:34.810866
updated_at2024-03-08 09:39:55.59222
descriptionA directory concatinator
homepagehttps://github.com/LordOfPolls/FileCat
repositoryhttps://github.com/LordOfPolls/FileCat
max_upload_size
id1165766
size22,353
LordOfPolls (LordOfPolls)

documentation

README

FileCat

Crates.io Version

FileCat is a command-line tool written in Rust that allows you to concatenate the contents of files with a specified extension. This was originally created to concatenate project directories for LLM context and training data.

Usage

To use FileCat, run the compiled binary with the desired file extension as an argument. You can also specify the path to search for files (default is the current directory) and exclude specific directories from the search.

Usage: file_cat [OPTIONS] <FILE_EXTENSION>

Arguments:
  <FILE_EXTENSION>  Files with this extension will be collected

Options:
  -p, --path <PATH>            The path to search for files [default: .]
  -e, --exclude <EXCLUDE>      Directories to exclude from the search, comma separated [default: ]
  -r, --recursive              Search recursively
  -m, --max-depth <MAX_DEPTH>  Max Recursion Depth [default: 100]
  -s, --strip-newlines         Strip newlines from the output
  -c, --no-comments            Hide filename comments
  -d  --default-only           Only use the default handler, instead of the handler for the specified extension
  -h, --help                   Print help
  -V, --version                Print version

Examples:

file_cat rs -r
file_cat txt -p /path/to/directory
file_cat js -p /path/to/directory -e node_modules,dist

Output

FileCat will display the file paths, names, and contents in the console. It automatically detects the appropriate comment syntax based on the file extension and includes it in the output.

Example output:

// File: src/main.rs
use std::env;
use std::fs::{self, File};
use std::io::{self, BufRead, BufReader, Write};
use std::path::Path;

fn collect_files_with_extension(
extension: &str,
recursive: bool,
path: &Path,
excluded_dirs: &[String],
) -> io::Result<Vec<fs::DirEntry>> {
// ...
}

// ...

To store the output as a file, normal syntax applies for redirecting the output to a file:

file_cat rs -r > output.txt

Handlers

FileCat supports extension-specific handlers for processing files. Currently, the following handlers are available:

csv_handler: Concatenates CSV files by aligning the headers and columns.
default: The default handler, which concatenates files as-is with optional filename comments.

By default, FileCat will use the appropriate handler based on the file extension. If you want to force using the default handler regardless of the extension, you can use the --default-only flag.

Installation

To use FileCat, you need to have Rust installed on your system. If you don't have Rust installed, you can download and install it from the official Rust website: https://www.rust-lang.org

Once Rust is installed, you can clone this repository and build the project using Cargo, the Rust package manager:

From Crates.io

cargo install file_cat

From Source

git clone https://github.com/your-username/file_cat.git
cd file_cat
cargo install --path .    

License

This project is licensed under the MIT License.

Commit count: 0

cargo fmt