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
use clap::{Parser, ValueEnum};

#[derive(ValueEnum, Clone, Debug)]
pub enum Part {
    Scheme,
    Host,
    Port,
    User,
    Password,
    /// Often corresponds to the database name
    Path,
}

#[derive(Parser, Debug)]
#[command(
    about,
    author,
    version,
    propagate_version = true,
    next_line_help = false,
    disable_help_subcommand = true,
    after_long_help = "This tool can be used to extract parts of a connection string. It is useful for extracting the database name from a connection string, for example."
)]
pub struct Cli {
    /// The connection string to parse
    pub url: String,

    /// The part of the connection string to extract
    #[arg(short, long, required = true)]
    pub part: Part,

    /// Fail silently even if the part is not found
    #[arg(short, long, default_value = "false")]
    pub fail_silently: bool,
}