“完成命令行模式初始设置”
Signed-off-by: Jia Chao <jiac13@chinaunicom.cn>
This commit is contained in:
parent
e340539e1a
commit
1a57382fc7
23
src/cli.rs
Normal file
23
src/cli.rs
Normal file
|
@ -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<String>,
|
||||||
|
|
||||||
|
/// 是否在终端打印转换后的 cusa 内容,若不指定输出文件,则输出至终端,
|
||||||
|
/// 在指定 output 后同时使用该选项,亦可同时输出至文件和终端
|
||||||
|
#[arg(short, long, default_value_t = false)]
|
||||||
|
pub print: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse() -> Cli {
|
||||||
|
Cli::parse()
|
||||||
|
}
|
18
src/lib.rs
Normal file
18
src/lib.rs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
use cvrf_xmlparser::{
|
||||||
|
CVRF,
|
||||||
|
SaInfo as CUSA,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub mod cli;
|
||||||
|
|
||||||
|
/// 定义 crate::Error
|
||||||
|
/// 大部分函数返回的错误
|
||||||
|
pub type Error = Box<dyn std::error::Error + Send + Sync>;
|
||||||
|
|
||||||
|
/// 定义 crate::Result
|
||||||
|
pub type Result<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
|
pub fn cumain() -> Result<()> {
|
||||||
|
let cli = cli::parse();
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
fn main() {
|
use cvrf2cusa::{cumain, Result};
|
||||||
println!("Hello, world!");
|
fn main() -> Result<()> {
|
||||||
|
cumain()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user