| Crates.io | gather-all-code-from-crates |
| lib.rs | gather-all-code-from-crates |
| version | 0.1.0 |
| created_at | 2024-12-11 06:55:10.599197+00 |
| updated_at | 2024-12-11 06:55:10.599197+00 |
| description | a Rust crate designed to extract, filter, and reconstruct code elements from Rust projects. It provides a flexible and configurable toolset for analyzing and processing Abstract Syntax Trees (ASTs) of Rust code, with options to include or exclude specific elements based on user-defined criteria. |
| homepage | |
| repository | https://github.com/klebs6/klebs-general |
| max_upload_size | |
| id | 1479643 |
| size | 139,337 |
gather-all-code-from-crates is a Rust crate designed to extract, filter, and reconstruct code elements from Rust projects. It provides a flexible and configurable toolset for analyzing and processing Abstract Syntax Trees (ASTs) of Rust code, with options to include or exclude specific elements based on user-defined criteria.
Version 0.1.0 is a quick sketch.
It needs a refactor, a thorough testing, and is bound to have some bugs.
That said, the basic functionality is currently decent and mostly working.
Pull requests are most welcome.
Add this crate to your Cargo.toml:
[dependencies]
gather-all-code-from-crates = "0.1.0"
Run the tool using the CLI to gather and filter code from crates:
cargo run -- --crate path/to/crate --include-tests --omit-private
use gather_all_code_from_crates::{load_global_config, GlobalConfig};
let config = load_global_config()?;
use gather_all_code_from_crates::{process_crate_directory, AstFilterCriteria};
use std::path::PathBuf;
let criteria = AstFilterCriteria::default();
let crate_path = PathBuf::from("path/to/crate");
let result = process_crate_directory(&crate_path, &criteria)?;
println!("Filtered Code:\n{}", result);
use gather_all_code_from_crates::build_effective_config_from_cli;
let effective_config = build_effective_config_from_cli()?;
println!("Effective Config: {:?}", effective_config);
--crate <path>: Specify one or more crate directories to scan. Defaults to the current directory if not provided.--include-tests: Include test code in the output.--omit-private: Exclude private functions and items.--omit-bodies: Exclude function bodies in the output.--single-test <name>: Include only a single test block by name.--single-function <name>: Include only a single function body by name.--exclude-file <path>: Exclude specific files by relative path.--exclude-main-file: Exclude main files such as src/lib.rs or src/main.rs.--remove-doc-comments: Remove documentation comments from the output.Global configuration is loaded from a JSON file located at ~/.gather-all-code-from-crates. Example:
{
"project_overrides": {
"project_a": {
"include_tests": true,
"omit_private": false
}
},
"default_include_tests": true,
"default_omit_bodies": false,
"extra_flags": 0
}
The crate defines custom error types (AppError) to handle different scenarios, including:
Contributions are welcome! Please submit a pull request or open an issue to discuss any changes or features.
This project is licensed under the MIT License. See the LICENSE file for details.