Run definition over creation

This commit is contained in:
0xf8 2023-05-29 23:41:21 -04:00
parent 9be5bebf78
commit 87fa949309
Signed by: 0xf8
GPG Key ID: 446580D758689584
3 changed files with 11 additions and 15 deletions

View File

@ -24,6 +24,7 @@ impl std::fmt::Display for Host {
} }
impl Host { impl Host {
// todo: validate ssh config
pub fn edit(&mut self) -> Result<Self> { pub fn edit(&mut self) -> Result<Self> {
let mut data = toml::to_string_pretty(self)?; let mut data = toml::to_string_pretty(self)?;

View File

@ -21,19 +21,15 @@ pub fn get_host(config: &mut ConfigManager) -> Result<Host> {
.item("New host definition...") .item("New host definition...")
.default(0); .default(0);
let c = loop { Ok({
let c = select.interact()?; let c = select.interact()?;
if c == hosts.len() { if c == hosts.len() {
let _ = config.new_host()?; config.new_host()?
let _hosts = config.configs.to_owned();
hosts = _hosts.into_iter().collect();
} else { } else {
break c hosts.get(c).unwrap().to_owned()
} }
}; })
Ok(hosts.get(c).unwrap().to_owned())
} }
pub fn get_platform() -> Result<Platform> { pub fn get_platform() -> Result<Platform> {

View File

@ -13,7 +13,7 @@ pub mod platform;
fn main() -> Result<()> { fn main() -> Result<()> {
let mut search_path: Option<String> = None; let mut search_path: Option<String> = None;
let mut config_root: Option<String> = None; let mut config_root: Option<String> = None;
let mut dry_run: bool = false; // let mut dry_run: bool = false;
{ {
let mut parser = argparse::ArgumentParser::new(); 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.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 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 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(); parser.parse_args_or_exit();
} }
@ -37,9 +38,7 @@ fn main() -> Result<()> {
let mut host = input::get_host(&mut config)?; let mut host = input::get_host(&mut config)?;
if !dry_run { let platform = host.platform.to_owned();
let platform = host.platform.to_owned(); platform.run(&mut host, &mut config)?;
platform.run(&mut host, &mut config)?;
}
} }
} }