shitbox/src/cmd/false/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

41 lines
820 B
Rust

use super::Cmd;
use crate::Path;
use clap::Command;
use std::{error::Error, process};
#[derive(Debug)]
pub struct False {
name: &'static str,
path: Option<Path>,
}
impl Default for False {
fn default() -> Self {
Self {
name: "false",
path: Some(crate::Path::Bin),
}
}
}
impl Cmd for False {
fn name(&self) -> &str {
self.name
}
fn cli(&self) -> clap::Command {
Command::new(self.name)
.about("Does nothing unsuccessfully")
.long_about("Exit with a status code indicating failure")
.author("Nathan Fisher")
}
fn run(&self, _matches: Option<&clap::ArgMatches>) -> Result<(), Box<dyn Error>> {
process::exit(1);
}
fn path(&self) -> Option<Path> {
self.path
}
}