code_packager is both an executable binary that can be run, and a library that can be used in Rust programs.
Installing the command-line executable
Assuming you have Rust/Cargo installed , run this command in a terminal:
cargo install code_packager
It will make the code_packager command available in your PATH if you've allowed the PATH to be modified when installing Rust . cargo uninstall code_packager uninstalls.
Adding code_packager library as a dependency
Run this command in a terminal, in your project's directory:
cargo add code_packager
To add it manually, edit your project's Cargo.toml file and add to the [dependencies] section:
code_packager = "0.1.0"
The code_packager library will be automatically available globally.
Read the code_packager library documentation .
Back to the crate overview .
Readme
Code Packager
一个用于将源代码文件打包到单个文本文件中的 Rust 工具。
功能特性
递归打包目录中的源代码文件
支持 glob 模式忽略文件/目录
支持额外包含文件
输出格式化的代码文件
安装
从 crates.io 安装
cargo install code_packager
从源码安装
git clone https://github.com/ymc-github/code_packager
cd code_packager
cargo install -- path .
使用方法
作为命令行工具
# 基本使用
code_packager
# 指定输入输出
code_packager -i ./src -o output.txt
# 添加额外文件
code_packager -a "Cargo.toml" -a "README.md"
# 忽略文件模式
code_packager --ignore "target/*" --ignore "*.tmp"
作为库使用
添加依赖到 Cargo.toml :
[ dependencies ]
code_packager = " 0.1"
在代码中使用:
use code_packager:: { package_code, PackagerConfig} ;
fn main ( ) -> Result < ( ) , Box < dyn std:: error:: Error> > {
let config = PackagerConfig {
input_dir: " src" . to_string ( ) ,
output_file: " code.txt" . to_string ( ) ,
extra_files: vec! [ " Cargo.toml" . to_string ( ) , " README.md" . to_string ( ) ] ,
ignore_patterns: vec! [ " target/*" . to_string ( ) , " *.tmp" . to_string ( ) ] ,
} ;
package_code ( & config) ? ;
Ok ( ( ) )
}
作为 Cargo 子命令
安装后,可以直接使用:
cargo code_packager
许可证
MIT OR Apache-2.0