diff --git a/cli/src/main.rs b/cli/src/main.rs index 653a75a0..f1f42039 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,5 +1,5 @@ -use clap::Parser; -use seaography_generator::{write_project, WebFrameworkEnum}; +use clap::{ArgEnum, Parser}; +use seaography_generator::write_project; #[derive(clap::Parser)] #[clap(author, version, about, long_about = None)] @@ -28,8 +28,8 @@ pub struct Args { #[clap(short, long)] pub hidden_tables: Option, - #[clap(short, long)] - pub framework: Option, + #[clap(short, long, arg_enum, value_parser, default_value = "poem")] + pub framework: WebFrameworkEnum, } /** @@ -143,10 +143,25 @@ async fn main() { expanded_format, tables, sql_library, - args.framework.unwrap_or_else(|| WebFrameworkEnum::Poem), + args.framework.into(), args.depth_limit, args.complexity_limit, ) .await .unwrap(); } + +#[derive(ArgEnum, Debug, Clone, Copy, Eq, PartialEq)] +pub enum WebFrameworkEnum { + Actix, + Poem, +} + +impl From for seaography_generator::WebFrameworkEnum { + fn from(framework: WebFrameworkEnum) -> Self { + match framework { + WebFrameworkEnum::Actix => seaography_generator::WebFrameworkEnum::Actix, + WebFrameworkEnum::Poem => seaography_generator::WebFrameworkEnum::Poem, + } + } +} diff --git a/generator/src/lib.rs b/generator/src/lib.rs index 2249d3f8..586d29ba 100644 --- a/generator/src/lib.rs +++ b/generator/src/lib.rs @@ -15,30 +15,6 @@ pub enum WebFrameworkEnum { Poem, } -impl std::str::FromStr for WebFrameworkEnum { - type Err = String; - - fn from_str(input: &str) -> std::result::Result { - match input { - "actix" => Ok(Self::Actix), - "poem" => Ok(Self::Poem), - _ => Err(format!( - "Invalid framework '{}', 'actix' and 'poem' are supported!", - input - )), - } - } -} - -impl std::fmt::Display for WebFrameworkEnum { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - WebFrameworkEnum::Actix => f.write_str("actix"), - WebFrameworkEnum::Poem => f.write_str("poem"), - } - } -} - pub async fn write_project>( path: &P, db_url: &str,