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
57
58
59
60
61
62
63
64
//! Safety guards for privileged and destructive operations, implementing the
//! workflow standard: `--sudo` paired with a real root check, a self-documenting
//! confirmation flag, and `--dry-run` support surfaced through the context.
//!
//! The confirmation flag name and refusal wording are read from the active
//! [`crate::theme::Theme`], so a tool can reword them without touching this code.
use crate;
/// The default long confirmation flag for destructive operations. Overridable
/// per-tool via [`crate::theme::Theme::confirm_flag`].
pub const DEFAULT_CONFIRM_FLAG: &str =
"i-understand-this-is-permanent-i-have-saved-my-important-data";
/// Return the current effective user id (0 == root) on unix.
/// True when running as root.
/// Enforce that a root operation was both requested (`--sudo`) and is actually
/// running as root. Returns a permission error otherwise.
/// Enforce that a destructive operation was explicitly confirmed. `confirmed`
/// is whether the confirmation flag was present. When `dry_run` is set,
/// confirmation is not required because nothing is written. The refusal message
/// and flag name come from the active theme.