Add Display trait implementation for Config struct
This commit is contained in:
parent
f22dfa12f7
commit
2135d66767
@ -1,3 +1,5 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
pub const HELP_MESSAGE: &str = r#"call [options] [--] [arguments]
|
||||
Options:
|
||||
--hide Hide console window (default)
|
||||
@ -10,6 +12,7 @@ Options:
|
||||
--help Print this help message
|
||||
"#;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Config {
|
||||
pub show_console: bool,
|
||||
pub chdir: Option<String>,
|
||||
@ -19,6 +22,21 @@ pub struct Config {
|
||||
pub bin_arg: String,
|
||||
}
|
||||
|
||||
impl Display for Config {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut s = String::new();
|
||||
s.push_str("Config {\n");
|
||||
s.push_str(&format!(" show_console: {}\n", self.show_console));
|
||||
s.push_str(&format!(" chdir: {:?}\n", self.chdir));
|
||||
s.push_str(&format!(" bin: {:?}\n", self.bin));
|
||||
s.push_str(&format!(" dir: {:?}\n", self.dir));
|
||||
s.push_str(&format!(" config: {:?}\n", self.config));
|
||||
s.push_str(&format!(" bin_arg: {:?}\n", self.bin_arg));
|
||||
s.push_str("}");
|
||||
write!(f, "{}", s)
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn from_cli() -> Option<Config> {
|
||||
let mut show_console = false;
|
||||
|
@ -17,6 +17,9 @@ fn main() {
|
||||
return;
|
||||
}
|
||||
let config = config.unwrap();
|
||||
// 输出相关信息
|
||||
println!("call {}", VERSION);
|
||||
println!("config: {}", config);
|
||||
if config.show_console {
|
||||
win::show_window();
|
||||
} else {
|
||||
|
11
src/win.rs
11
src/win.rs
@ -1,10 +1,3 @@
|
||||
pub fn hide_window() {}
|
||||
|
||||
|
||||
pub fn hide_window () {
|
||||
|
||||
}
|
||||
|
||||
pub fn show_window () {
|
||||
|
||||
}
|
||||
|
||||
pub fn show_window() {}
|
||||
|
Loading…
Reference in New Issue
Block a user