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:
parent
290d2c5172
commit
fe1877a49d
@ -12,10 +12,20 @@ documentation = "https://docs.rs/sea-orm"
|
|||||||
repository = "https://github.com/SeaQL/sea-orm"
|
repository = "https://github.com/SeaQL/sea-orm"
|
||||||
categories = [ "database" ]
|
categories = [ "database" ]
|
||||||
keywords = ["async", "orm", "mysql", "postgres", "sqlite"]
|
keywords = ["async", "orm", "mysql", "postgres", "sqlite"]
|
||||||
|
default-run = "sea-orm-cli"
|
||||||
|
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "sea_orm_cli"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "sea-orm-cli"
|
name = "sea-orm-cli"
|
||||||
path = "src/main.rs"
|
path = "src/bin/main.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "sea"
|
||||||
|
path = "src/bin/sea.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "^2.33.3" }
|
clap = { version = "^2.33.3" }
|
||||||
|
@ -1,5 +1,19 @@
|
|||||||
# SeaORM CLI
|
# 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:
|
Getting Help:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
18
sea-orm-cli/src/bin/main.rs
Normal file
18
sea-orm-cli/src/bin/main.rs
Normal 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"),
|
||||||
|
}
|
||||||
|
}
|
19
sea-orm-cli/src/bin/sea.rs
Normal file
19
sea-orm-cli/src/bin/sea.rs
Normal 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"),
|
||||||
|
}
|
||||||
|
}
|
@ -108,3 +108,4 @@ pub fn build_cli() -> App<'static, 'static> {
|
|||||||
)
|
)
|
||||||
.setting(AppSettings::SubcommandRequiredElseHelp)
|
.setting(AppSettings::SubcommandRequiredElseHelp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,27 +1,10 @@
|
|||||||
|
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use dotenv::dotenv;
|
|
||||||
use sea_orm_codegen::{EntityTransformer, OutputFile, WithSerde};
|
use sea_orm_codegen::{EntityTransformer, OutputFile, WithSerde};
|
||||||
use std::{error::Error, fmt::Display, fs, io::Write, path::Path, process::Command, str::FromStr};
|
use std::{error::Error, fmt::Display, fs, io::Write, path::Path, process::Command, str::FromStr};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
mod cli;
|
pub async fn run_generate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Error>> {
|
||||||
|
|
||||||
#[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>> {
|
|
||||||
match matches.subcommand() {
|
match matches.subcommand() {
|
||||||
("entity", Some(args)) => {
|
("entity", Some(args)) => {
|
||||||
let output_dir = args.value_of("OUTPUT_DIR").unwrap();
|
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(())
|
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();
|
let migrate_subcommand = matches.subcommand();
|
||||||
// If it's `migrate init`
|
// If it's `migrate init`
|
||||||
if let ("init", Some(args)) = migrate_subcommand {
|
if let ("init", Some(args)) = migrate_subcommand {
|
||||||
@ -263,7 +246,7 @@ fn run_migrate_command(matches: &ArgMatches<'_>) -> Result<(), Box<dyn Error>> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_error<E>(error: E)
|
pub fn handle_error<E>(error: E)
|
||||||
where
|
where
|
||||||
E: Display,
|
E: Display,
|
||||||
{
|
{
|
||||||
@ -275,6 +258,7 @@ where
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use clap::AppSettings;
|
use clap::AppSettings;
|
||||||
|
use crate::cli;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic(
|
#[should_panic(
|
5
sea-orm-cli/src/lib.rs
Normal file
5
sea-orm-cli/src/lib.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
pub mod cli;
|
||||||
|
pub mod commands;
|
||||||
|
|
||||||
|
pub use cli::*;
|
||||||
|
pub use commands::*;
|
Loading…
x
Reference in New Issue
Block a user