Moving clap to version 4 (#1468)
* Moving clap to vesion 4 * Moving the sea-orm-migration cli to clap v4 * Removing the deprecated flag from clapv4 * Upgrade clap to 4.3 * Fixup * . * Try compile [CLI] --------- Co-authored-by: aadi58002 <aadi58002gmail.com> Co-authored-by: Billy Chan <ccw.billy.123@gmail.com>
This commit is contained in:
parent
00c90b2d79
commit
f6c9d81918
@ -34,7 +34,7 @@ path = "src/bin/sea.rs"
|
||||
required-features = ["cli", "codegen"]
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "3.2", default-features = false, features = ["std", "env", "derive"], optional = true }
|
||||
clap = { version = "4.3", features = ["env", "derive"], optional = true }
|
||||
dotenvy = { version = "0.15", default-features = false, optional = true }
|
||||
async-std = { version = "1.9", default-features = false, features = ["attributes", "tokio1"], optional = true }
|
||||
sea-orm-codegen = { version = "=0.12.0", path = "../sea-orm-codegen", default-features = false, optional = true }
|
||||
|
@ -1,4 +1,4 @@
|
||||
use clap::StructOpt;
|
||||
use clap::Parser;
|
||||
use dotenvy::dotenv;
|
||||
use sea_orm_cli::{handle_error, run_generate_command, run_migrate_command, Cli, Commands};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! COPY FROM bin/main.rs
|
||||
|
||||
use clap::StructOpt;
|
||||
use clap::Parser;
|
||||
use dotenvy::dotenv;
|
||||
use sea_orm_cli::{handle_error, run_generate_command, run_migrate_command, Cli, Commands};
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
use clap::{ArgEnum, ArgGroup, Parser, Subcommand};
|
||||
use clap::{ArgGroup, Parser, Subcommand, ValueEnum};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(
|
||||
#[command(
|
||||
version,
|
||||
author,
|
||||
help_template = r#"{before-help}{name} {version}
|
||||
@ -37,28 +37,27 @@ AUTHORS:
|
||||
"#
|
||||
)]
|
||||
pub struct Cli {
|
||||
#[clap(action, global = true, short, long, help = "Show debug messages")]
|
||||
#[arg(global = true, short, long, help = "Show debug messages")]
|
||||
pub verbose: bool,
|
||||
|
||||
#[clap(subcommand)]
|
||||
#[command(subcommand)]
|
||||
pub command: Commands,
|
||||
}
|
||||
|
||||
#[derive(Subcommand, PartialEq, Eq, Debug)]
|
||||
pub enum Commands {
|
||||
#[clap(
|
||||
#[command(
|
||||
about = "Codegen related commands",
|
||||
arg_required_else_help = true,
|
||||
display_order = 10
|
||||
)]
|
||||
Generate {
|
||||
#[clap(subcommand)]
|
||||
#[command(subcommand)]
|
||||
command: GenerateSubcommands,
|
||||
},
|
||||
#[clap(about = "Migration related commands", display_order = 20)]
|
||||
#[command(about = "Migration related commands", display_order = 20)]
|
||||
Migrate {
|
||||
#[clap(
|
||||
value_parser,
|
||||
#[arg(
|
||||
global = true,
|
||||
short = 'd',
|
||||
long,
|
||||
@ -71,8 +70,7 @@ you should provide the directory of that submodule.",
|
||||
)]
|
||||
migration_dir: String,
|
||||
|
||||
#[clap(
|
||||
value_parser,
|
||||
#[arg(
|
||||
global = true,
|
||||
short = 's',
|
||||
long,
|
||||
@ -83,8 +81,7 @@ you should provide the directory of that submodule.",
|
||||
)]
|
||||
database_schema: Option<String>,
|
||||
|
||||
#[clap(
|
||||
value_parser,
|
||||
#[arg(
|
||||
global = true,
|
||||
short = 'u',
|
||||
long,
|
||||
@ -93,76 +90,59 @@ you should provide the directory of that submodule.",
|
||||
)]
|
||||
database_url: Option<String>,
|
||||
|
||||
#[clap(subcommand)]
|
||||
#[command(subcommand)]
|
||||
command: Option<MigrateSubcommands>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subcommand, PartialEq, Eq, Debug)]
|
||||
pub enum MigrateSubcommands {
|
||||
#[clap(about = "Initialize migration directory", display_order = 10)]
|
||||
#[command(about = "Initialize migration directory", display_order = 10)]
|
||||
Init,
|
||||
#[clap(about = "Generate a new, empty migration", display_order = 20)]
|
||||
#[command(about = "Generate a new, empty migration", display_order = 20)]
|
||||
Generate {
|
||||
#[clap(
|
||||
value_parser,
|
||||
required = true,
|
||||
takes_value = true,
|
||||
help = "Name of the new migration"
|
||||
)]
|
||||
#[arg(required = true, help = "Name of the new migration")]
|
||||
migration_name: String,
|
||||
|
||||
#[clap(
|
||||
action,
|
||||
#[arg(
|
||||
long,
|
||||
default_value = "true",
|
||||
help = "Generate migration file based on Utc time",
|
||||
conflicts_with = "local-time",
|
||||
conflicts_with = "local_time",
|
||||
display_order = 1001
|
||||
)]
|
||||
universal_time: bool,
|
||||
|
||||
#[clap(
|
||||
action,
|
||||
#[arg(
|
||||
long,
|
||||
help = "Generate migration file based on Local time",
|
||||
conflicts_with = "universal-time",
|
||||
conflicts_with = "universal_time",
|
||||
display_order = 1002
|
||||
)]
|
||||
local_time: bool,
|
||||
},
|
||||
#[clap(
|
||||
#[command(
|
||||
about = "Drop all tables from the database, then reapply all migrations",
|
||||
display_order = 30
|
||||
)]
|
||||
Fresh,
|
||||
#[clap(
|
||||
#[command(
|
||||
about = "Rollback all applied migrations, then reapply all migrations",
|
||||
display_order = 40
|
||||
)]
|
||||
Refresh,
|
||||
#[clap(about = "Rollback all applied migrations", display_order = 50)]
|
||||
#[command(about = "Rollback all applied migrations", display_order = 50)]
|
||||
Reset,
|
||||
#[clap(about = "Check the status of all migrations", display_order = 60)]
|
||||
#[command(about = "Check the status of all migrations", display_order = 60)]
|
||||
Status,
|
||||
#[clap(about = "Apply pending migrations", display_order = 70)]
|
||||
#[command(about = "Apply pending migrations", display_order = 70)]
|
||||
Up {
|
||||
#[clap(
|
||||
value_parser,
|
||||
short,
|
||||
long,
|
||||
help = "Number of pending migrations to apply"
|
||||
)]
|
||||
#[arg(short, long, help = "Number of pending migrations to apply")]
|
||||
num: Option<u32>,
|
||||
},
|
||||
#[clap(
|
||||
value_parser,
|
||||
about = "Rollback applied migrations",
|
||||
display_order = 80
|
||||
)]
|
||||
#[command(about = "Rollback applied migrations", display_order = 80)]
|
||||
Down {
|
||||
#[clap(
|
||||
value_parser,
|
||||
#[arg(
|
||||
short,
|
||||
long,
|
||||
default_value = "1",
|
||||
@ -175,54 +155,46 @@ pub enum MigrateSubcommands {
|
||||
|
||||
#[derive(Subcommand, PartialEq, Eq, Debug)]
|
||||
pub enum GenerateSubcommands {
|
||||
#[clap(about = "Generate entity")]
|
||||
#[clap(arg_required_else_help = true)]
|
||||
#[clap(group(ArgGroup::new("formats").args(&["compact-format", "expanded-format"])))]
|
||||
#[clap(group(ArgGroup::new("group-tables").args(&["tables", "include-hidden-tables"])))]
|
||||
#[command(about = "Generate entity")]
|
||||
#[command(group(ArgGroup::new("formats").args(&["compact_format", "expanded_format"])))]
|
||||
#[command(group(ArgGroup::new("group-tables").args(&["tables", "include_hidden_tables"])))]
|
||||
Entity {
|
||||
#[clap(action, long, help = "Generate entity file of compact format")]
|
||||
#[arg(long, help = "Generate entity file of compact format")]
|
||||
compact_format: bool,
|
||||
|
||||
#[clap(action, long, help = "Generate entity file of expanded format")]
|
||||
#[arg(long, help = "Generate entity file of expanded format")]
|
||||
expanded_format: bool,
|
||||
|
||||
#[clap(
|
||||
action,
|
||||
#[arg(
|
||||
long,
|
||||
help = "Generate entity file for hidden tables (i.e. table name starts with an underscore)"
|
||||
)]
|
||||
include_hidden_tables: bool,
|
||||
|
||||
#[clap(
|
||||
value_parser,
|
||||
#[arg(
|
||||
short = 't',
|
||||
long,
|
||||
use_value_delimiter = true,
|
||||
takes_value = true,
|
||||
value_delimiter = ',',
|
||||
help = "Generate entity file for specified tables only (comma separated)"
|
||||
)]
|
||||
tables: Vec<String>,
|
||||
|
||||
#[clap(
|
||||
value_parser,
|
||||
#[arg(
|
||||
long,
|
||||
use_value_delimiter = true,
|
||||
takes_value = true,
|
||||
value_delimiter = ',',
|
||||
default_value = "seaql_migrations",
|
||||
help = "Skip generating entity file for specified tables (comma separated)"
|
||||
)]
|
||||
ignore_tables: Vec<String>,
|
||||
|
||||
#[clap(
|
||||
value_parser,
|
||||
#[arg(
|
||||
long,
|
||||
default_value = "1",
|
||||
help = "The maximum amount of connections to use when connecting to the database."
|
||||
)]
|
||||
max_connections: u32,
|
||||
|
||||
#[clap(
|
||||
value_parser,
|
||||
#[arg(
|
||||
short = 'o',
|
||||
long,
|
||||
default_value = "./",
|
||||
@ -230,8 +202,7 @@ pub enum GenerateSubcommands {
|
||||
)]
|
||||
output_dir: String,
|
||||
|
||||
#[clap(
|
||||
value_parser,
|
||||
#[arg(
|
||||
short = 's',
|
||||
long,
|
||||
env = "DATABASE_SCHEMA",
|
||||
@ -242,17 +213,10 @@ pub enum GenerateSubcommands {
|
||||
)]
|
||||
database_schema: String,
|
||||
|
||||
#[clap(
|
||||
value_parser,
|
||||
short = 'u',
|
||||
long,
|
||||
env = "DATABASE_URL",
|
||||
help = "Database URL"
|
||||
)]
|
||||
#[arg(short = 'u', long, env = "DATABASE_URL", help = "Database URL")]
|
||||
database_url: String,
|
||||
|
||||
#[clap(
|
||||
value_parser,
|
||||
#[arg(
|
||||
long,
|
||||
default_value = "none",
|
||||
help = "Automatically derive serde Serialize / Deserialize traits for the entity (none, \
|
||||
@ -260,23 +224,20 @@ pub enum GenerateSubcommands {
|
||||
)]
|
||||
with_serde: String,
|
||||
|
||||
#[clap(
|
||||
action,
|
||||
#[arg(
|
||||
long,
|
||||
help = "Generate a serde field attribute, '#[serde(skip_deserializing)]', for the primary key fields to skip them during deserialization, this flag will be affective only when '--with-serde' is 'both' or 'deserialize'"
|
||||
)]
|
||||
serde_skip_deserializing_primary_key: bool,
|
||||
|
||||
#[clap(
|
||||
action,
|
||||
#[arg(
|
||||
long,
|
||||
default_value = "false",
|
||||
help = "Opt-in to add skip attributes to hidden columns (i.e. when 'with-serde' enabled and column name starts with an underscore)"
|
||||
)]
|
||||
serde_skip_hidden_column: bool,
|
||||
|
||||
#[clap(
|
||||
action,
|
||||
#[arg(
|
||||
long,
|
||||
default_value = "false",
|
||||
long_help = "Automatically derive the Copy trait on generated enums.\n\
|
||||
@ -286,17 +247,15 @@ pub enum GenerateSubcommands {
|
||||
)]
|
||||
with_copy_enums: bool,
|
||||
|
||||
#[clap(
|
||||
arg_enum,
|
||||
value_parser,
|
||||
#[arg(
|
||||
long,
|
||||
default_value = "chrono",
|
||||
default_value_t,
|
||||
value_enum,
|
||||
help = "The datetime crate to use for generating entities."
|
||||
)]
|
||||
date_time_crate: DateTimeCrate,
|
||||
|
||||
#[clap(
|
||||
action,
|
||||
#[arg(
|
||||
long,
|
||||
short = 'l',
|
||||
default_value = "false",
|
||||
@ -304,26 +263,21 @@ pub enum GenerateSubcommands {
|
||||
)]
|
||||
lib: bool,
|
||||
|
||||
#[clap(
|
||||
value_parser,
|
||||
#[arg(
|
||||
long,
|
||||
use_value_delimiter = true,
|
||||
takes_value = true,
|
||||
value_delimiter = ',',
|
||||
help = "Add extra derive macros to generated model struct (comma separated), e.g. `--model-extra-derives 'ts_rs::Ts','CustomDerive'`"
|
||||
)]
|
||||
model_extra_derives: Vec<String>,
|
||||
|
||||
#[clap(
|
||||
value_parser,
|
||||
#[arg(
|
||||
long,
|
||||
use_value_delimiter = true,
|
||||
takes_value = true,
|
||||
value_delimiter = ',',
|
||||
help = r#"Add extra attributes to generated model struct, no need for `#[]` (comma separated), e.g. `--model-extra-attributes 'serde(rename_all = "camelCase")','ts(export)'`"#
|
||||
)]
|
||||
model_extra_attributes: Vec<String>,
|
||||
|
||||
#[clap(
|
||||
action,
|
||||
#[arg(
|
||||
long,
|
||||
default_value = "false",
|
||||
long_help = "Generate helper Enumerations that are used by Seaography."
|
||||
@ -332,8 +286,9 @@ pub enum GenerateSubcommands {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(ArgEnum, Copy, Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum, Default)]
|
||||
pub enum DateTimeCrate {
|
||||
#[default]
|
||||
Chrono,
|
||||
Time,
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ impl From<DateTimeCrate> for CodegenDateTimeCrate {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use clap::StructOpt;
|
||||
use clap::Parser;
|
||||
|
||||
use super::*;
|
||||
use crate::{Cli, Commands};
|
||||
|
@ -21,7 +21,7 @@ path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
async-trait = { version = "0.1", default-features = false }
|
||||
clap = { version = "3.2", default-features = false, features = ["std", "env", "derive"], optional = true }
|
||||
clap = { version = "4.3", features = ["env", "derive"], optional = true }
|
||||
dotenvy = { version = "0.15", default-features = false, optional = true }
|
||||
sea-orm = { version = "0.12.0", path = "../", default-features = false, features = ["macros"] }
|
||||
sea-orm-cli = { version = "0.12.0", path = "../sea-orm-cli", default-features = false, optional = true }
|
||||
|
@ -87,13 +87,12 @@ where
|
||||
}
|
||||
|
||||
#[derive(Parser)]
|
||||
#[clap(version)]
|
||||
#[command(version)]
|
||||
pub struct Cli {
|
||||
#[clap(action, short = 'v', long, global = true, help = "Show debug messages")]
|
||||
#[arg(short = 'v', long, global = true, help = "Show debug messages")]
|
||||
verbose: bool,
|
||||
|
||||
#[clap(
|
||||
value_parser,
|
||||
#[arg(
|
||||
global = true,
|
||||
short = 's',
|
||||
long,
|
||||
@ -104,8 +103,7 @@ pub struct Cli {
|
||||
)]
|
||||
database_schema: Option<String>,
|
||||
|
||||
#[clap(
|
||||
value_parser,
|
||||
#[arg(
|
||||
global = true,
|
||||
short = 'u',
|
||||
long,
|
||||
@ -114,7 +112,7 @@ pub struct Cli {
|
||||
)]
|
||||
database_url: Option<String>,
|
||||
|
||||
#[clap(subcommand)]
|
||||
#[command(subcommand)]
|
||||
command: Option<MigrateSubcommands>,
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user