use std::fmt::{Display, Formatter};
use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum Shell {
Bash,
Zsh,
Fish,
Elvish,
Powershell,
Other(String),
}
impl Display for Shell {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Bash => write!(f, "bash"),
Self::Zsh => write!(f, "zsh"),
Self::Fish => write!(f, "fish"),
Self::Elvish => write!(f, "elvish"),
Self::Powershell => write!(f, "powershell"),
Self::Other(value) => write!(f, "{value}"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FileChange {
Created,
Updated,
Unchanged,
Removed,
Absent,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ActivationMode {
SystemLoader,
ManagedRcBlock,
NativeDirectory,
Manual,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ActivationPolicy {
AutoManaged,
Manual,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Availability {
ActiveNow,
AvailableAfterNewShell,
AvailableAfterSource,
ManualActionRequired,
Unknown,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Operation {
Install,
DetectActivation,
Uninstall,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FailureKind {
MissingHome,
UnsupportedShell,
InvalidTargetPath,
DefaultPathUnavailable,
CompletionTargetUnavailable,
CompletionFileUnreadable,
ProfileUnavailable,
ProfileCorrupted,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InstallRequest<'a> {
pub shell: Shell,
pub program_name: &'a str,
pub script: &'a [u8],
pub path_override: Option<PathBuf>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct UninstallRequest<'a> {
pub shell: Shell,
pub program_name: &'a str,
pub path_override: Option<PathBuf>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InstallReport {
pub shell: Shell,
pub target_path: PathBuf,
pub file_change: FileChange,
pub activation: ActivationReport,
pub affected_locations: Vec<PathBuf>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct CleanupReport {
pub mode: ActivationMode,
pub change: FileChange,
pub location: Option<PathBuf>,
pub reason: Option<String>,
pub next_step: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RemoveReport {
pub shell: Shell,
pub target_path: PathBuf,
pub file_change: FileChange,
pub cleanup: CleanupReport,
pub affected_locations: Vec<PathBuf>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ActivationReport {
pub mode: ActivationMode,
pub availability: Availability,
pub location: Option<PathBuf>,
pub reason: Option<String>,
pub next_step: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FailureReport {
pub operation: Operation,
pub shell: Shell,
pub target_path: Option<PathBuf>,
pub affected_locations: Vec<PathBuf>,
pub kind: FailureKind,
pub file_change: Option<FileChange>,
pub activation: Option<ActivationReport>,
pub cleanup: Option<CleanupReport>,
pub reason: String,
pub next_step: Option<String>,
}