Skip to main content

max / mountaineer-sysop

1.2 KB · 44 lines History Blame Raw
1 use crate::config;
2 use anyhow::Result;
3 use std::time::SystemTime;
4
5 const TIPS: &[&str] = &[
6 "sysop info <role> — show which tool fills a role and where its config lives",
7 "sysop services — s6-rc service health",
8 "sysop wifi — network connections",
9 "sysop storage — ZFS pool state",
10 "sysop logs <svc> — structured logs for a service",
11 "sysop help — list all sysop commands",
12 ];
13
14 pub fn status() -> Result<i32> {
15 let cfg = config::load()?;
16 let state = if cfg.motd.enabled { "on" } else { "off" };
17 println!("motd: {state}");
18 println!("config: {}", config::path().display());
19 Ok(0)
20 }
21
22 pub fn set(enabled: bool) -> Result<i32> {
23 let mut cfg = config::load()?;
24 cfg.motd.enabled = enabled;
25 config::save(&cfg)?;
26 println!("motd: {}", if enabled { "on" } else { "off" });
27 Ok(0)
28 }
29
30 pub fn print() -> Result<i32> {
31 let cfg = config::load()?;
32 if !cfg.motd.enabled {
33 return Ok(0);
34 }
35 let bucket = SystemTime::now()
36 .duration_since(SystemTime::UNIX_EPOCH)
37 .map(|d| d.as_secs() / 60)
38 .unwrap_or(0) as usize;
39 let idx = bucket % TIPS.len();
40 println!();
41 println!(" {}", TIPS[idx]);
42 Ok(0)
43 }
44