| 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 |
|
| 22 |
Info { |
| 23 |
|
| 24 |
role: Option<String>, |
| 25 |
}, |
| 26 |
|
| 27 |
Motd { |
| 28 |
#[command(subcommand)] |
| 29 |
action: Option<MotdAction>, |
| 30 |
}, |
| 31 |
|
| 32 |
Services { |
| 33 |
|
| 34 |
#[arg(long)] |
| 35 |
summary: bool, |
| 36 |
}, |
| 37 |
|
| 38 |
Storage { |
| 39 |
|
| 40 |
#[arg(long)] |
| 41 |
summary: bool, |
| 42 |
}, |
| 43 |
|
| 44 |
Wifi, |
| 45 |
|
| 46 |
Net { |
| 47 |
|
| 48 |
#[arg(long)] |
| 49 |
summary: bool, |
| 50 |
}, |
| 51 |
} |
| 52 |
|
| 53 |
#[derive(Subcommand)] |
| 54 |
enum MotdAction { |
| 55 |
|
| 56 |
On, |
| 57 |
|
| 58 |
Off, |
| 59 |
|
| 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 |
|