Compare commits

...

2 Commits

Author SHA1 Message Date
d1132d88d2 release v0.1.3: 初步与 cuap 联调通过
Signed-off-by: Jia Chao <jiachao2130@126.com>
2024-09-05 17:57:03 +08:00
2fa030c388 子命令 auto 支持参数指定源和目标路径
Signed-off-by: Jia Chao <jiachao2130@126.com>
2024-09-05 17:56:17 +08:00
4 changed files with 40 additions and 17 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "cvrf2cusa" name = "cvrf2cusa"
version = "0.1.2" version = "0.1.3"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@ -74,4 +74,12 @@ pub fn parse() -> Cli {
#[derive(Clone, Debug, Parser)] #[derive(Clone, Debug, Parser)]
#[command(author, version, about, long_about = None)] #[command(author, version, about, long_about = None)]
pub struct AutoCli; pub struct AutoCli {
/// 指定 CVRF 公告所在的源路径
#[arg(long, short)]
pub source: Option<String>,
/// 转换 CUSA 后存储的目标路径
#[arg(long, short)]
pub target: Option<String>,
}

View File

@ -13,6 +13,11 @@ pub(crate) struct AutoConfig {
} }
impl AutoConfig { impl AutoConfig {
// 新建一个配置结构
pub fn new(source: String, target: String) -> Self {
Self { source, target }
}
// 从文件中读取配置 // 从文件中读取配置
pub fn from<P: AsRef<Path>>(path: P) -> crate::Result<Self> { pub fn from<P: AsRef<Path>>(path: P) -> crate::Result<Self> {
let data = std::fs::read_to_string(path)?; let data = std::fs::read_to_string(path)?;

View File

@ -8,7 +8,7 @@ use regex::Regex;
use tracing::{debug, error, info, trace}; use tracing::{debug, error, info, trace};
use tracing_subscriber::{fmt, EnvFilter}; use tracing_subscriber::{fmt, EnvFilter};
use config::RepairConfig; use config::{AutoConfig, RepairConfig};
use cvrf_xmlparser::{ use cvrf_xmlparser::{
CVRF, CVRF,
// SaInfo 即为 CUSA // SaInfo 即为 CUSA
@ -41,7 +41,7 @@ pub fn cumain() -> Result<()> {
match cli.subcommand { match cli.subcommand {
cli::CliSub::Convert(cli) => covert(&cli), cli::CliSub::Convert(cli) => covert(&cli),
cli::CliSub::Db(cli) => sadb(&cli), cli::CliSub::Db(cli) => sadb(&cli),
cli::CliSub::Auto(_) => auto(), cli::CliSub::Auto(cli) => auto(&cli),
} }
} }
@ -203,20 +203,30 @@ fn walk_dir<P: AsRef<Path>>(path: P, nodir: bool) -> Vec<PathBuf> {
} }
/// 从配置文件中读取 cvrf 和 cusa 数据库的路径,并执行自动转换操作 /// 从配置文件中读取 cvrf 和 cusa 数据库的路径,并执行自动转换操作
pub fn auto() -> Result<()> { pub fn auto(cli: &cli::AutoCli) -> Result<()> {
// 默认配置为,但也可读取执行命令路径下的配置 let auto = if cli.source.is_some() && cli.target.is_some() {
let config = { let auto = AutoConfig::new(
let default = Path::new("/etc/cuvars/cvrf2cusa.json"); cli.source.as_ref().unwrap().to_owned(),
if default.is_file() { cli.target.as_ref().unwrap().to_owned(),
default.to_str().unwrap() );
} else { info!("从参数中读取 AutoConfig: {:#?}", auto);
"cvrf2cusa.json" auto
} } else {
}; // 默认配置为,但也可读取执行命令路径下的配置
info!("Config file is: {}", config); let config = {
let default = Path::new("/etc/cuvars/cvrf2cusa.json");
if default.is_file() {
default.to_str().unwrap()
} else {
"cvrf2cusa.json"
}
};
info!("Config file is: {}", config);
let auto = config::AutoConfig::from(config)?; let auto = config::AutoConfig::from(config)?;
info!("Load AutoConfig: {:?}", auto); info!("Load AutoConfig: {:#?}", auto);
auto
};
let files = walk_dir(auto.source(), true); let files = walk_dir(auto.source(), true);