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() }