Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nit: CLI framework options with clap arg_enum and default #96

Merged
merged 1 commit into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -28,8 +28,8 @@ pub struct Args {
#[clap(short, long)]
pub hidden_tables: Option<bool>,

#[clap(short, long)]
pub framework: Option<WebFrameworkEnum>,
#[clap(short, long, arg_enum, value_parser, default_value = "poem")]
pub framework: WebFrameworkEnum,
}

/**
Expand Down Expand Up @@ -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<WebFrameworkEnum> for seaography_generator::WebFrameworkEnum {
fn from(framework: WebFrameworkEnum) -> Self {
match framework {
WebFrameworkEnum::Actix => seaography_generator::WebFrameworkEnum::Actix,
WebFrameworkEnum::Poem => seaography_generator::WebFrameworkEnum::Poem,
}
}
}
24 changes: 0 additions & 24 deletions generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebFrameworkEnum, Self::Err> {
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<P: AsRef<Path>>(
path: &P,
db_url: &str,
Expand Down