hyper_scripter/args/
types.rs1use super::help_str::*;
2use crate::script_type::ScriptFullType;
3use clap::{Error as ClapError, Parser};
4use serde::Serialize;
5
6#[derive(Parser, Debug, Serialize)]
7pub struct Types {
8 #[clap(subcommand)]
9 pub subcmd: Option<TypesSubs>,
10}
11
12#[derive(Parser, Debug, Serialize)]
13#[clap(allow_hyphen_values = true)] pub enum TypesSubs {
15 #[clap(external_subcommand)]
16 Other(Vec<String>),
17 LS {
18 #[clap(long)]
19 no_sub: bool,
20 },
21 Template {
22 #[clap(long, short)]
23 edit: bool,
24 #[clap(help = TYPE_HELP)]
25 ty: ScriptFullType,
26 },
27}
28
29impl Types {
30 pub fn sanitize(&mut self) -> Result<(), ClapError> {
31 match self.subcmd.as_ref() {
32 None => self.subcmd = Some(TypesSubs::LS { no_sub: false }),
33 Some(TypesSubs::Other(args)) => {
34 let args = ["types", "template"]
35 .into_iter()
36 .chain(args.iter().map(|s| s.as_str()));
37 self.subcmd = Some(TypesSubs::try_parse_from(args)?);
38 }
39 _ => (),
40 }
41 Ok(())
42 }
43}