diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..ad0f4fb --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,61 @@ +use clap::{Arg, ArgAction, ArgMatches, Command}; + +pub fn parse() -> ArgMatches { + Command::new("sqlant") + .about( + "Generate Entity Relationship diagram textual description from SQL connection string", + ) + .version(env!("CARGO_PKG_VERSION")) + .arg(Arg::new("connection_string").required(true)) + .arg( + Arg::new("inline-puml-lib") + .long("inline-puml-lib") + .help("Inline PlantUML lib into diagram code") + .action(ArgAction::SetTrue), + ) + .arg( + Arg::new("legend") + .long("legend") + .help("Add legend to diagram (supported only for PlantUML)") + .action(ArgAction::SetTrue), + ) + .arg( + Arg::new("not_null") + .short('n') + .long("nn") + .help("Add NOT_NULL(NN) marks (for PlantUML always true)") + .action(ArgAction::SetTrue), + ) + .arg( + Arg::new("enums") + .short('e') + .long("en") + .help("Draw enum types") + .action(ArgAction::SetTrue), + ) + .arg( + Arg::new("schema") + .short('s') + .long("schema") + .help("Schema name") + .action(ArgAction::Set) + .default_value("public"), + ) + .arg( + Arg::new("output") + .short('o') + .value_parser(["plantuml", "mermaid"]) + .long("output") + .help("Generate output in mermaid format") + .action(ArgAction::Set) + .default_value("plantuml"), + ) + .arg( + Arg::new("conceptual") + .long("conceptual") + .help("Create conceptual ER diagram") + .action(ArgAction::SetTrue) + .default_value("false"), + ) + .get_matches() +} diff --git a/src/lib.rs b/src/lib.rs index 06f2ec4..35466c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ use strum_macros::{Display, EnumString}; +pub mod cli; pub mod error; pub mod mermaid_generator; pub mod plantuml_generator; diff --git a/src/main.rs b/src/main.rs index 796ffb9..1ce6216 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use clap::{Arg, ArgAction, ArgMatches, Command}; +use clap::ArgMatches; use sqlant::{get_generator, lookup_parser, GeneratorConfigOptions, GeneratorType}; fn get_arg(args: &ArgMatches, arg_name: &str) -> String { @@ -9,63 +9,7 @@ fn get_arg(args: &ArgMatches, arg_name: &str) -> String { #[tokio::main] async fn main() { - let args = Command::new("sqlant") - .about( - "Generate Entity Relationship diagram textual description from SQL connection string", - ) - .version(env!("CARGO_PKG_VERSION")) - .arg(Arg::new("connection_string").required(true)) - .arg( - Arg::new("inline-puml-lib") - .long("inline-puml-lib") - .help("Inline PlantUML lib into diagram code") - .action(ArgAction::SetTrue), - ) - .arg( - Arg::new("legend") - .long("legend") - .help("Add legend to diagram (supported only for PlantUML)") - .action(ArgAction::SetTrue), - ) - .arg( - Arg::new("not_null") - .short('n') - .long("nn") - .help("Add NOT_NULL(NN) marks (for PlantUML always true)") - .action(ArgAction::SetTrue), - ) - .arg( - Arg::new("enums") - .short('e') - .long("en") - .help("Draw enum types") - .action(ArgAction::SetTrue), - ) - .arg( - Arg::new("schema") - .short('s') - .long("schema") - .help("Schema name") - .action(ArgAction::Set) - .default_value("public"), - ) - .arg( - Arg::new("output") - .short('o') - .value_parser(["plantuml", "mermaid"]) - .long("output") - .help("Generate output in mermaid format") - .action(ArgAction::Set) - .default_value("plantuml"), - ) - .arg( - Arg::new("conceptual") - .long("conceptual") - .help("Create conceptual ER diagram") - .action(ArgAction::SetTrue) - .default_value("false"), - ) - .get_matches(); + let args = sqlant::cli::parse(); let mut s = lookup_parser( &get_arg(&args, "connection_string"),