seaplane_cli/cli/cmds/
flight.rs

1pub mod common;
2mod copy;
3mod delete;
4mod edit;
5mod list;
6mod plan;
7#[cfg(feature = "unstable")]
8mod template;
9
10use clap::{ArgMatches, Command};
11use seaplane::rexports::container_image_ref::{ImageReference, ImageReferenceError};
12
13#[cfg(feature = "unstable")]
14pub use self::template::SeaplaneFlightTemplate;
15pub use self::{
16    common::SeaplaneFlightCommonArgMatches, copy::SeaplaneFlightCopy, delete::SeaplaneFlightDelete,
17    edit::SeaplaneFlightEdit, list::SeaplaneFlightList, plan::SeaplaneFlightPlan,
18};
19use crate::{
20    cli::{specs::IMAGE_SPEC, CliCommand},
21    error::{CliError, Result},
22};
23
24pub const FLIGHT_MINIMUM_DEFAULT: u64 = 1;
25
26/// Allows eliding `registry` but otherwise just proxies parsing to ImageReference
27pub fn str_to_image_ref(registry: &str, image_str: &str) -> Result<ImageReference> {
28    match image_str.parse::<ImageReference>() {
29        Ok(ir) => Ok(ir),
30        Err(ImageReferenceError::ErrDomainInvalidFormat(_)) => {
31            let ir: ImageReference = format!("{registry}/{image_str}").parse()?;
32            Ok(ir)
33        }
34        Err(e) => Err(CliError::from(e)),
35    }
36}
37
38#[derive(Copy, Clone, Debug)]
39pub struct SeaplaneFlight;
40
41impl SeaplaneFlight {
42    pub fn command() -> Command {
43        #[cfg_attr(not(feature = "unstable"), allow(unused_mut))]
44        let mut app = Command::new("flight")
45            .about("Operate on local Flight Plans which define \"Flights\" (logical containers), and are then referenced by Formations")
46            .subcommand_required(true)
47            .arg_required_else_help(true)
48            .subcommand(SeaplaneFlightPlan::command())
49            .subcommand(SeaplaneFlightCopy::command())
50            .subcommand(SeaplaneFlightEdit::command())
51            .subcommand(SeaplaneFlightDelete::command())
52            .subcommand(SeaplaneFlightList::command());
53
54        #[cfg(feature = "unstable")]
55        {
56            app = app.subcommand(SeaplaneFlightTemplate::command());
57        }
58        app
59    }
60}
61
62impl CliCommand for SeaplaneFlight {
63    fn next_subcmd<'a>(
64        &self,
65        matches: &'a ArgMatches,
66    ) -> Option<(Box<dyn CliCommand>, &'a ArgMatches)> {
67        match &matches.subcommand() {
68            Some(("copy", m)) => Some((Box::new(SeaplaneFlightCopy), m)),
69            Some(("edit", m)) => Some((Box::new(SeaplaneFlightEdit), m)),
70            Some(("delete", m)) => Some((Box::new(SeaplaneFlightDelete), m)),
71            Some(("list", m)) => Some((Box::new(SeaplaneFlightList), m)),
72            Some(("plan", m)) => Some((Box::new(SeaplaneFlightPlan), m)),
73            #[cfg(feature = "unstable")]
74            Some(("template", m)) => Some((Box::new(SeaplaneFlightTemplate), m)),
75            _ => None,
76        }
77    }
78}