Skip to content

Commit

Permalink
Export main() of sea-orm-cli (#1889) (#2034)
Browse files Browse the repository at this point in the history
* Export main() of sea-orm-cli (#1889)

* Fix compile error: require "codegen" feature for main()
  • Loading branch information
Expurple authored Jan 12, 2024
1 parent a73f699 commit e3c94a7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 58 deletions.
30 changes: 1 addition & 29 deletions sea-orm-cli/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,4 @@
use clap::Parser;
use dotenvy::dotenv;
use sea_orm_cli::{handle_error, run_generate_command, run_migrate_command, Cli, Commands};

#[async_std::main]
async fn main() {
dotenv().ok();

let cli = Cli::parse();
let verbose = cli.verbose;

match cli.command {
Commands::Generate { command } => {
run_generate_command(command, verbose)
.await
.unwrap_or_else(handle_error);
}
Commands::Migrate {
migration_dir,
database_schema,
database_url,
command,
} => run_migrate_command(
command,
&migration_dir,
database_schema,
database_url,
verbose,
)
.unwrap_or_else(handle_error),
}
sea_orm_cli::main().await
}
30 changes: 1 addition & 29 deletions sea-orm-cli/src/bin/sea.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,6 @@
//! COPY FROM bin/main.rs
use clap::Parser;
use dotenvy::dotenv;
use sea_orm_cli::{handle_error, run_generate_command, run_migrate_command, Cli, Commands};

#[async_std::main]
async fn main() {
dotenv().ok();

let cli = Cli::parse();
let verbose = cli.verbose;

match cli.command {
Commands::Generate { command } => {
run_generate_command(command, verbose)
.await
.unwrap_or_else(handle_error);
}
Commands::Migrate {
migration_dir,
database_schema,
database_url,
command,
} => run_migrate_command(
command,
&migration_dir,
database_schema,
database_url,
verbose,
)
.unwrap_or_else(handle_error),
}
sea_orm_cli::main().await
}
36 changes: 36 additions & 0 deletions sea-orm-cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use clap::{ArgGroup, Parser, Subcommand, ValueEnum};
#[cfg(feature = "codegen")]
use dotenvy::dotenv;

#[cfg(feature = "codegen")]
use crate::{handle_error, run_generate_command, run_migrate_command};

#[derive(Parser, Debug)]
#[command(
Expand Down Expand Up @@ -309,3 +314,34 @@ pub enum DateTimeCrate {
Chrono,
Time,
}

/// Use this to build a local, version-controlled `sea-orm-cli` in dependent projects
/// (see [example use case](https://github.com/SeaQL/sea-orm/discussions/1889)).
#[cfg(feature = "codegen")]
pub async fn main() {
dotenv().ok();

let cli = Cli::parse();
let verbose = cli.verbose;

match cli.command {
Commands::Generate { command } => {
run_generate_command(command, verbose)
.await
.unwrap_or_else(handle_error);
}
Commands::Migrate {
migration_dir,
database_schema,
database_url,
command,
} => run_migrate_command(
command,
&migration_dir,
database_schema,
database_url,
verbose,
)
.unwrap_or_else(handle_error),
}
}

0 comments on commit e3c94a7

Please sign in to comment.