use clap::{Parser, Subcommand};
use std::str::FromStr;
#[derive(Parser, Debug)]
#[command(name = "ffcv")]
#[command(about = "View Firefox configuration from the command line")]
#[command(
long_about = "ffcv lets you view Firefox configuration (prefs.js) as JSON \
from the command line. Use subcommands to list profiles or inspect configuration."
)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
Profile {
#[arg(short = 'd', long = "profiles-dir")]
profiles_dir: Option<std::path::PathBuf>,
},
Install {
#[arg(short = 'd', long = "profiles-dir")]
profiles_dir: Option<std::path::PathBuf>,
#[arg(long)]
all: bool,
},
Config {
#[arg(short = 'p', long, default_value = "default")]
profile: String,
#[arg(long, conflicts_with = "profile")]
stdin: bool,
#[arg(short = 'd', long = "profiles-dir")]
profiles_dir: Option<std::path::PathBuf>,
#[arg(long = "install-dir")]
install_dir: Option<std::path::PathBuf>,
#[arg(long = "max-file-size", default_value = "104857600")]
max_file_size: usize,
#[arg(long, conflicts_with = "get")]
query: Vec<String>,
#[arg(long, conflicts_with = "query")]
get: Option<String>,
#[arg(
long = "output-type",
default_value = "json-object",
conflicts_with = "get"
)]
output_type: OutputType,
#[arg(long = "show-only-modified", conflicts_with = "all")]
show_only_modified: bool,
#[arg(long)]
all: bool,
#[arg(long = "unexplained-only", hide = true)]
unexplained_only: bool,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum OutputType {
JsonObject,
JsonArray,
}
impl FromStr for OutputType {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"json-object" => Ok(OutputType::JsonObject),
"json-array" => Ok(OutputType::JsonArray),
_ => Err(format!(
"Invalid output type: '{}'. Valid values: json-object, json-array",
s
)),
}
}
}
impl std::fmt::Display for OutputType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
OutputType::JsonObject => write!(f, "json-object"),
OutputType::JsonArray => write!(f, "json-array"),
}
}
}