46 lines
1.5 KiB
Rust
46 lines
1.5 KiB
Rust
#![feature(fs_try_exists)]
|
|
|
|
use anyhow::Result;
|
|
use config::ConfigManager;
|
|
use std::io;
|
|
use termion::screen::IntoAlternateScreen;
|
|
use tui::{ backend::TermionBackend, Terminal };
|
|
|
|
pub mod config;
|
|
pub mod input;
|
|
pub mod platform;
|
|
|
|
fn main() -> Result<()> {
|
|
let mut search_path: Option<String> = None;
|
|
let mut config_root: Option<String> = None;
|
|
let mut dry_run: bool = false;
|
|
{
|
|
let mut parser = argparse::ArgumentParser::new();
|
|
|
|
parser.set_description("Key manager for command line programs");
|
|
|
|
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");
|
|
|
|
parser.parse_args_or_exit();
|
|
}
|
|
|
|
let mut config: ConfigManager = ConfigManager::new(config_root, search_path)?;
|
|
|
|
let backend = TermionBackend::new(io::stdout().into_alternate_screen()?);
|
|
let mut term = Terminal::new(backend)?;
|
|
|
|
loop {
|
|
term.clear()?;
|
|
|
|
let mut host = input::get_host(&mut config)?;
|
|
|
|
if !dry_run {
|
|
let platform = host.platform.to_owned();
|
|
platform.run(&mut host, &mut config)?;
|
|
}
|
|
}
|
|
}
|