use clap::{Parser, Subcommand};
use sysexits::ExitCode;
use crate::{VERSION, EXIT_CODE_INSUFFICIENT_PARAMS, cli::command::CommandExecutor};
pub mod command;
pub mod config;
pub mod util;
#[derive(Parser)]
#[command(
version = VERSION,
disable_help_subcommand = true,
about = "A secure and high performance secret management software that is compatible with Hashicorp Vault."
)]
pub struct Cli {
#[command(subcommand)]
command: Option<Commands>,
}
#[derive(Subcommand)]
pub enum Commands {
Server(command::server::Server),
Status(command::status::Status),
Operator(command::operator::Operator),
Read(command::read::Read),
Write(command::write::Write),
Delete(command::delete::Delete),
List(command::list::List),
Login(command::login::Login),
Auth(command::auth::Auth),
}
impl Commands {
pub fn execute(&mut self) -> ExitCode {
return match self {
Commands::Server(server) => server.execute(),
Commands::Status(status) => status.execute(),
Commands::Operator(operator) => operator.execute(),
Commands::Read(read) => read.execute(),
Commands::Write(write) => write.execute(),
Commands::Delete(delete) => delete.execute(),
Commands::List(list) => list.execute(),
Commands::Login(login) => login.execute(),
Commands::Auth(auth) => auth.execute(),
}
}
}
impl Cli {
#[inline]
pub fn run(&mut self) -> ExitCode {
if let Some(ref mut cmd) = &mut self.command {
return cmd.execute();
}
EXIT_CODE_INSUFFICIENT_PARAMS
}
}