shitbox/src/cmd/nologin/mod.rs
Nathan Fisher fb389fd309 Simplify subcommand parsing:
- one match statement to return a `Box<dyn Cmd>`
- one array containing all command names
Only two places to register new commands (besides their module), both in
crate::cmd::mod.rs. Also removes `once_cell` crate dependency.

Replace `base64` crate dependency with `data_encoding::BASE64` so that
both base32 and base64 commands use the same crate.
2023-01-06 23:41:02 -05:00

40 lines
824 B
Rust

use super::Cmd;
use clap::Command;
use std::process;
#[derive(Debug)]
pub struct Nologin {
name: &'static str,
path: Option<crate::Path>,
}
impl Default for Nologin {
fn default() -> Self {
Self {
name: "nologin",
path: Some(crate::Path::Sbin),
}
}
}
impl Cmd for Nologin {
fn name(&self) -> &str {
self.name
}
fn cli(&self) -> clap::Command {
Command::new(self.name)
.author("Nathan Fisher")
.about("Denies a user account login ability")
}
fn run(&self, _matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn std::error::Error>> {
eprintln!("I'm sorry, I can't let you do that, Dave");
process::exit(42);
}
fn path(&self) -> Option<crate::Path> {
self.path
}
}