commit 76f3b6592dea4b9bbc7f84830a9257baf38a7649 Author: Benjamyn Love Date: Tue Aug 6 13:44:04 2024 +1000 initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5c7247b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..60f4614 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,68 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "motd-rust" +version = "0.1.0" +dependencies = [ + "glob", + "untildify", +] + +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + +[[package]] +name = "untildify" +version = "0.1.1" +dependencies = [ + "regex", +] diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..0466a3b --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "motd-rust" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +glob = "0.3.1" +untildify = { path = "../untildify" } diff --git a/src/files.rs b/src/files.rs new file mode 100644 index 0000000..0dab253 --- /dev/null +++ b/src/files.rs @@ -0,0 +1,28 @@ +use crate::structs::*; +use glob::glob; +use std::{fs, path::PathBuf}; +use untildify::untildify; + +pub fn load_motds() -> Vec { + let mut path: String = untildify("~/.local/motd"); + path.push_str("/*.motd"); + + let mut motds = Vec::::new(); + + for entry in glob(&path).unwrap() { + match entry { + Ok(path) => motds.push(read_motd(path)), + Err(e) => { + println!("{}", e); + } + } + } + + motds +} + +pub fn read_motd(path: PathBuf) -> MOTD { + let motd_contents: String = fs::read_to_string(path).unwrap(); + let motd = MOTD::new(motd_contents); + motd +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..19d30fe --- /dev/null +++ b/src/main.rs @@ -0,0 +1,14 @@ +mod files; +use files::*; + +mod structs; + +fn main() { + let motds = load_motds(); + println!("** Important Notes **"); + for motd in motds { + motd.print(); + } + println!(); + println!(); +} diff --git a/src/structs.rs b/src/structs.rs new file mode 100644 index 0000000..72b7c1b --- /dev/null +++ b/src/structs.rs @@ -0,0 +1,15 @@ +pub struct MOTD { + title: Option, +} + +impl MOTD { + pub fn new(motd_title: String) -> MOTD { + return MOTD { + title: Some(String::from(motd_title)), + }; + } + + pub fn print(&self) { + println!("[*] {}", &self.title.as_ref().unwrap().trim()) + } +}