1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::model::ShellKind;
/// Planned profile edit action.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ApplyAction {
/// The target profile does not exist and would be created by a future mutating apply.
CreateProfile,
/// The target profile exists without a patholog managed block.
AppendBlock,
/// The target profile has one complete patholog managed block.
ReplaceBlock,
}
impl ApplyAction {
/// Stable action string for human and JSON output.
#[must_use]
pub fn as_str(self) -> &'static str {
match self {
Self::CreateProfile => "create_profile",
Self::AppendBlock => "append_block",
Self::ReplaceBlock => "replace_block",
}
}
}
/// Plan describing what an apply operation would write.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ApplyPlan {
/// Shell syntax used by the planned block.
pub shell: ShellKind,
/// Target shell profile path.
pub profile_path: String,
/// Planned operation.
pub action: ApplyAction,
/// Existing managed block when replacing one.
pub existing_block: Option<String>,
/// Complete managed block that apply writes or would write.
pub planned_block: String,
/// Cleaned PATH value used to render the planned block.
pub cleaned_path: String,
/// Whether this run writes files.
pub would_write: bool,
}
/// Result of a mutating apply run.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct ApplyOutcome {
/// Apply plan that was executed.
pub plan: ApplyPlan,
/// Whether the profile was written.
pub wrote: bool,
/// Backup path when one was created.
pub backup_path: Option<String>,
/// Whether a backup file was created.
pub backup_created: bool,
}