64 lines
1.5 KiB
Rust
64 lines
1.5 KiB
Rust
use anyhow::Result;
|
|
use crate::{ ConfigManager, config::Host };
|
|
use serde::{ Serialize, Deserialize };
|
|
use std::io;
|
|
use tui::{ backend::TermionBackend, Terminal };
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct PlatformKey {
|
|
pub file: String,
|
|
pub display: String,
|
|
}
|
|
|
|
impl std::fmt::Display for PlatformKey {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
f.write_str(&self.display)
|
|
}
|
|
}
|
|
|
|
|
|
// todo: GPG support
|
|
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
|
pub enum Platform {
|
|
SSH
|
|
}
|
|
|
|
impl std::fmt::Display for Platform {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
f.write_str(match self {
|
|
Platform::SSH => "SSH",
|
|
})
|
|
}
|
|
}
|
|
|
|
impl Platform {
|
|
pub fn all() -> Vec<Platform> {
|
|
vec![
|
|
Self::SSH
|
|
]
|
|
}
|
|
|
|
pub fn new_host(&self, config: &mut ConfigManager) -> Result<Host> {
|
|
match self {
|
|
Platform::SSH => self.ssh_new_host(config)
|
|
}
|
|
}
|
|
|
|
pub fn get_keys(&self, config: &ConfigManager) -> Vec<PlatformKey> {
|
|
match self {
|
|
Platform::SSH => self.ssh_get_keys(config),
|
|
}
|
|
}
|
|
pub fn run(&self, host: &mut Host, config: &mut ConfigManager, term: &mut Terminal<TermionBackend<io::Stdout>>) -> Result<()> {
|
|
match self {
|
|
Platform::SSH => self.ssh_run(host, config, term),
|
|
}
|
|
}
|
|
|
|
// --- --- ---
|
|
// GPG
|
|
// --- --- ---
|
|
}
|
|
|