use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema, Default)]
#[serde(rename_all = "lowercase")]
pub enum ReprexFormatter {
#[default]
Auto,
Air,
Arity,
}
impl fmt::Display for ReprexFormatter {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Auto => "auto",
Self::Air => "air",
Self::Arity => "arity",
})
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FormatterBackend {
Air,
Arity,
}
impl FormatterBackend {
pub const fn display_name(self) -> &'static str {
match self {
Self::Air => "Air",
Self::Arity => "Arity",
}
}
pub const fn command(self) -> &'static str {
match self {
Self::Air => "air",
Self::Arity => "arity",
}
}
pub const fn install_url(self) -> &'static str {
match self {
Self::Air => "https://github.com/posit-dev/air",
Self::Arity => "https://github.com/jolars/arity",
}
}
pub const fn minimum_version(self) -> &'static str {
match self {
Self::Air => "0.9.0",
Self::Arity => "0.18.0",
}
}
}
impl fmt::Display for FormatterBackend {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.command())
}
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(default)]
pub struct ReprexConfig {
pub comment: String,
pub formatter: ReprexFormatter,
}
impl Default for ReprexConfig {
fn default() -> Self {
ReprexConfig {
comment: "#> ".to_string(),
formatter: ReprexFormatter::Auto,
}
}
}