From 1a57382fc77b50f81037cea3e81cc3fa951d800e Mon Sep 17 00:00:00 2001 From: Jia Chao Date: Thu, 27 Jun 2024 11:03:58 +0800 Subject: [PATCH] =?UTF-8?q?=E2=80=9C=E5=AE=8C=E6=88=90=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A1=8C=E6=A8=A1=E5=BC=8F=E5=88=9D=E5=A7=8B=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jia Chao --- src/cli.rs | 23 +++++++++++++++++++++++ src/lib.rs | 18 ++++++++++++++++++ src/main.rs | 5 +++-- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/cli.rs create mode 100644 src/lib.rs diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..9f24de5 --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,23 @@ +use clap::Parser; + +// 构建命令行工具的结构体 +#[derive(Clone, Debug, Parser)] +#[command(author, version, about, long_about = None)] +pub struct Cli { + /// 输入的文件,应为 cvrf 格式的 xml + #[arg(short, long)] + pub input: String, + + /// 可选项,将 cvrf 转换为 cusa 后输出到对应的文件中,格式为 json + #[arg(short, long)] + pub output: Option, + + /// 是否在终端打印转换后的 cusa 内容,若不指定输出文件,则输出至终端, + /// 在指定 output 后同时使用该选项,亦可同时输出至文件和终端 + #[arg(short, long, default_value_t = false)] + pub print: bool, +} + +pub fn parse() -> Cli { + Cli::parse() +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..6189d8e --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,18 @@ +use cvrf_xmlparser::{ + CVRF, + SaInfo as CUSA, +}; + +pub mod cli; + +/// 定义 crate::Error +/// 大部分函数返回的错误 +pub type Error = Box; + +/// 定义 crate::Result +pub type Result = std::result::Result; + +pub fn cumain() -> Result<()> { + let cli = cli::parse(); + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..9bc4ebd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ -fn main() { - println!("Hello, world!"); +use cvrf2cusa::{cumain, Result}; +fn main() -> Result<()> { + cumain() }