summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2023-03-19 21:40:05 -0500
committerToby Vincent <tobyv13@gmail.com>2023-03-19 21:40:05 -0500
commit6b0ca0d87fa180262ff651d287a3d09e92480178 (patch)
tree791cade20a81bf25d3ed4dbf0f63dcdb6d5a049a
parent82598a3adc9d950c34346ccd0128d6ef78bbb437 (diff)
feat: impl SessionSource for /etc/hosts
-rw-r--r--Cargo.lock7
-rw-r--r--Cargo.toml1
-rw-r--r--src/hostfile.rs19
-rw-r--r--src/lib.rs3
4 files changed, 29 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4e4ea07..90eab5f 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -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",
diff --git a/Cargo.toml b/Cargo.toml
index efe4443..3a8c041 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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)
+ }
+}
diff --git a/src/lib.rs b/src/lib.rs
index d9a9862..dc3961f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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>;