use clap::Parser;
#[derive(Parser, Debug)]
#[command(version, about)]
pub struct Flags {
#[arg(long)]
pub config: Option<String>,
#[arg(long)]
pub username: Option<String>,
#[arg(long)]
pub apikey: Option<String>,
#[arg(short, long, conflicts_with_all = ["random", "toplist", "hot", "id"])]
pub collection: Option<String>,
#[arg(short, long, conflicts_with_all = ["collection", "toplist", "hot", "id"])]
pub random: Option<String>,
#[arg(short, long, conflicts_with_all = ["collection", "hot", "id", "random"])]
pub toplist: bool,
#[arg(long)]
pub range: Option<String>,
#[arg(long)]
pub hot: bool,
#[arg(short, long, conflicts_with_all = ["collection", "toplist", "hot", "random"])]
pub id: Option<String>,
#[arg(short, long, value_parser = check3bit)]
pub purity: Option<String>,
#[arg(long, alias = "cat", value_parser = check3bit)]
pub categories: Option<String>,
#[arg(long, value_parser = clap::value_parser!(i64).range(1..11))]
pub pages: Option<i64>,
#[arg(short, long)]
pub expiry: Option<i64>,
#[arg(short, long)]
pub script: Option<String>,
#[arg(short, long = "file")]
pub file: bool,
#[arg(short, long = "url")]
pub url: bool,
#[arg(short, long)]
pub last: bool,
#[arg(short, long)]
pub delete: bool,
}
pub fn cli_args() -> Flags {
let flags = Flags::parse();
return flags;
}
pub fn check3bit(bits: &str) -> Result<String, String> {
if bits.len() == 3 && bits.chars().all(|c| c == '0' || c == '1') {
return Ok(bits.to_string());
} else {
return Err(format!("should be bits e.g. 110"));
}
}