Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -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()
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use strum_macros::{Display, EnumString};

pub mod cli;
pub mod error;
pub mod mermaid_generator;
pub mod plantuml_generator;
Expand Down
60 changes: 2 additions & 58 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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"),
Expand Down