seaplane_cli/cli/cmds/
license.rs

1use clap::{ArgMatches, Command};
2
3use crate::{cli::CliCommand, error::Result, Ctx};
4
5static THIRD_PARTY_LICENSES: &str =
6    include_str!(concat!(env!("OUT_DIR"), "/third_party_licenses.md"));
7
8// @TODO @SIZE this str is ~11.3kb, it can be stored compressed at ~4kb. However that would
9// require a code to do the compression/decompression which is larger than the 7.3kb savings. There
10// are other locations in the code may benefit as well; if the uncompressed sum of those becomes
11// greater than code required to do the compression, we may look at compressing these large strings
12// to keep the binary size minimal.
13static SELF_LICENSE: &str = include_str!(concat!(env!("OUT_DIR"), "/LICENSE"));
14
15#[derive(Copy, Clone, Debug)]
16pub struct SeaplaneLicense;
17
18impl SeaplaneLicense {
19    pub fn command() -> Command {
20        Command::new("license")
21            .about("Print license information")
22            .arg(
23                arg!(--("third-party"))
24                    .help("Display a list of third party libraries and their licenses"),
25            )
26    }
27}
28
29impl CliCommand for SeaplaneLicense {
30    fn run(&self, ctx: &mut Ctx) -> Result<()> {
31        if ctx.args.third_party {
32            println!("{THIRD_PARTY_LICENSES}");
33        } else {
34            println!("{SELF_LICENSE}");
35        }
36
37        Ok(())
38    }
39
40    fn update_ctx(&self, matches: &ArgMatches, ctx: &mut Ctx) -> Result<()> {
41        ctx.args.third_party = matches.get_flag("third-party");
42        Ok(())
43    }
44}