use std::path::PathBuf;
use clap::{
ArgAction, ValueHint,
builder::{IntoResettable, OsStr, Resettable},
};
#[derive(Clone)]
#[derive(Debug)]
#[derive(clap::Parser)]
#[command(version, about, long_about)]
pub struct Args {
#[command(subcommand)]
pub cmd: Option<SubCmd>,
#[arg(
short,
long,
default_value("results"),
verbatim_doc_comment,
value_hint(ValueHint::DirPath)
)]
pub output_dir: PathBuf,
#[arg(short, long)]
pub all_browsers: bool,
#[arg(long, default_value(","), value_hint(ValueHint::Other))]
pub sep: String,
#[arg(long, id("domain"), value_hint(ValueHint::Url))]
pub host: Option<String>,
#[arg(long, default_value(Format::Csv))]
pub out_format: Format,
}
#[derive(Clone, Copy)]
#[derive(Debug)]
#[derive(Default)]
pub enum Format {
#[default]
Csv,
Json,
JsonLines,
}
impl clap::ValueEnum for Format {
fn value_variants<'a>() -> &'a [Self] {
&[Self::Csv, Self::Json, Self::JsonLines]
}
fn to_possible_value<'a>(&self) -> ::std::option::Option<clap::builder::PossibleValue> {
match self {
Self::Csv => Some(clap::builder::PossibleValue::new("csv")),
Self::Json => Some(clap::builder::PossibleValue::new("json")),
Self::JsonLines => Some(clap::builder::PossibleValue::new("jsonl")),
}
}
}
impl IntoResettable<OsStr> for Format {
fn into_resettable(self) -> clap::builder::Resettable<OsStr> {
Resettable::Value(match self {
Format::Csv => "csv".into(),
Format::Json => "json".into(),
Format::JsonLines => "jsonl".into(),
})
}
}
#[derive(Clone)]
#[derive(Debug)]
#[derive(clap::Subcommand)]
pub enum SubCmd {
Chromium(ChromiumArgs),
Firefox(FirefoxArgs),
BinaryCookies(BinaryCookiesArgs),
#[cfg(target_os = "macos")]
Safari(SafariArgs),
Completions {
shell: clap_complete_command::Shell,
},
}
#[derive(Clone, Copy)]
#[derive(Debug)]
#[derive(Default)]
#[derive(PartialEq, Eq, PartialOrd, Ord)]
#[derive(clap::ValueEnum)]
#[derive(Hash)]
#[derive(strum::EnumIter)]
pub enum Value {
#[default]
Cookie,
Login,
}
#[derive(Clone)]
#[derive(Debug)]
#[derive(PartialEq, Eq, PartialOrd, Ord)]
#[derive(clap::Args)]
pub struct SafariArgs {
#[arg(short, long, value_delimiter(','), action(ArgAction::Append))]
pub values: Vec<Value>,
#[arg(long, value_hint(ValueHint::FilePath))]
pub cookies_path: Option<PathBuf>,
}
#[derive(Clone)]
#[derive(Debug)]
#[derive(PartialEq, Eq, PartialOrd, Ord)]
#[derive(clap::Args)]
pub struct ChromiumArgs {
#[arg(short, long)]
pub name: ChromiumName,
#[arg(long, id("DIR"), verbatim_doc_comment, value_hint(ValueHint::DirPath))]
#[cfg_attr(target_os = "linux", doc = "[example value: ~/.config/google-chrome]")]
#[cfg_attr(
target_os = "macos",
doc = "[example value: ~/Library/Application Support/Google/Chrome]"
)]
#[cfg_attr(
target_os = "windows",
doc = r"[example value: ~\AppData\Local\Google\Chrome\User Data]"
)]
pub user_data_dir: Option<PathBuf>,
#[arg(short, long, value_delimiter(','), action(ArgAction::Append))]
pub values: Vec<Value>,
}
#[derive(Clone, Copy)]
#[derive(Debug)]
#[derive(PartialEq, Eq, PartialOrd, Ord)]
#[derive(clap::ValueEnum)]
#[clap(rename_all = "PascalCase")]
#[derive(strum::EnumIter)]
pub enum ChromiumName {
Chrome,
Edge,
Chromium,
Brave,
Vivaldi,
Yandex,
Opera,
#[cfg(not(target_os = "linux"))]
Arc,
#[cfg(not(target_os = "linux"))]
OperaGX,
#[cfg(not(target_os = "linux"))]
CocCoc,
}
#[derive(Clone)]
#[derive(Debug)]
#[derive(PartialEq, Eq, PartialOrd, Ord)]
#[derive(clap::Args)]
pub struct FirefoxArgs {
#[arg(short, long)]
pub name: FirefoxName,
#[arg(long, id("DIR"), value_hint(ValueHint::DirPath))]
#[cfg_attr(target_os = "linux", doc = "[example value: ~/.mozilla/firefox]")]
#[cfg_attr(
target_os = "macos",
doc = "[example value: ~/Library/Application Support/Firefox]"
)]
#[cfg_attr(
target_os = "windows",
doc = r"[example value: ~\AppData\Roaming\Mozilla\Firefox]"
)]
pub base: Option<PathBuf>,
#[arg(short('P'), id("profile"), value_hint(ValueHint::Other))]
pub profile: Option<String>,
#[arg(long("profile"), id("path"))]
#[arg(verbatim_doc_comment)]
pub profile_path: Option<PathBuf>,
#[arg(short, long, value_delimiter(','), action(ArgAction::Append))]
pub values: Vec<Value>,
}
#[derive(Clone, Copy)]
#[derive(Debug)]
#[derive(PartialEq, Eq, PartialOrd, Ord)]
#[derive(clap::ValueEnum)]
#[clap(rename_all = "PascalCase")]
#[derive(strum::EnumIter)]
pub enum FirefoxName {
Firefox,
Librewolf,
Floorp,
Zen,
}
#[derive(Clone)]
#[derive(Debug)]
#[derive(PartialEq, Eq, PartialOrd, Ord)]
#[derive(clap::Args)]
pub struct BinaryCookiesArgs {
#[arg(short('i'), long, value_hint(ValueHint::FilePath))]
pub cookies_path: PathBuf,
#[arg(short, long, value_hint(ValueHint::FilePath))]
pub out_file: Option<PathBuf>,
}