Skip to main content

max / mountaineer-sysop

2.0 KB · 80 lines History Blame Raw
1 mod config;
2 mod info;
3 mod motd;
4 mod net;
5 mod roles;
6 mod services;
7 mod storage;
8 mod wifi;
9
10 use clap::{Parser, Subcommand};
11
12 #[derive(Parser)]
13 #[command(name = "sysop", about = "Mountaineer operator interface")]
14 struct Cli {
15 #[command(subcommand)]
16 command: Command,
17 }
18
19 #[derive(Subcommand)]
20 enum Command {
21 /// Show which tool fills a role and where its config lives
22 Info {
23 /// Role name (omit for the full list)
24 role: Option<String>,
25 },
26 /// Login tip rotation (on/off/print)
27 Motd {
28 #[command(subcommand)]
29 action: Option<MotdAction>,
30 },
31 /// s6-rc service health view
32 Services {
33 /// One-line summary for the yambar `svc` segment
34 #[arg(long)]
35 summary: bool,
36 },
37 /// ZFS pool health view
38 Storage {
39 /// One-line summary for the yambar `zfs` segment
40 #[arg(long)]
41 summary: bool,
42 },
43 /// Connect to a wireless network
44 Wifi,
45 /// Network interface status
46 Net {
47 /// One-line summary for the yambar `net` segment
48 #[arg(long)]
49 summary: bool,
50 },
51 }
52
53 #[derive(Subcommand)]
54 enum MotdAction {
55 /// Enable the login tip
56 On,
57 /// Disable the login tip
58 Off,
59 /// Emit the current tip (called by /etc/profile.d/sysop-motd.sh on login)
60 Print,
61 }
62
63 fn main() -> anyhow::Result<()> {
64 let cli = Cli::parse();
65 let code = match cli.command {
66 Command::Info { role } => info::run(role)?,
67 Command::Motd { action } => match action {
68 None => motd::status()?,
69 Some(MotdAction::On) => motd::set(true)?,
70 Some(MotdAction::Off) => motd::set(false)?,
71 Some(MotdAction::Print) => motd::print()?,
72 },
73 Command::Services { summary } => services::run(summary)?,
74 Command::Storage { summary } => storage::run(summary)?,
75 Command::Wifi => wifi::run()?,
76 Command::Net { summary } => net::run(summary)?,
77 };
78 std::process::exit(code);
79 }
80