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

sea as an alternative bin name to sea-orm-cli #558

Merged
merged 3 commits into from
Mar 26, 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
12 changes: 11 additions & 1 deletion sea-orm-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ documentation = "https://docs.rs/sea-orm"
repository = "https://github.com/SeaQL/sea-orm"
categories = [ "database" ]
keywords = ["async", "orm", "mysql", "postgres", "sqlite"]
default-run = "sea-orm-cli"


[lib]
name = "sea_orm_cli"
path = "src/lib.rs"

[[bin]]
name = "sea-orm-cli"
path = "src/main.rs"
path = "src/bin/main.rs"

[[bin]]
name = "sea"
path = "src/bin/sea.rs"

[dependencies]
clap = { version = "^2.33.3" }
Expand Down
14 changes: 14 additions & 0 deletions sea-orm-cli/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# SeaORM CLI

Install and Usage:

```sh
> cargo install sea-orm-cli
> sea-orm-cli help
```

Or:

```sh
> cargo install --bin sea
> sea help
```

Getting Help:

```sh
Expand Down
18 changes: 18 additions & 0 deletions sea-orm-cli/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

use dotenv::dotenv;
use sea_orm_cli::*;

#[async_std::main]
async fn main() {
dotenv().ok();

let matches = cli::build_cli().get_matches();

match matches.subcommand() {
("generate", Some(matches)) => run_generate_command(matches)
.await
.unwrap_or_else(handle_error),
("migrate", Some(matches)) => run_migrate_command(matches).unwrap_or_else(handle_error),
_ => unreachable!("You should never see this message"),
}
}
19 changes: 19 additions & 0 deletions sea-orm-cli/src/bin/sea.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! COPY FROM bin/main.rs

use dotenv::dotenv;
use sea_orm_cli::*;

#[async_std::main]
async fn main() {
dotenv().ok();

let matches = cli::build_cli().get_matches();

match matches.subcommand() {
("generate", Some(matches)) => run_generate_command(matches)
.await
.unwrap_or_else(handle_error),
("migrate", Some(matches)) => run_migrate_command(matches).unwrap_or_else(handle_error),
_ => unreachable!("You should never see this message"),
}
}
1 change: 1 addition & 0 deletions sea-orm-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@ pub fn build_cli() -> App<'static, 'static> {
)
.setting(AppSettings::SubcommandRequiredElseHelp)
}

26 changes: 5 additions & 21 deletions sea-orm-cli/src/main.rs → sea-orm-cli/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@

use clap::ArgMatches;
use dotenv::dotenv;
use sea_orm_codegen::{EntityTransformer, OutputFile, WithSerde};
use std::{error::Error, fmt::Display, fs, io::Write, path::Path, process::Command, str::FromStr};
use url::Url;

mod cli;

#[async_std::main]
async fn main() {
dotenv().ok();

let matches = cli::build_cli().get_matches();

match matches.subcommand() {
("generate", Some(matches)) => run_generate_command(matches)
.await
.unwrap_or_else(handle_error),
("migrate", Some(matches)) => run_migrate_command(matches).unwrap_or_else(handle_error),
_ => unreachable!("You should never see this message"),
}
}

async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Error>> {
pub async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Error>> {
match matches.subcommand() {
("entity", Some(args)) => {
let output_dir = args.value_of("OUTPUT_DIR").unwrap();
Expand Down Expand Up @@ -188,7 +171,7 @@ async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Er
Ok(())
}

fn run_migrate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Error>> {
pub fn run_migrate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Error>> {
let migrate_subcommand = matches.subcommand();
// If it's `migrate init`
if let ("init", Some(args)) = migrate_subcommand {
Expand Down Expand Up @@ -263,7 +246,7 @@ fn run_migrate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Error>> {
Ok(())
}

fn handle_error<E>(error: E)
pub fn handle_error<E>(error: E)
where
E: Display,
{
Expand All @@ -275,6 +258,7 @@ where
mod tests {
use super::*;
use clap::AppSettings;
use crate::cli;

#[test]
#[should_panic(
Expand Down
5 changes: 5 additions & 0 deletions sea-orm-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod cli;
pub mod commands;

pub use cli::*;
pub use commands::*;