Skip to content

Commit

Permalink
sea-orm-cli: bump clap to 3.1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanh Van committed May 10, 2022
1 parent 2c4e1b2 commit 51c8b30
Show file tree
Hide file tree
Showing 6 changed files with 326 additions and 330 deletions.
2 changes: 1 addition & 1 deletion sea-orm-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ path = "src/bin/sea.rs"
required-features = ["codegen"]

[dependencies]
clap = { version = "^2.33.3" }
clap = { version = "^3.1.17", features = ["env"] }
dotenv = { version = "^0.15" }
async-std = { version = "^1.9", features = [ "attributes", "tokio1" ] }
sea-orm-codegen = { version = "^0.8.0", path = "../sea-orm-codegen", optional = true }
Expand Down
13 changes: 8 additions & 5 deletions sea-orm-cli/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ async fn main() {
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"),
Some((subcommand, matches)) => match subcommand {
"generate" => run_generate_command(matches)
.await
.unwrap_or_else(handle_error),
"migrate" => run_migrate_command(matches).unwrap_or_else(handle_error),
_ => unreachable!("You should never see this message"),
},
None => unreachable!("You should never see this message"),
}
}
13 changes: 8 additions & 5 deletions sea-orm-cli/src/bin/sea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ async fn main() {
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"),
Some((subcommand, matches)) => match subcommand {
"generate" => run_generate_command(matches)
.await
.unwrap_or_else(handle_error),
"migrate" => run_migrate_command(matches).unwrap_or_else(handle_error),
_ => unreachable!("You should never see this message"),
},
None => unreachable!("You should never see this message"),
}
}
64 changes: 31 additions & 33 deletions sea-orm-cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
use crate::migration::get_subcommands;
use clap::{App, AppSettings, Arg, SubCommand};
use clap::{Arg, Command};

pub fn build_cli() -> App<'static, 'static> {
let entity_subcommand = SubCommand::with_name("generate")
pub fn build_cli() -> Command<'static> {
let entity_subcommand = Command::new("generate")
.about("Codegen related commands")
.setting(AppSettings::VersionlessSubcommands)
.subcommand(
SubCommand::with_name("entity")
Command::new("entity")
.about("Generate entity")
.arg(
Arg::with_name("DATABASE_URL")
Arg::new("DATABASE_URL")
.long("database-url")
.short("u")
.short('u')
.help("Database URL")
.takes_value(true)
.required(true)
.env("DATABASE_URL"),
)
.arg(
Arg::with_name("DATABASE_SCHEMA")
Arg::new("DATABASE_SCHEMA")
.long("database-schema")
.short("s")
.short('s')
.help("Database schema")
.long_help("Database schema\n \
- For MySQL, this argument is ignored.\n \
Expand All @@ -29,78 +28,77 @@ pub fn build_cli() -> App<'static, 'static> {
.env("DATABASE_SCHEMA"),
)
.arg(
Arg::with_name("OUTPUT_DIR")
Arg::new("OUTPUT_DIR")
.long("output-dir")
.short("o")
.short('o')
.help("Entity file output directory")
.takes_value(true)
.default_value("./"),
)
.arg(
Arg::with_name("INCLUDE_HIDDEN_TABLES")
Arg::new("INCLUDE_HIDDEN_TABLES")
.long("include-hidden-tables")
.help("Generate entity file for hidden tables (i.e. table name starts with an underscore)")
.takes_value(false),
)
.arg(
Arg::with_name("TABLES")
Arg::new("TABLES")
.long("tables")
.short("t")
.use_delimiter(true)
.short('t')
.use_value_delimiter(true)
.help("Generate entity file for specified tables only (comma seperated)")
.takes_value(true)
.conflicts_with("INCLUDE_HIDDEN_TABLES"),
)
.arg(
Arg::with_name("EXPANDED_FORMAT")
Arg::new("EXPANDED_FORMAT")
.long("expanded-format")
.help("Generate entity file of expanded format")
.takes_value(false)
.conflicts_with("COMPACT_FORMAT"),
)
.arg(
Arg::with_name("COMPACT_FORMAT")
Arg::new("COMPACT_FORMAT")
.long("compact-format")
.help("Generate entity file of compact format")
.takes_value(false)
.conflicts_with("EXPANDED_FORMAT"),
)
.arg(
Arg::with_name("WITH_SERDE")
Arg::new("WITH_SERDE")
.long("with-serde")
.help("Automatically derive serde Serialize / Deserialize traits for the entity (none, serialize, deserialize, both)")
.takes_value(true)
.default_value("none")
)
.arg(
Arg::with_name("MAX_CONNECTIONS")
Arg::new("MAX_CONNECTIONS")
.long("max-connections")
.help("The maximum amount of connections to use when connecting to the database.")
.takes_value(true)
.default_value("1")
),
)
.setting(AppSettings::SubcommandRequiredElseHelp);
).subcommand_required(true).arg_required_else_help(true);

let arg_migration_dir = Arg::with_name("MIGRATION_DIR")
let arg_migration_dir = Arg::new("MIGRATION_DIR")
.long("migration-dir")
.short("d")
.short('d')
.help("Migration script directory")
.takes_value(true)
.default_value("./migration");
let mut migrate_subcommands = SubCommand::with_name("migrate")
let mut migrate_subcommands = Command::new("migrate")
.about("Migration related commands")
.subcommand(
SubCommand::with_name("init")
Command::new("init")
.about("Initialize migration directory")
.arg(arg_migration_dir.clone()),
)
.subcommand(
SubCommand::with_name("generate")
Command::new("generate")
.about("Generate a new, empty migration")
.arg(
Arg::with_name("MIGRATION_NAME")
.help("Name of the new migation")
Arg::new("MIGRATION_NAME")
.help("Name of the new migration")
.required(true)
.takes_value(true),
)
Expand All @@ -112,18 +110,18 @@ pub fn build_cli() -> App<'static, 'static> {
migrate_subcommands.subcommand(subcommand.arg(arg_migration_dir.clone()));
}

App::new("sea-orm-cli")
Command::new("sea-orm-cli")
.version(env!("CARGO_PKG_VERSION"))
.setting(AppSettings::VersionlessSubcommands)
.subcommand(entity_subcommand)
.subcommand(migrate_subcommands)
.arg(
Arg::with_name("VERBOSE")
Arg::new("VERBOSE")
.long("verbose")
.short("v")
.short('v')
.help("Show debug messages")
.takes_value(false)
.global(true),
)
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand_required(true)
.arg_required_else_help(true)
}
Loading

0 comments on commit 51c8b30

Please sign in to comment.