webview_bundle_cli/commands/
mod.rs

1mod bundle;
2pub mod extract;
3pub mod pack;
4
5use crate::options::{cli_options, CliOptions, ColorsArg};
6use crate::VERSION;
7use bpaf::Bpaf;
8use std::ffi::OsString;
9
10#[derive(Debug, Clone, Bpaf)]
11#[bpaf(options, version(VERSION))]
12pub enum CliCommand {
13  /// Create webview bundle archive
14  #[bpaf(command)]
15  Pack {
16    #[bpaf(external(cli_options), hide_usage)]
17    cli_options: CliOptions,
18
19    /// Outfile path to create webview bundle archive.
20    /// If not provided, will create file with directory name.
21    /// If extension not set, will automatically add extension (`.wvb`)
22    #[bpaf(short('o'), long("outfile"), argument("PATH"), optional)]
23    outfile: Option<String>,
24
25    /// Options to truncate outfile if file already exists.
26    #[bpaf(long("truncate"), switch)]
27    truncate: bool,
28
29    /// Directory path to archive as webview bundle format.
30    #[bpaf(positional("PATH"))]
31    dir: OsString,
32  },
33
34  /// Extract webview bundle archive
35  #[bpaf(command)]
36  Extract {
37    #[bpaf(external(cli_options), hide_usage)]
38    cli_options: CliOptions,
39
40    /// Don't create extract files on disk, instead just look what inside on the webview bundle file.
41    #[bpaf(long("dry-run"), switch)]
42    dry_run: bool,
43
44    /// Outdir path to extract webview bundle files.
45    /// If not provided, will use webview bundle file name as directory.
46    #[bpaf(short('o'), long("outdir"), argument("PATH"), optional)]
47    outdir: Option<String>,
48
49    /// Webview bundle file path to extract.
50    #[bpaf(positional("PATH"))]
51    file: OsString,
52  },
53}
54
55impl CliCommand {
56  const fn cli_options(&self) -> Option<&CliOptions> {
57    match self {
58      CliCommand::Pack { cli_options, .. } | CliCommand::Extract { cli_options, .. } => {
59        Some(cli_options)
60      }
61    }
62  }
63
64  pub const fn get_color(&self) -> Option<&ColorsArg> {
65    match self.cli_options() {
66      Some(cli_options) => cli_options.colors.as_ref(),
67      None => None,
68    }
69  }
70}