Add Display trait implementation for Config struct

This commit is contained in:
shenjack 2024-01-21 17:37:29 +08:00
parent f22dfa12f7
commit 2135d66767
Signed by: shenjack
GPG Key ID: 7B1134A979775551
3 changed files with 23 additions and 9 deletions

View File

@ -1,3 +1,5 @@
use std::fmt::Display;
pub const HELP_MESSAGE: &str = r#"call [options] [--] [arguments] pub const HELP_MESSAGE: &str = r#"call [options] [--] [arguments]
Options: Options:
--hide Hide console window (default) --hide Hide console window (default)
@ -10,6 +12,7 @@ Options:
--help Print this help message --help Print this help message
"#; "#;
#[derive(Clone)]
pub struct Config { pub struct Config {
pub show_console: bool, pub show_console: bool,
pub chdir: Option<String>, pub chdir: Option<String>,
@ -19,6 +22,21 @@ pub struct Config {
pub bin_arg: String, 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 { impl Config {
pub fn from_cli() -> Option<Config> { pub fn from_cli() -> Option<Config> {
let mut show_console = false; let mut show_console = false;

View File

@ -17,6 +17,9 @@ fn main() {
return; return;
} }
let config = config.unwrap(); let config = config.unwrap();
// 输出相关信息
println!("call {}", VERSION);
println!("config: {}", config);
if config.show_console { if config.show_console {
win::show_window(); win::show_window();
} else { } else {

View File

@ -1,10 +1,3 @@
pub fn hide_window() {}
pub fn show_window() {}
pub fn hide_window () {
}
pub fn show_window () {
}