CLI命令重复修复完成(18个命令): - interface模块:ssh-start, web-start, webdav-start, iscsi-start, iscsi-stop, iscsi-status - metadata模块:db-create, db-status, db-backup, db-restore, user-create, user-list, user-show, user-delete, config-show - storage模块:archive-decompress, archive-list, sync-start, sync-status, mount-attach, mount-detach, mount-list - interface/tree模块:tree-create, tree-list, tree-import, tree-delete, tree-folder-create, tree-folder-delete, tree-folder-rename 根本原因: - 所有CLI子模块使用 #[command(flatten)] 导致命令名冲突 - 修复方法:添加 #[command(name = "module-command")] 属性 测试结果: - ✅ 编译成功(150 warnings, 0 errors) - ✅ CLI命令列表正确(所有命令在顶层命名空间) - ✅ SSH服务器启动成功(port 2024) - ✅ SSH版本交换测试通过(SSH-2.0-MarkBaseSSH_1.0) 影响范围: - 13个CLI文件修改 - 18个命令添加唯一命名属性 - CLI结构从 interface/metadata/storage/tools 四层变为扁平化单层
62 lines
2.1 KiB
Rust
62 lines
2.1 KiB
Rust
use clap::Subcommand;
|
|
|
|
#[derive(Subcommand)]
|
|
pub enum SyncCommand {
|
|
#[command(name = "sync-start")]
|
|
Start {
|
|
#[arg(short, long)]
|
|
source: String,
|
|
#[arg(short, long)]
|
|
target: String,
|
|
#[arg(short, long, default_value = "mirror")]
|
|
mode: String,
|
|
},
|
|
#[command(name = "sync-status")]
|
|
Status,
|
|
}
|
|
|
|
pub fn handle_sync_command(cmd: SyncCommand) -> anyhow::Result<()> {
|
|
match cmd {
|
|
SyncCommand::Start { source, target, mode } => {
|
|
use std::path::Path;
|
|
|
|
println!("Syncing {} to {} (mode: {})", source, target, mode);
|
|
|
|
let source_path = Path::new(&source);
|
|
let target_path = Path::new(&target);
|
|
|
|
if !source_path.exists() {
|
|
return Err(anyhow::anyhow!("Source path not found: {}", source));
|
|
}
|
|
|
|
if mode == "mirror" {
|
|
std::fs::create_dir_all(target_path)?;
|
|
|
|
let entries = std::fs::read_dir(source_path)?;
|
|
for entry in entries {
|
|
let entry = entry?;
|
|
let path = entry.path();
|
|
let target_file = target_path.join(entry.file_name());
|
|
|
|
if path.is_file() {
|
|
std::fs::copy(&path, &target_file)?;
|
|
println!(" Copied: {:?}", entry.file_name());
|
|
} else if path.is_dir() {
|
|
std::fs::create_dir_all(&target_file)?;
|
|
println!(" Created directory: {:?}", entry.file_name());
|
|
}
|
|
}
|
|
|
|
println!("✓ Sync completed (mirror mode)");
|
|
} else {
|
|
return Err(anyhow::anyhow!("Unknown sync mode: {}. Use 'mirror'", mode));
|
|
}
|
|
}
|
|
SyncCommand::Status => {
|
|
println!("Checking sync status");
|
|
println!("Note: Sync status tracking requires persistent state management.");
|
|
println!("Current implementation: Simple directory sync without state tracking.");
|
|
}
|
|
}
|
|
Ok(())
|
|
} |