seaplane_cli/cli/cmds/restrict/
get.rs1use clap::{ArgMatches, Command};
2
3use crate::{
4 api::RestrictReq,
5 cli::{cmds::restrict::common, CliCommand},
6 context::{Ctx, RestrictCtx},
7 error::Result,
8 printer::{Output, OutputFormat},
9};
10
11static LONG_ABOUT: &str = "Get information about restrictions on a directory
12
13Directory will be displayed in base64 encoded format by default because they may contain
14arbitrary binary data. Use --decode to output the decoded values instead.";
15
16#[derive(Copy, Clone, Debug)]
17pub struct SeaplaneRestrictGet;
18
19impl SeaplaneRestrictGet {
20 pub fn command() -> Command {
21 Command::new("get")
22 .visible_alias("show")
23 .about("Retrieve information about a directory restriction")
24 .long_about(LONG_ABOUT)
25 .arg(common::api())
26 .arg(common::directory())
27 .arg(common::base64())
28 .args(common::display_args())
29 }
30}
31
32impl CliCommand for SeaplaneRestrictGet {
33 fn run(&self, ctx: &mut Ctx) -> Result<()> {
34 let restriction = {
35 let mut req = RestrictReq::new(ctx)?;
36 let restrict_ctx = ctx.restrict_ctx.get_mut_or_init();
37 req.set_api(restrict_ctx.api.as_ref().unwrap())?;
38 req.set_directory(restrict_ctx.directory.as_ref().unwrap().to_string())?;
39 req.get_restriction()?
40 };
41 match ctx.args.out_format {
42 OutputFormat::Json => restriction.print_json(ctx)?,
43 OutputFormat::Table => restriction.print_table(ctx)?,
44 }
45 Ok(())
46 }
47
48 fn update_ctx(&self, matches: &ArgMatches, ctx: &mut Ctx) -> Result<()> {
49 ctx.restrict_ctx.init(RestrictCtx::from_restrict_common(
50 &common::SeaplaneRestrictCommonArgMatches(matches),
51 )?);
52 ctx.args.out_format = matches.get_one("format").copied().unwrap_or_default();
53 let mut restrict_ctx = ctx.restrict_ctx.get_mut_or_init();
54 restrict_ctx.decode = matches.get_flag("decode");
55 restrict_ctx.no_header = matches.get_flag("no-header");
56 Ok(())
57 }
58
59 fn next_subcmd<'a>(
60 &self,
61 _matches: &'a ArgMatches,
62 ) -> Option<(Box<dyn CliCommand>, &'a ArgMatches)> {
63 None
64 }
65}