From 87fa949309578bdc245ad0fd21c8601661fb5531 Mon Sep 17 00:00:00 2001 From: 0xf8 <0xf8.dev@proton.me> Date: Mon, 29 May 2023 23:41:21 -0400 Subject: [PATCH] Run definition over creation --- src/config.rs | 1 + src/input.rs | 14 +++++--------- src/main.rs | 11 +++++------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/config.rs b/src/config.rs index 8d32093..cf3b7c0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,6 +24,7 @@ impl std::fmt::Display for Host { } impl Host { + // todo: validate ssh config pub fn edit(&mut self) -> Result { let mut data = toml::to_string_pretty(self)?; diff --git a/src/input.rs b/src/input.rs index 6eab19a..7b2bf8e 100644 --- a/src/input.rs +++ b/src/input.rs @@ -21,19 +21,15 @@ pub fn get_host(config: &mut ConfigManager) -> Result { .item("New host definition...") .default(0); - let c = loop { + Ok({ let c = select.interact()?; - + if c == hosts.len() { - let _ = config.new_host()?; - let _hosts = config.configs.to_owned(); - hosts = _hosts.into_iter().collect(); + config.new_host()? } else { - break c + hosts.get(c).unwrap().to_owned() } - }; - - Ok(hosts.get(c).unwrap().to_owned()) + }) } pub fn get_platform() -> Result { diff --git a/src/main.rs b/src/main.rs index 24146ea..df9abcc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ pub mod platform; fn main() -> Result<()> { let mut search_path: Option = None; let mut config_root: Option = None; - let mut dry_run: bool = false; +// let mut dry_run: bool = false; { let mut parser = argparse::ArgumentParser::new(); @@ -22,7 +22,8 @@ fn main() -> Result<()> { parser.add_option(&["-V", "--version"], argparse::Print(env!("CARGO_PKG_VERSION").to_string()), "Show version"); parser.refer(&mut search_path).add_option(&["-s", "--search"], argparse::StoreOption, "Search path for keys"); parser.refer(&mut config_root).add_option(&["-c", "--config"], argparse::StoreOption, "Path to keyman's config dir"); - parser.refer(&mut dry_run).add_option(&["-d", "--dry-run", "--dryrun"], argparse::StoreTrue, "Do a dry run"); + // todo: actual dryrun + // parser.refer(&mut dry_run).add_option(&["-d", "--dry-run", "--dryrun"], argparse::StoreTrue, "Do a dry run"); parser.parse_args_or_exit(); } @@ -37,9 +38,7 @@ fn main() -> Result<()> { let mut host = input::get_host(&mut config)?; - if !dry_run { - let platform = host.platform.to_owned(); - platform.run(&mut host, &mut config)?; - } + let platform = host.platform.to_owned(); + platform.run(&mut host, &mut config)?; } }