seaplane_cli/cli/cmds/
locks.rs

1mod acquire;
2mod common;
3mod list;
4mod release;
5mod renew;
6
7use clap::{value_parser, ArgMatches, Command};
8
9pub use self::{
10    acquire::SeaplaneLocksAcquire, common::SeaplaneLocksCommonArgMatches, list::SeaplaneLocksList,
11    release::SeaplaneLocksRelease, renew::SeaplaneLocksRenew,
12};
13use crate::{cli::CliCommand, printer::OutputFormat};
14
15#[derive(Copy, Clone, Debug)]
16pub struct SeaplaneLocks;
17
18impl SeaplaneLocks {
19    pub fn command() -> Command {
20        Command::new("locks")
21            .about("Operate on the Locks API")
22            .subcommand_required(true)
23            .arg_required_else_help(true)
24            .arg(
25                arg!(--format =["FORMAT"=>"table"] global)
26                    .help("Change the output format")
27                    .value_parser(value_parser!(OutputFormat)),
28            )
29            .subcommand(SeaplaneLocksList::command())
30            .subcommand(SeaplaneLocksAcquire::command())
31            .subcommand(SeaplaneLocksRelease::command())
32            .subcommand(SeaplaneLocksRenew::command())
33    }
34}
35
36impl CliCommand for SeaplaneLocks {
37    fn next_subcmd<'a>(
38        &self,
39        matches: &'a ArgMatches,
40    ) -> Option<(Box<dyn CliCommand>, &'a ArgMatches)> {
41        match &matches.subcommand() {
42            Some(("list", m)) => Some((Box::new(SeaplaneLocksList), m)),
43            Some(("acquire", m)) => Some((Box::new(SeaplaneLocksAcquire), m)),
44            Some(("release", m)) => Some((Box::new(SeaplaneLocksRelease), m)),
45            Some(("renew", m)) => Some((Box::new(SeaplaneLocksRenew), m)),
46            _ => None,
47        }
48    }
49}