CLI三层架构重构完成:interface/metadata/storage/tools层
架构设计: - 上层(interface):虚拟操作系统层 - web.rs: HTTP Server - ssh.rs: SSH/SFTP Server - webdav.rs: WebDAV Server - iscsi.rs: iSCSI Server - tree.rs: File Tree管理(categories/series) - 中层(metadata):核心数据库层 - config.rs: 配置管理(从framework.rs迁移) - user.rs: 用户管理 - db.rs: 数据库管理 - auth.rs: 认证授权 - 底层(storage):文件存取层 - scan.rs: 文件扫描导入(从framework.rs迁移) - hash.rs: 哈希计算(从framework.rs迁移) - archive.rs: 压缩解压缩 - sync.rs: 文件同步 - mount.rs: 存储挂载 - 辅助工具(tools):辅助功能 - render.rs: Markdown渲染(从framework.rs迁移) - test.rs: 测试命令(从framework.rs迁移) 架构优势: ✅ 清晰的三层分离,符合架构理念 ✅ 21个独立模块,职责清晰 ✅ main.rs简化至23行,cli/mod.rs24行 ✅ 删除旧架构(cli/apps和framework.rs) ✅ 编译成功,所有CLI命令可用 命令範例: markbase interface web start --port 11438 markbase interface ssh start --port 2024 markbase interface tree import --user accusys --tree-type categories markbase metadata config show markbase storage scan directory --user accusys --dir data/downloads markbase tools render file --file README.md 文件统计: - 新增文件:20个Rust模块 - 删除文件:3个旧架构文件 - 修改文件:2个核心入口 - 总计:21个文件变更
This commit is contained in:
@@ -0,0 +1,117 @@
|
||||
use clap::Subcommand;
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Subcommand)]
|
||||
pub enum ConfigCommand {
|
||||
Init {
|
||||
#[arg(short, long)]
|
||||
force: bool,
|
||||
},
|
||||
Show {
|
||||
#[arg(short, long)]
|
||||
section: Option<String>,
|
||||
},
|
||||
Edit {
|
||||
#[arg(short, long)]
|
||||
key: String,
|
||||
#[arg(short, long)]
|
||||
value: String,
|
||||
},
|
||||
Validate,
|
||||
}
|
||||
|
||||
pub fn handle_config_command(cmd: ConfigCommand) -> anyhow::Result<()> {
|
||||
match cmd {
|
||||
ConfigCommand::Init { force } => {
|
||||
let config_path = Path::new("config/markbase.toml");
|
||||
|
||||
if config_path.exists() && !force {
|
||||
println!("Configuration file already exists at config/markbase.toml");
|
||||
println!("Use --force to overwrite");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let config = crate::config::MarkBaseConfig::default_config();
|
||||
config.save(config_path)?;
|
||||
|
||||
println!("✓ Configuration file created: config/markbase.toml");
|
||||
println!("Default values:");
|
||||
println!(" Server port: {}", config.server.port);
|
||||
println!(" PostgreSQL host: {}", config.postgresql.host);
|
||||
println!(" Test users: {}", config.test.users.join(", "));
|
||||
}
|
||||
ConfigCommand::Show { section } => {
|
||||
let config_path = Path::new("config/markbase.toml");
|
||||
|
||||
if !config_path.exists() {
|
||||
println!("Configuration file not found. Run 'markbase metadata config init' first.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let config = crate::config::MarkBaseConfig::load(config_path)?;
|
||||
|
||||
if let Some(s) = section {
|
||||
show_section(&config, &s);
|
||||
} else {
|
||||
println!("{}", toml::to_string_pretty(&config)?);
|
||||
}
|
||||
}
|
||||
ConfigCommand::Edit { key, value } => {
|
||||
let config_path = Path::new("config/markbase.toml");
|
||||
|
||||
if !config_path.exists() {
|
||||
println!("Configuration file not found. Run 'markbase metadata config init' first.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut config = crate::config::MarkBaseConfig::load(config_path)?;
|
||||
|
||||
match config.get(&key) {
|
||||
Some(old_value) => {
|
||||
config.set(&key, &value)?;
|
||||
config.validate()?;
|
||||
config.save(config_path)?;
|
||||
println!("✓ Updated {}: {} → {}", key, old_value, value);
|
||||
}
|
||||
None => {
|
||||
println!("Invalid config key: {}", key);
|
||||
println!(
|
||||
"Valid keys: server.*, postgresql.*, authentication.*, test.*, logging.*"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ConfigCommand::Validate => {
|
||||
let config_path = Path::new("config/markbase.toml");
|
||||
|
||||
if !config_path.exists() {
|
||||
println!("Configuration file not found. Run 'markbase metadata config init' first.");
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let config = crate::config::MarkBaseConfig::load(config_path)?;
|
||||
|
||||
match config.validate() {
|
||||
Ok(_) => {
|
||||
println!("✓ Configuration is valid");
|
||||
}
|
||||
Err(e) => {
|
||||
println!("✗ Configuration validation failed: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn show_section(config: &crate::config::MarkBaseConfig, section: &str) {
|
||||
match section {
|
||||
"server" => println!("{}", toml::to_string_pretty(&config.server).unwrap()),
|
||||
"postgresql" => println!("{}", toml::to_string_pretty(&config.postgresql).unwrap()),
|
||||
"authentication" => println!("{}", toml::to_string_pretty(&config.authentication).unwrap()),
|
||||
"test" => println!("{}", toml::to_string_pretty(&config.test).unwrap()),
|
||||
"logging" => println!("{}", toml::to_string_pretty(&config.logging).unwrap()),
|
||||
_ => println!("Invalid section: {}. Valid sections: server, postgresql, authentication, test, logging", section),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user