From 653c68b30f1f8a5cae93e562fc070f268c34d49e Mon Sep 17 00:00:00 2001 From: Jia Chao Date: Mon, 1 Jul 2024 11:51:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=80=E4=BA=9B=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E8=AF=B4=E6=98=8E=EF=BC=8C=E5=8D=B3=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jia Chao --- src/cli.rs | 11 +++++++++++ src/lib.rs | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/cli.rs b/src/cli.rs index f1c30ae..ff4bbd3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -19,6 +19,7 @@ pub enum CliSub { Db(SaDbCli), } +/// ConvertCli 用于将指定的 cvrf 格式 xml 文件转换为 cusa 格式 #[derive(Clone, Debug, Parser)] #[command(author, version, about, long_about = None)] pub struct ConvertCli { @@ -36,6 +37,16 @@ pub struct ConvertCli { pub print: bool, } +impl ConvertCli { + pub fn new(input: String, output: Option, print: bool) -> Self { + ConvertCli { + input, + output, + print, + } + } +} + #[derive(Clone, Debug, Parser)] #[command(author, version, about, long_about = None)] pub struct SaDbCli { diff --git a/src/lib.rs b/src/lib.rs index ac2a3c4..58cfc97 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,6 +27,24 @@ pub fn cumain() -> Result<()> { } } +/// 可使用 convert 函数将 cvrf 格式文件转换并输出至指定的 cusa 文件。 +/// +/// 例: +/// +/// ```no_run +/// use cvrf2cusa::cli::ConvertCli +/// +/// let cli = ConvertCli::new( +/// // input +/// "xxx-cvrf.xml".to_string, +/// // output +/// Some("pkg_version_said.json".to_string), +/// // print to screen +/// false, +/// ); +/// +/// cvrf2cusa::Convert(cli)?; +/// ``` pub fn covert(cli: &cli::ConvertCli) -> Result<()> { // 检查 input,此为必须项 let input = Path::new(&cli.input);