use std::collections::{BTreeMap, BTreeSet};
use std::path::PathBuf;
use crate::variables::{ShellValueUnsetType, ShellVariableUpdateTransform};
#[derive(Clone, Debug, Default)]
pub struct SnapshotOptions {
pub baseline: BTreeMap<String, String>,
pub exclude: BTreeSet<String>,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct ShellSnapshot {
pub working_dir: PathBuf,
pub directory_stack: Vec<PathBuf>,
pub last_exit_status: u8,
pub positional_parameters: Vec<String>,
pub variables: BTreeMap<String, SavedVariable>,
pub unset_variables: BTreeSet<String>,
pub functions: BTreeMap<String, SavedFunction>,
pub aliases: BTreeMap<String, String>,
pub traps: BTreeMap<String, String>,
pub set_options: BTreeMap<String, bool>,
pub shopt_options: BTreeMap<String, bool>,
pub disabled_builtins: BTreeSet<String>,
pub not_kept: Vec<NotKept>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SavedVariable {
pub value: SavedValue,
pub exported: bool,
pub readonly: bool,
pub integer: bool,
pub nameref: bool,
pub trace: bool,
pub transform: ShellVariableUpdateTransform,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SavedValue {
Unset(ShellValueUnsetType),
String(String),
IndexedArray(BTreeMap<u64, String>),
AssociativeArray(BTreeMap<String, String>),
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SavedFunction {
pub body: String,
pub exported: bool,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct NotKept {
pub kind: NotKeptKind,
pub name: String,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NotKeptKind {
Job,
OpenFile,
Function,
}
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct RestoreReport {
pub failed: Vec<RestoreFailure>,
}
impl RestoreReport {
pub const fn is_complete(&self) -> bool {
self.failed.is_empty()
}
pub(crate) fn fail(&mut self, kind: StateKind, name: &str, reason: RestoreFailureReason) {
self.failed.push(RestoreFailure {
kind,
name: name.to_owned(),
reason,
});
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct RestoreFailure {
pub kind: StateKind,
pub name: String,
pub reason: RestoreFailureReason,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum StateKind {
WorkingDir,
Variable,
UnsetVariable,
Function,
Trap,
SetOption,
ShoptOption,
DisabledBuiltin,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RestoreFailureReason {
NotADirectory,
Readonly,
DoesNotParse,
UnknownSignal,
UnknownOption,
UnknownBuiltin,
}