1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use clap::{ArgMatches, Command};
use crate::{
cli::{
cmds::flight::{
common::{self, SeaplaneFlightCommonArgMatches},
IMAGE_SPEC,
},
errors::wrap_cli_context,
validator::{validate_flight_name, validate_name_id},
CliCommand,
},
context::{Ctx, FlightCtx},
error::Result,
};
#[derive(Copy, Clone, Debug)]
pub struct SeaplaneFlightEdit;
impl SeaplaneFlightEdit {
pub fn command() -> Command<'static> {
let validator = |s: &str| validate_name_id(validate_flight_name, s);
Command::new("edit")
.about("Edit a local Flight Plan")
.after_help(IMAGE_SPEC)
.override_usage("seaplane flight edit <NAME|ID> [OPTIONS]")
.arg(
arg!(name_id required =["NAME|ID"])
.help("The source name or ID of the Flight Plan to edit")
.validator(validator),
)
.arg(arg!(--exact - ('x')).help("The given name or ID must be an exact match"))
.args(common::args(false))
}
}
impl CliCommand for SeaplaneFlightEdit {
fn run(&self, ctx: &mut Ctx) -> Result<()> {
if ctx.args.stateless {
cli_eprint!(@Red, "error: ");
cli_eprint!("'");
cli_eprint!(@Yellow, "--stateless");
cli_eprint!("' cannot be used with '");
cli_eprint!(@Yellow, "seaplane flight edit");
cli_eprintln!("'");
cli_eprintln!("(hint: 'seaplane flight edit' only modifies local plans)");
cli_eprint!("(hint: you may want 'seaplane ");
cli_eprint!(@Green, "formation ");
cli_eprintln!("edit' instead)");
std::process::exit(1);
}
let flights = &mut ctx.db.flights;
if let Err(e) = flights.update_flight(
ctx.args.name_id.as_ref().unwrap(),
ctx.args.exact,
ctx.flight_ctx.get_or_init(),
) {
return wrap_cli_context(e, ctx.args.exact, false);
}
ctx.persist_flights()?;
cli_print!("Successfully edited Flight Plan '");
cli_print!(@Yellow, "{}", ctx.args.name_id.as_ref().unwrap());
cli_println!("'");
Ok(())
}
fn update_ctx(&self, matches: &ArgMatches, ctx: &mut Ctx) -> Result<()> {
ctx.args.name_id = matches.get_one::<String>("name_id").map(ToOwned::to_owned);
ctx.flight_ctx
.init(FlightCtx::from_flight_common(&SeaplaneFlightCommonArgMatches(matches), "")?);
Ok(())
}
}