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

* Simplify bin name from  sea-orm-cli to sea

* -S

* fixed test
This commit is contained in:
Alex 2022-03-26 18:06:14 +08:00 committed by GitHub
parent 290d2c5172
commit fe1877a49d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 22 deletions

View File

@ -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" }

View File

@ -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

View File

@ -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"),
}
}

View File

@ -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"),
}
}

View File

@ -108,3 +108,4 @@ pub fn build_cli() -> App<'static, 'static> {
)
.setting(AppSettings::SubcommandRequiredElseHelp)
}

View File

@ -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();
@ -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 {
@ -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,
{
@ -275,6 +258,7 @@ where
mod tests {
use super::*;
use clap::AppSettings;
use crate::cli;
#[test]
#[should_panic(

5
sea-orm-cli/src/lib.rs Normal file
View File

@ -0,0 +1,5 @@
pub mod cli;
pub mod commands;
pub use cli::*;
pub use commands::*;