aboutsummaryrefslogtreecommitdiff
path: root/src/cli.rs
blob: 9466359aad3c5b653a19f2a7c1fcd9267e82ccad (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
use clap::Parser;
use std::path::PathBuf;

#[derive(Parser, Debug)]
#[command(
    name = "hoardom",
    version = "0.0.1",
    about = "Domain hoarding made less painful"
)] // static version infos ???? whoops
#[command(disable_help_flag = true, disable_version_flag = true)]
pub struct Args {
    /// ffs why were a million comments added at some point !?!? basically all of these are self explanatory. removed dumb ass redundant ones.

    #[arg(value_name = "DOMAIN")]
    pub domains: Vec<String>,
    #[arg(long = "cli", default_value_t = false)]
    pub cli_mode: bool,
    #[arg(long = "tui", default_value_t = false)]
    pub tui_mode: bool,
    #[arg(short = 'e', long = "environement")]
    pub env_path: Option<PathBuf>,
    #[arg(short = 'a', long = "all", default_value_t = false)]
    pub show_all: bool,
    #[arg(short = 'c', long = "csv")]
    pub csv: Option<Option<PathBuf>>,
    #[arg(short = 'l', long = "list")]
    pub tld_list: Option<String>,
    #[arg(short = 'i', long = "import-list", alias = "import-filter")]
    pub import_list: Option<PathBuf>,
    #[arg(short = 't', long = "top", value_delimiter = ',')]
    pub top_tlds: Option<Vec<String>>,
    #[arg(short = 'o', long = "onlytop", value_delimiter = ',')]
    pub only_top: Option<Vec<String>>,
    #[arg(short = 's', long = "suggestions")]
    pub suggestions: Option<usize>,
    #[arg(short = 'j', long = "jobs")]
    pub jobs: Option<u8>,
    #[arg(short = 'D', long = "delay")]
    pub delay: Option<f64>,
    #[arg(short = 'R', long = "retry")]
    pub retry: Option<u32>,
    #[arg(short = 'V', long = "verbose", default_value_t = false)]
    pub verbose: bool,
    /// search for names/domains in a text file line by line.
    #[arg(short = 'A', long = "autosearch")]
    pub autosearch: Option<PathBuf>,
    /// Use a monochrome color scheme
    #[arg(short = 'C', long = "no-color", default_value_t = false)]
    pub no_color: bool,
    /// Do not use unicode only plain ASCII
    #[arg(short = 'U', long = "no-unicode", default_value_t = false)]
    pub no_unicode: bool,
    #[arg(short = 'M', long = "no-mouse", default_value_t = false)]
    pub no_mouse: bool,
    #[arg(short = 'r', long = "refresh-cache", default_value_t = false)]
    pub refresh_cache: bool,
    #[arg(short = 'h', long = "help", default_value_t = false)]
    pub help: bool,
    #[arg(short = 'H', long = "fullhelp", default_value_t = false)]
    pub fullhelp: bool,
}

impl Args {
    pub fn is_tui(&self) -> bool {
        self.tui_mode
    }

    pub fn effective_list(&self) -> String {
        self.tld_list
            .clone()
            .map(|s| s.to_lowercase())
            .unwrap_or_else(|| crate::tlds::default_list_name().to_string())
    }

    pub fn effective_suggestions(&self) -> usize {
        self.suggestions.unwrap_or(0)
    }

    pub fn effective_retry(&self) -> u32 {
        self.retry.unwrap_or(1)
    }

    pub fn effective_delay(&self) -> f64 {
        self.delay.unwrap_or(0.0)
    }

    pub fn effective_jobs(&self) -> u8 {
        self.jobs.unwrap_or(1).max(1)
    }
}

pub fn print_help() {
    println!(
        "hoardom {} - Domain hoarding made less painful
Mode :
--cli                            Default none interactive mode
--tui                            Easy to use Terminal based Graphical user interface

Basics :
-a --all                         Show all in list even when unavailable
-H --fullhelp                    Show full help

Example usage :
hoardom --tui                    Launch Terminal UI.
hoardom idea.com                 See if idea.com is available
hoardom -a idea1 idea2           See Table of available domains starting with that


",
        env!("CARGO_PKG_VERSION")
    );
}

pub fn print_fullhelp() {
    println!(
        "hoardom {} - they are inside your walls! 
        
## if you see this send a fax to +41 43 543 04 47 that mentions hoardom to know your fate ##

Mode :
--cli                            Default none interactive mode
--tui                            Easy to use Terminal based Graphical user interface

Basics :
-a --all                         Show all in list even when unavailable
-c --csv=PATH                    Out in CSV, Path is optional
-l --list=LIST                   Built in TLD Lists are : {}

Advanced :
-e --environement=PATH           Define where .hoardom folder should be
                                 Defaults to /home/USER/.hoardom/
                                 Stores settings, imported lists, favs, cache etc.
-i --import-list=PATH            Import a custom toml list for this session
-t --top=TLD,TLD                 Set certain TLDs to show up as first result
                                 for when you need a domain in your country or for searching
                                 a specific one.
                                 (Unless changed after launch in TUI mode)
-o --onlytop=TLD,TLD             Only search these TLDs
-s --suggestions=NUMBER          How many suggestions to look up and try to show from list
                                 Number of available alternativ domains to try and find when
                                 Searching for full domain name directly.
                                 Defaults to 0 (aka disabled)

Various :
-j --jobs=NUMBER                 Number of concurrent lookup requests
                                 How many TLDs to look up at the same time (default: 32)
-D --delay=DELAY                 Set the global delay in Seconds between lookup requests
-R --retry=NUMBER                Retry NUMBER amount of times if domain lookup errors out
-V --verbose                     Verbose output for debugging
-A --autosearch=FILE             Search for names/domains in text file one domain per new line
-C --no-color                    Use a monochrome color scheme
-U --no-unicode                  Do not use unicode only plain ASCII
-M --no-mouse                    Disable the mouse integration for TUI
-r --refresh-cache               Force refresh the RDAP bootstrap cache

Help :
-h --help                        Basic Help
-H --fullhelp                    You just did this",
        env!("CARGO_PKG_VERSION"),
        crate::tlds::list_names().join(", ")
    );
}