use anyhow::Result;
use clap::{ArgMatches, Command};
use crate::{CliCommand, core::command::command};
mod domain;
mod invitations;
mod members;
mod shared;
mod show;
use domain::DomainCommand;
use invitations::InvitationsCommand;
use members::MembersCommand;
use show::ShowCommand;
#[derive(Debug)]
pub(crate) struct OrgCommand {
show: ShowCommand,
members: MembersCommand,
invitations: InvitationsCommand,
domain: DomainCommand,
}
impl OrgCommand {
pub(crate) fn new() -> Self {
Self {
show: ShowCommand::new(),
members: MembersCommand::new(),
invitations: InvitationsCommand::new(),
domain: DomainCommand::new(),
}
}
}
impl CliCommand for OrgCommand {
fn command(&self) -> Command {
command(
"org",
"Show and administer your organization: members, invitations, domain",
)
.subcommand(self.show.command())
.subcommand(self.members.command())
.subcommand(self.invitations.command())
.subcommand(self.domain.command())
}
fn handler(&self, matches: &ArgMatches) -> Result<()> {
match matches.subcommand() {
Some(("show", m)) => self.show.handler(m),
Some(("members", m)) => self.members.handler(m),
Some(("invitations", m)) => self.invitations.handler(m),
Some(("domain", m)) => self.domain.handler(m),
_ => self.show.handler(matches),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn command_definition_is_valid() {
OrgCommand::new()
.command()
.version("0.0.0-test")
.debug_assert();
}
}