tidy_browser/
args.rs

1use std::path::PathBuf;
2
3use clap::ArgAction;
4
5#[derive(Clone)]
6#[derive(Debug)]
7#[derive(PartialEq, Eq, PartialOrd, Ord)]
8#[derive(clap::Parser)]
9pub struct Args {
10    #[command(subcommand)]
11    pub core: Option<Core>,
12
13    #[arg(short, long)]
14    pub output_dir: Option<PathBuf>,
15
16    #[arg(short, long)]
17    /// All browsers data
18    pub all_browsers: bool,
19
20    #[arg(long, default_value(","))]
21    /// Csv separator
22    pub sep: String,
23
24    #[arg(long)]
25    /// Filter by host/domain
26    pub host: Option<String>,
27}
28
29#[derive(Clone)]
30#[derive(Debug)]
31#[derive(PartialEq, Eq, PartialOrd, Ord)]
32#[derive(clap::Subcommand)]
33pub enum Core {
34    /// Chromium based
35    Chromium(ChromiumArgs),
36    /// Firefox based
37    Firefox(FirefoxArgs),
38    #[cfg(target_os = "macos")]
39    /// Safari
40    Safari(SafariArgs),
41}
42
43#[derive(Clone, Copy)]
44#[derive(Debug)]
45#[derive(Default)]
46#[derive(PartialEq, Eq, PartialOrd, Ord)]
47#[derive(clap::ValueEnum)]
48#[derive(Hash)]
49#[derive(strum::EnumIter)]
50pub enum Value {
51    #[default]
52    Cookie,
53    Login,
54}
55
56#[derive(Clone)]
57#[derive(Debug)]
58#[derive(PartialEq, Eq, PartialOrd, Ord)]
59#[derive(clap::Args)]
60pub struct SafariArgs {
61    #[arg(
62        short,
63        long,
64        value_delimiter(','),
65        action(ArgAction::Append),
66        required(true)
67    )]
68    /// Only support cookie
69    pub values: Vec<Value>,
70
71    #[arg(long)]
72    pub cookies_path: Option<PathBuf>,
73}
74
75#[derive(Clone)]
76#[derive(Debug)]
77#[derive(PartialEq, Eq, PartialOrd, Ord)]
78#[derive(clap::Args)]
79pub struct ChromiumArgs {
80    #[arg(short, long)]
81    pub name: ChromiumName,
82
83    #[arg(long, id("DIR"))]
84    #[arg(verbatim_doc_comment)]
85    /// When browser is started with `--user-data-dir=DIR   Specify the directory that user data (your "profile") is kept in.`
86    #[cfg_attr(target_os = "linux", doc = "[default value: ~/.config/google-chrome]")]
87    #[cfg_attr(
88        target_os = "macos",
89        doc = "[default value: ~/Library/Application Support/Google/Chrome]"
90    )]
91    #[cfg_attr(
92        target_os = "windows",
93        doc = r"[default value: ~\AppData\Local\Google\Chrome\User Data]"
94    )]
95    pub user_data_dir: Option<PathBuf>,
96
97    #[arg(short, long, value_delimiter(','))]
98    pub values: Vec<Value>,
99}
100
101#[derive(Clone, Copy)]
102#[derive(Debug)]
103#[derive(PartialEq, Eq, PartialOrd, Ord)]
104#[derive(clap::ValueEnum)]
105#[clap(rename_all = "PascalCase")]
106#[derive(strum::EnumIter)]
107pub enum ChromiumName {
108    Chrome,
109    Edge,
110    Chromium,
111    Brave,
112    Vivaldi,
113    Yandex,
114    Opera,
115    #[cfg(not(target_os = "linux"))]
116    Arc,
117    #[cfg(not(target_os = "linux"))]
118    OperaGX,
119    #[cfg(not(target_os = "linux"))]
120    CocCoc,
121}
122
123#[derive(Clone)]
124#[derive(Debug)]
125#[derive(PartialEq, Eq, PartialOrd, Ord)]
126#[derive(clap::Args)]
127pub struct FirefoxArgs {
128    #[arg(short, long)]
129    pub name: FirefoxName,
130
131    #[arg(long, id("DIR"))]
132    /// Browser data dir.
133    #[cfg_attr(target_os = "linux", doc = "[possible value: ~/.mozilla/firefox]")]
134    #[cfg_attr(
135        target_os = "macos",
136        doc = "[possible value: ~/Library/Application Support/Firefox]"
137    )]
138    #[cfg_attr(
139        target_os = "windows",
140        doc = r"[possible value: ~\AppData\Roaming\Mozilla\Firefox]"
141    )]
142    pub base: Option<PathBuf>,
143
144    #[arg(short('P'), id("profile"))]
145    /// When browser is started with `-P <profile>       Start with <profile>.`
146    pub profile: Option<String>,
147
148    #[arg(long("profile"), id("path"))]
149    #[arg(verbatim_doc_comment)]
150    /// When browser is started with `--profile <path>   Start with profile at <path>.`
151    /// When the arg is used, other args (such as `--base`, `-P`) are ignore.
152    pub profile_path: Option<PathBuf>,
153
154    #[arg(short, long, value_delimiter(','))]
155    /// Only support cookie
156    pub values: Vec<Value>,
157}
158
159#[derive(Clone, Copy)]
160#[derive(Debug)]
161#[derive(PartialEq, Eq, PartialOrd, Ord)]
162#[derive(clap::ValueEnum)]
163#[clap(rename_all = "PascalCase")]
164#[derive(strum::EnumIter)]
165pub enum FirefoxName {
166    Firefox,
167    Librewolf,
168    Floorp,
169}