use std::fmt;
use std::path::PathBuf;
use serde::Serialize;
use super::{ConfigSource, OwnershipState};
#[derive(Debug)]
pub struct ClientError(String);
impl ClientError {
pub(super) fn message(message: impl Into<String>) -> Self {
Self(crate::login_url::redact_secrets(&message.into()))
}
}
impl fmt::Display for ClientError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl std::error::Error for ClientError {}
impl From<std::io::Error> for ClientError {
fn from(error: std::io::Error) -> Self {
Self::message(error.to_string())
}
}
impl From<serde_json::Error> for ClientError {
fn from(error: serde_json::Error) -> Self {
Self::message(error.to_string())
}
}
#[derive(Clone, Debug, Serialize)]
pub struct ClientStatus {
pub client: String,
pub installed: bool,
pub configured: bool,
pub config_path: PathBuf,
pub dialect: &'static str,
pub base_url: Option<String>,
pub token_env: Option<&'static str>,
pub token_env_set: bool,
pub ownership_state: OwnershipState,
#[serde(skip_serializing_if = "Option::is_none")]
pub effective_source: Option<ConfigSource>,
pub conflicts: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub unreadable: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub unsupported: Option<&'static str>,
}
#[derive(Debug)]
pub struct SetupResult {
pub path: PathBuf,
pub backup: Option<PathBuf>,
pub changed: bool,
}