enhance(tools):增加直接导出power.conf的功能。
This commit is contained in:
parent
dee2d96fb3
commit
242a36a61c
@ -1,4 +1,8 @@
|
||||
use std::path::PathBuf;
|
||||
use std::{
|
||||
fs::File,
|
||||
io::{BufWriter, Write},
|
||||
path::PathBuf,
|
||||
};
|
||||
|
||||
use clap::Args;
|
||||
|
||||
@ -6,11 +10,29 @@ use clap::Args;
|
||||
pub struct PowerEqualResultOption {
|
||||
#[arg(help = "Certificate file")]
|
||||
key_file: PathBuf,
|
||||
#[arg(short, long, default_value = "false", help = "Export to power.conf")]
|
||||
export: bool,
|
||||
}
|
||||
|
||||
pub fn calculate_equal_result(options: PowerEqualResultOption) {
|
||||
let cert = cert_lib::load_certificate(options.key_file).expect("load certificate failed");
|
||||
let result =
|
||||
cert_lib::calculate_power_euqal_result(cert).expect("calculate equal result failed");
|
||||
println!("{}", result);
|
||||
if options.export {
|
||||
let mut power_conf_path = PathBuf::new();
|
||||
power_conf_path.push(".");
|
||||
power_conf_path.push("power.conf");
|
||||
let power_conf_file = File::create(power_conf_path).expect("create power.conf failed");
|
||||
let mut writer = BufWriter::new(power_conf_file);
|
||||
writer
|
||||
.write("[Args]\n\n[Result]\n".as_bytes())
|
||||
.expect("write power.conf failed");
|
||||
writer
|
||||
.write(result.as_bytes())
|
||||
.expect("write power.conf failed");
|
||||
writer.flush().expect("write power.conf failed");
|
||||
println!("Export to power.conf completed.");
|
||||
} else {
|
||||
println!("{}", result);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user