Skip to content

Commit

Permalink
sea-orm-migration: bump clap version to 3.1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanh Van committed May 11, 2022
1 parent e84aa1c commit 56d03cf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 30 deletions.
2 changes: 1 addition & 1 deletion sea-orm-migration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ path = "src/lib.rs"
[dependencies]
async-std = { version = "^1", features = ["attributes", "tokio1"] }
async-trait = { version = "^0.1" }
clap = { version = "^2.33" }
clap = { version = "^3.1.17", features = ["env"] }
dotenv = { version = "^0.15" }
sea-orm = { version = "^0.8.0", path = "../", default-features = false, features = ["macros"] }
sea-orm-cli = { version = "^0.8.1", path = "../sea-orm-cli", default-features = false }
Expand Down
58 changes: 32 additions & 26 deletions sea-orm-migration/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{App, Arg, AppSettings};
use clap::{Command, Arg};
use dotenv::dotenv;
use std::{fmt::Display, process::exit};
use tracing_subscriber::{prelude::*, EnvFilter};
Expand All @@ -19,21 +19,21 @@ where
get_matches(migrator, db, app).await;
}

pub async fn get_matches<M>(_: M, db: &DbConn, app: App<'static, 'static>)
pub async fn get_matches<M>(_: M, db: &DbConn, app: Command<'static>)
where
M: MigratorTrait,
{
let matches = app.get_matches();
let mut verbose = false;
let filter = match matches.subcommand() {
(_, None) => "sea_orm_migration=info",
(_, Some(args)) => match args.is_present("VERBOSE") {
Some((_, args)) => match args.is_present("VERBOSE") {
true => {
verbose = true;
"debug"
}
false => "sea_orm_migration=info",
},
None => "sea_schema::migration=info",
};
let filter_layer = EnvFilter::try_new(filter).unwrap();
if verbose {
Expand All @@ -53,35 +53,41 @@ where
.init()
};
match matches.subcommand() {
("fresh", _) => M::fresh(db).await,
("refresh", _) => M::refresh(db).await,
("reset", _) => M::reset(db).await,
("status", _) => M::status(db).await,
("up", None) => M::up(db, None).await,
("down", None) => M::down(db, Some(1)).await,
("up", Some(args)) => {
let str = args.value_of("NUM_MIGRATION").unwrap_or_default();
let steps = str.parse().ok();
M::up(db, steps).await
}
("down", Some(args)) => {
let str = args.value_of("NUM_MIGRATION").unwrap();
let steps = str.parse().ok().unwrap_or(1);
M::down(db, Some(steps)).await
}
_ => M::up(db, None).await,
Some((cmd, args)) => match cmd {
"fresh" => M::fresh(db).await,
"refresh" => M::refresh(db).await,
"reset" => M::reset(db).await,
"status" => M::status(db).await,
"up" => match args.subcommand() {
Some(_) => {
let str = args.value_of("NUM_MIGRATION").unwrap_or_default();
let steps = str.parse().ok();
M::up(db, steps).await
}
None => M::up(db, None).await,
},
"down" => match args.subcommand() {
Some(_) => {
let str = args.value_of("NUM_MIGRATION").unwrap();
let steps = str.parse().ok().unwrap_or(1);
M::down(db, Some(steps)).await
}
None => M::down(db, Some(1)).await,
},
_ => M::up(db, None).await,
},
None => M::up(db, None).await,
}
.unwrap_or_else(handle_error);
}

pub fn build_cli() -> App<'static, 'static> {
let mut app = App::new("sea-orm-migration")
pub fn build_cli() -> Command<'static> {
let mut app = Command::new("sea-orm-migration")
.version(env!("CARGO_PKG_VERSION"))
.setting(AppSettings::VersionlessSubcommands)
.arg(
Arg::with_name("VERBOSE")
Arg::new("VERBOSE")
.long("verbose")
.short("v")
.short('v')
.help("Show debug messages")
.takes_value(false)
.global(true),
Expand Down
6 changes: 3 additions & 3 deletions sea-orm-migration/src/manager.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use sea_orm::sea_query::{
extension::postgres::{TypeAlterStatement, TypeCreateStatement, TypeDropStatement},
ForeignKeyCreateStatement, ForeignKeyDropStatement, IndexCreateStatement,
IndexDropStatement, TableAlterStatement, TableCreateStatement, TableDropStatement,
TableRenameStatement, TableTruncateStatement,
ForeignKeyCreateStatement, ForeignKeyDropStatement, IndexCreateStatement, IndexDropStatement,
TableAlterStatement, TableCreateStatement, TableDropStatement, TableRenameStatement,
TableTruncateStatement,
};
use sea_orm::{ConnectionTrait, DbBackend, DbConn, DbErr, StatementBuilder};
use sea_schema::{mysql::MySql, postgres::Postgres, probe::SchemaProbe, sqlite::Sqlite};
Expand Down

0 comments on commit 56d03cf

Please sign in to comment.