commit
This commit is contained in:
2
r/data-transfer/.gitignore
vendored
Normal file
2
r/data-transfer/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
.github
|
||||
target
|
||||
279
r/data-transfer/Cargo.lock
generated
Normal file
279
r/data-transfer/Cargo.lock
generated
Normal file
@@ -0,0 +1,279 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is_terminal_polyfill",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"once_cell_polyfill",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c26d721170e0295f191a69bd9a1f93efcdb0aff38684b61ab5750468972e5f5"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.51"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75835f0c7bf681bfd05abe44e965760fea999a5286c6eb2d59883634fd02011a"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2a0b5487afeab2deb2ff4e03a807ad1a03ac532ff5a2cee5d86884440c7f7671"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
|
||||
|
||||
[[package]]
|
||||
name = "data-transfer"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell_polyfill"
|
||||
version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.103"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.108"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.60.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.53.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.53.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
|
||||
9
r/data-transfer/Cargo.toml
Normal file
9
r/data-transfer/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "data-transfer"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.51", features = ["derive"] }
|
||||
anyhow = "1.0.100"
|
||||
thiserror = "2.0.17"
|
||||
101
r/data-transfer/PROJECT_MILESTONES.md
Normal file
101
r/data-transfer/PROJECT_MILESTONES.md
Normal file
@@ -0,0 +1,101 @@
|
||||
# Project Milestones
|
||||
|
||||
## Dependencies and Crate Management
|
||||
|
||||
This section documents all external crates used in the project. We strictly avoid using multiple crates that provide the same core functionality to maintain a clean and maintainable dependency tree.
|
||||
|
||||
### Core Dependencies
|
||||
|
||||
| Crate | Version | Purpose | Rationale |
|
||||
| ----------- | ------- | ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||||
| `clap` | 4.5.51 | Command-line argument parsing | Industry-standard CLI framework with derive API support. Chosen for its ergonomic API, comprehensive feature set, and excellent documentation. |
|
||||
| `anyhow` | 1.0.100 | Error handling and propagation | Provides simplified error handling for application-level code. Ideal for quickly propagating errors with context up the call stack. |
|
||||
| `thiserror` | 2.0.17 | Custom error type definitions | Complementary to anyhow, used for defining library-level error types with derive macros. Provides clear error messages and seamless integration with Result types. |
|
||||
|
||||
### Dependency Selection Principles
|
||||
|
||||
1. **Single Responsibility**: Each dependency serves a distinct, non-overlapping purpose
|
||||
2. **Maturity**: All selected crates are stable, well-maintained, and widely adopted in the Rust ecosystem
|
||||
3. **Minimal Overhead**: Dependencies are lightweight and do not introduce unnecessary transitive dependencies
|
||||
4. **Compatibility**: All dependencies work seamlessly together without version conflicts
|
||||
|
||||
### Future Considerations
|
||||
|
||||
As new requirements emerge, the following types of crates may be considered:
|
||||
|
||||
- **Serialization**: `serde`, `serde_json` for data format handling
|
||||
- **HTTP Client**: `reqwest` if network operations are needed
|
||||
- **Async Runtime**: `tokio` if asynchronous operations become necessary
|
||||
- **Logging**: `tracing` or `log` if advanced logging capabilities are required
|
||||
- **Configuration**: `config` or `figment` if complex configuration management is needed
|
||||
|
||||
## Version Contents
|
||||
|
||||
### Version 0.1.0 (Current)
|
||||
|
||||
**Release Date**: November 5, 2025
|
||||
|
||||
**Status**: Initial Development
|
||||
|
||||
#### Features
|
||||
|
||||
- ✅ **Project Foundation**
|
||||
- Established modular project structure with clear separation of concerns
|
||||
- Implemented core modules: `cli`, `config`, `error`, `commands`
|
||||
- Set up Rust edition 2024 for latest language features
|
||||
- Configured dependencies using latest stable versions (clap 4.5.51, anyhow 1.0.100, thiserror 2.0.17)
|
||||
|
||||
- ✅ **CLI Framework**
|
||||
- Integrated `clap` for command-line argument parsing using derive API
|
||||
- Implemented verbose flag for detailed logging
|
||||
- Created extensible subcommand structure
|
||||
- Added help and version information display
|
||||
|
||||
- ✅ **Error Handling System**
|
||||
- Defined custom error types using `thiserror`
|
||||
- Implemented `DataTransferError` enum covering common error scenarios
|
||||
- Established `Result<T>` type alias for consistent error handling
|
||||
- Integrated `anyhow` for application-level error propagation
|
||||
|
||||
- ✅ **Configuration Management**
|
||||
- Created `Config` struct for application settings
|
||||
- Implemented configuration loading from CLI arguments
|
||||
- Added default configuration support
|
||||
|
||||
- ✅ **Example Command**
|
||||
- Implemented sample command as a template for future commands
|
||||
- Demonstrated proper error handling patterns
|
||||
- Included unit tests for command functionality
|
||||
|
||||
- ✅ **Testing Infrastructure**
|
||||
- Added unit tests for configuration module
|
||||
- Added unit tests for example command
|
||||
- Established testing patterns for future development
|
||||
|
||||
#### Architecture Highlights
|
||||
|
||||
1. **High Cohesion, Low Coupling**: Each module has a single, well-defined responsibility
|
||||
2. **Explicit Error Handling**: No use of `unwrap()` or `expect()` in production code
|
||||
3. **Ownership Safety**: Careful management of borrowing and lifetimes throughout
|
||||
4. **Documentation**: Comprehensive inline documentation for all public APIs
|
||||
5. **Test Coverage**: Unit tests for critical functionality
|
||||
|
||||
#### Known Limitations
|
||||
|
||||
- Currently contains only a placeholder example command
|
||||
- No persistent configuration file support yet
|
||||
- Limited logging infrastructure (only verbose flag)
|
||||
|
||||
#### Next Steps
|
||||
|
||||
The framework is now ready for feature implementation. Future versions will add:
|
||||
|
||||
1. Actual task automation commands based on user requirements
|
||||
2. Enhanced configuration management (possibly file-based)
|
||||
3. Improved logging with structured output
|
||||
4. Integration tests for end-to-end command validation
|
||||
5. Performance optimizations as needed
|
||||
|
||||
---
|
||||
|
||||
**Note**: This document will be updated as new features are implemented and new dependencies are added. All architectural decisions and dependency additions must be documented here to maintain project clarity and technical governance.
|
||||
163
r/data-transfer/README.md
Normal file
163
r/data-transfer/README.md
Normal file
@@ -0,0 +1,163 @@
|
||||
# Data Transfer
|
||||
|
||||
一个用于自动化处理工作中繁琐任务的命令行工具。
|
||||
|
||||
## 项目简介
|
||||
|
||||
Data Transfer 是一个基于 Rust 开发的命令行程序,旨在帮助快速处理工作中所需执行的重复性、繁琐任务。通过模块化设计和良好的错误处理机制,该工具提供了可靠且易于扩展的任务自动化解决方案。
|
||||
|
||||
## 特性
|
||||
|
||||
- 🚀 **高性能**: 基于 Rust 构建,执行速度快,内存安全
|
||||
- 🔧 **模块化设计**: 清晰的代码结构,易于维护和扩展
|
||||
- ⚡ **命令行友好**: 使用 clap 提供完善的命令行参数解析
|
||||
- 🛡️ **健壮的错误处理**: 使用 anyhow 和 thiserror 进行显式错误管理
|
||||
- 📝 **详细的日志**: 支持 verbose 模式查看详细运行信息
|
||||
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
data-transfer/
|
||||
├── Cargo.toml # 项目配置和依赖管理
|
||||
├── README.md # 项目文档
|
||||
├── PROJECT_MILESTONES.md # 版本里程碑和依赖管理
|
||||
└── src/
|
||||
├── main.rs # 程序入口
|
||||
├── cli.rs # 命令行参数定义
|
||||
├── config.rs # 配置管理
|
||||
├── error.rs # 错误类型定义
|
||||
└── commands/ # 命令实现模块
|
||||
├── mod.rs # 命令模块导出
|
||||
└── example.rs # 示例命令实现
|
||||
```
|
||||
|
||||
## 技术架构
|
||||
|
||||
### 核心模块
|
||||
|
||||
- **cli**: 使用 clap 的派生 API 定义命令行接口
|
||||
- **config**: 管理应用程序配置和参数
|
||||
- **error**: 自定义错误类型,提供清晰的错误上下文
|
||||
- **commands**: 所有子命令的实现逻辑
|
||||
|
||||
### 设计原则
|
||||
|
||||
项目严格遵循以下 Rust 最佳实践:
|
||||
|
||||
1. **高内聚、低耦合**: 功能模块独立,接口清晰
|
||||
2. **显式错误处理**: 使用 `Result<T, E>` 处理可恢复错误
|
||||
3. **所有权管理**: 合理使用借用和生命周期
|
||||
4. **并发安全**: 使用标准库同步原语保证线程安全
|
||||
5. **测试驱动**: 为核心逻辑提供单元测试
|
||||
|
||||
## 安装
|
||||
|
||||
### 前置要求
|
||||
|
||||
- Rust 1.70 或更高版本
|
||||
- Cargo
|
||||
|
||||
### 从源码构建
|
||||
|
||||
```bash
|
||||
# 克隆仓库
|
||||
git clone <repository-url>
|
||||
cd data-transfer
|
||||
|
||||
# 构建项目
|
||||
cargo build --release
|
||||
|
||||
# 可执行文件位于 target/release/data-transfer
|
||||
```
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 基本命令
|
||||
|
||||
```bash
|
||||
# 查看帮助信息
|
||||
./data-transfer --help
|
||||
|
||||
# 启用详细日志模式
|
||||
./data-transfer --verbose
|
||||
|
||||
# 运行示例命令
|
||||
./data-transfer example --input "test data"
|
||||
```
|
||||
|
||||
### 命令参数
|
||||
|
||||
- `-v, --verbose`: 启用详细日志输出
|
||||
- `-h, --help`: 显示帮助信息
|
||||
- `-V, --version`: 显示版本信息
|
||||
|
||||
## 开发指南
|
||||
|
||||
### 添加新命令
|
||||
|
||||
1. 在 `src/commands/` 目录下创建新模块文件
|
||||
2. 在 `src/cli.rs` 中的 `Commands` 枚举添加新命令变体
|
||||
3. 在 `src/commands/mod.rs` 中导出新命令
|
||||
4. 在 `src/main.rs` 中处理新命令的执行逻辑
|
||||
5. 为新命令编写单元测试
|
||||
|
||||
### 运行测试
|
||||
|
||||
```bash
|
||||
# 运行所有测试
|
||||
cargo test
|
||||
|
||||
# 运行特定测试
|
||||
cargo test test_name
|
||||
|
||||
# 显示测试输出
|
||||
cargo test -- --nocapture
|
||||
```
|
||||
|
||||
### 代码规范
|
||||
|
||||
- 使用 `snake_case` 命名函数、变量和模块
|
||||
- 使用 `UpperCamelCase` 命名类型(struct、enum、trait)
|
||||
- 所有公共 API 必须包含文档注释(`///`)
|
||||
- 禁止在生产代码中使用 `unwrap()` 或 `expect()`
|
||||
- 优先使用不可变引用 `&`,仅在必要时使用 `&mut`
|
||||
|
||||
### 错误处理规范
|
||||
|
||||
- 可恢复错误使用 `Result<T, E>` 类型
|
||||
- 使用 `?` 操作符传播错误
|
||||
- 自定义错误类型继承 `thiserror::Error`
|
||||
- 错误消息必须包含足够的上下文信息
|
||||
|
||||
## 依赖说明
|
||||
|
||||
核心依赖库:
|
||||
|
||||
- **clap**: 命令行参数解析库,提供强大的 CLI 构建能力
|
||||
- **anyhow**: 简化错误处理和传播
|
||||
- **thiserror**: 自定义错误类型的派生宏
|
||||
|
||||
详细依赖信息请参考 `PROJECT_MILESTONES.md`。
|
||||
|
||||
## 许可证
|
||||
|
||||
[待补充]
|
||||
|
||||
## 贡献指南
|
||||
|
||||
欢迎贡献代码和提交问题报告!请确保:
|
||||
|
||||
1. 代码符合项目规范
|
||||
2. 添加必要的测试
|
||||
3. 更新相关文档
|
||||
4. 提交前运行 `cargo fmt` 和 `cargo clippy`
|
||||
|
||||
## 路线图
|
||||
|
||||
当前版本为 0.1.0,处于初始开发阶段。后续功能将根据实际需求逐步添加。
|
||||
|
||||
详细的版本规划和功能列表请查看 `PROJECT_MILESTONES.md`。
|
||||
|
||||
## 联系方式
|
||||
|
||||
[待补充]
|
||||
31
r/data-transfer/src/cli.rs
Normal file
31
r/data-transfer/src/cli.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
/// CLI argument parsing module
|
||||
/// Defines command-line interface structure using clap's derive API
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(
|
||||
name = "data-transfer",
|
||||
version,
|
||||
about = "A CLI tool for automating tedious work tasks",
|
||||
long_about = None
|
||||
)]
|
||||
pub struct Cli {
|
||||
/// Enable verbose logging
|
||||
#[arg(short, long)]
|
||||
pub verbose: bool,
|
||||
|
||||
/// Subcommands
|
||||
#[command(subcommand)]
|
||||
pub command: Option<Commands>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, Debug)]
|
||||
pub enum Commands {
|
||||
/// Example command placeholder
|
||||
/// This will be replaced with actual commands as requirements are added
|
||||
Example {
|
||||
/// Example parameter
|
||||
#[arg(short, long)]
|
||||
input: Option<String>,
|
||||
},
|
||||
}
|
||||
33
r/data-transfer/src/commands/example.rs
Normal file
33
r/data-transfer/src/commands/example.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
/// Example command implementation
|
||||
/// This serves as a template for future command implementations
|
||||
use crate::error::{DataTransferError, Result};
|
||||
|
||||
/// Run the example command
|
||||
pub fn run(input: Option<String>) -> Result<()> {
|
||||
match input {
|
||||
Some(value) => {
|
||||
println!("Processing input: {}", value);
|
||||
Ok(())
|
||||
}
|
||||
None => Err(DataTransferError::CommandError(
|
||||
"No input provided".to_string(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_run_with_input() {
|
||||
let result = run(Some("test".to_string()));
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_run_without_input() {
|
||||
let result = run(None);
|
||||
assert!(result.is_err());
|
||||
}
|
||||
}
|
||||
10
r/data-transfer/src/commands/mod.rs
Normal file
10
r/data-transfer/src/commands/mod.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
/// Commands module
|
||||
/// Contains implementations for all CLI subcommands
|
||||
use crate::error::Result;
|
||||
|
||||
pub mod example;
|
||||
|
||||
/// Execute the example command
|
||||
pub fn execute_example(input: Option<String>) -> Result<()> {
|
||||
example::run(input)
|
||||
}
|
||||
48
r/data-transfer/src/config.rs
Normal file
48
r/data-transfer/src/config.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
/// Configuration module
|
||||
/// Handles application configuration loading and management
|
||||
use crate::error::Result;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Config {
|
||||
pub verbose: bool,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Create a new configuration with default values
|
||||
pub fn new() -> Self {
|
||||
Self { verbose: false }
|
||||
}
|
||||
|
||||
/// Create configuration from CLI arguments
|
||||
pub fn from_cli(verbose: bool) -> Self {
|
||||
Self { verbose }
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
/// Load configuration
|
||||
pub fn load(verbose: bool) -> Result<Config> {
|
||||
Ok(Config::from_cli(verbose))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_default_config() {
|
||||
let config = Config::default();
|
||||
assert!(!config.verbose);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_cli() {
|
||||
let config = Config::from_cli(true);
|
||||
assert!(config.verbose);
|
||||
}
|
||||
}
|
||||
20
r/data-transfer/src/error.rs
Normal file
20
r/data-transfer/src/error.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
/// Custom error types for the application
|
||||
/// Uses thiserror for ergonomic error definitions
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum DataTransferError {
|
||||
#[error("Configuration error: {0}")]
|
||||
ConfigError(String),
|
||||
|
||||
#[error("Command execution failed: {0}")]
|
||||
CommandError(String),
|
||||
|
||||
#[error("I/O error: {0}")]
|
||||
IoError(#[from] std::io::Error),
|
||||
|
||||
#[error("Unknown error occurred")]
|
||||
Unknown,
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, DataTransferError>;
|
||||
31
r/data-transfer/src/main.rs
Normal file
31
r/data-transfer/src/main.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
mod cli;
|
||||
mod commands;
|
||||
mod config;
|
||||
mod error;
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use cli::{Cli, Commands};
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let cli = Cli::parse();
|
||||
|
||||
// Load configuration based on CLI arguments
|
||||
let config = config::load(cli.verbose)?;
|
||||
|
||||
if config.verbose {
|
||||
println!("Running in verbose mode");
|
||||
}
|
||||
|
||||
// Execute command based on subcommand
|
||||
match &cli.command {
|
||||
Some(Commands::Example { input }) => {
|
||||
commands::execute_example(input.clone())?;
|
||||
}
|
||||
None => {
|
||||
println!("No command specified. Use --help for usage information.");
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user