1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! CLI Option parsing

use std::path::PathBuf;

use clap::{Args, Parser};
use serde::{Deserialize, Serialize};

#[derive(Debug, Parser, Clone, Serialize, Deserialize)]
#[command(author, version, about, long_about = None)]
/// `DBViz` a tool for generating database diagrams.
pub(crate) struct Cli {
    #[command(flatten)]
    /// Postgres connection options
    pub(crate) pg_opts: Pg,

    #[arg(short, long)]
    /// Tables to include in the current diagram.
    pub(crate) include_tables: Option<Vec<String>>,

    #[arg(short, long)]
    /// Tables to completely exclude in the current diagram.
    pub(crate) exclude_tables: Option<Vec<String>>,

    /// Title to give the Diagram
    #[arg(short, long)]
    pub(crate) title: Option<String>,

    /// How wide is the Column Description before we wrap it?
    #[arg(long)]
    pub(crate) column_description_wrap: Option<usize>,

    /// How wide is the Table Description before we wrap it?
    #[arg(long)]
    pub(crate) table_description_wrap: Option<usize>,

    /// Do we include comments in the diagram?
    #[arg(long)]
    pub(crate) comments: bool,

    /// Input file
    pub(crate) template: Option<PathBuf>,

    /// Output file
    pub(crate) output: Option<PathBuf>,
}

#[derive(Debug, Args, Clone, Serialize, Deserialize)]
/// Postgres connection options
pub(crate) struct Pg {
    #[arg(short, long, default_value = "localhost")]
    /// Hostname to connect to
    pub(crate) hostname: String,

    #[arg(short, long, default_value = "postgres")]
    /// Username to use when connecting
    pub(crate) username: String,

    #[arg(short, long, default_value = "postgres")]
    /// Password to use when connecting
    pub(crate) password: String,

    #[arg(short, long, default_value = "postgres")]
    /// Database name to connect to
    pub(crate) database: String,

    #[arg(short, long, default_value = "public")]
    /// Schema name to use
    pub(crate) schema: String,
}

/// Load CLI Options.
pub(crate) fn load() -> Cli {
    Cli::parse()
}