diff options
-rw-r--r-- | Cargo.lock | 7 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | src/hostfile.rs | 19 | ||||
-rw-r--r-- | src/lib.rs | 3 |
4 files changed, 29 insertions, 1 deletions
@@ -140,6 +140,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" [[package]] +name = "hostfile" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2733206bcc0550a15b450c64d8aa859f486d7281c4c0c36ef904b361960d658" + +[[package]] name = "indoc" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -498,6 +504,7 @@ dependencies = [ "anyhow", "clap", "directories", + "hostfile", "indoc", "ron", "serde", @@ -16,3 +16,4 @@ tracing = "0.1.37" thiserror = "1.0.40" tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } ssh2 = "0.9.4" +hostfile = "0.2.0" diff --git a/src/hostfile.rs b/src/hostfile.rs new file mode 100644 index 0000000..5414125 --- /dev/null +++ b/src/hostfile.rs @@ -0,0 +1,19 @@ +use crate::{Session, SessionSource}; + +pub struct HostFile; + +impl SessionSource for HostFile { + type Error = &'static str; + + type Iter = Vec<Session>; + + fn sessions(&self) -> Result<Self::Iter, Self::Error> { + let sessions = hostfile::parse_hostfile()? + .into_iter() + .flat_map(|h| h.names.into_iter()) + .map(Into::into) + .collect(); + + Ok(sessions) + } +} @@ -13,11 +13,12 @@ pub use tmux::Tmux; mod config; mod history; +mod hostfile; mod ssh; mod tmux; pub trait SessionSource { - type Error: std::error::Error; + type Error; type Iter: IntoIterator<Item = Session>; |