forked from rust-lang/rustup
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifications.rs
More file actions
142 lines (136 loc) · 5.48 KB
/
Copy pathnotifications.rs
File metadata and controls
142 lines (136 loc) · 5.48 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
use std::fmt::{self, Display};
use std::path::{Path, PathBuf};
use crate::{
dist::{dist::ToolchainDesc, temp},
toolchain::names::ToolchainName,
utils::notify::NotificationLevel,
};
#[derive(Debug)]
pub(crate) enum Notification<'a> {
Install(crate::dist::Notification<'a>),
Utils(crate::utils::Notification<'a>),
Temp(temp::Notification<'a>),
SetDefaultToolchain(Option<&'a ToolchainName>),
SetOverrideToolchain(&'a Path, &'a str),
SetProfile(&'a str),
SetSelfUpdate(&'a str),
LookingForToolchain(&'a ToolchainDesc),
ToolchainDirectory(&'a Path),
UpdatingToolchain(&'a str),
InstallingToolchain(&'a str),
InstalledToolchain(&'a str),
UsingExistingToolchain(&'a ToolchainDesc),
UninstallingToolchain(&'a ToolchainName),
UninstalledToolchain(&'a ToolchainName),
UpdateHashMatches,
UpgradingMetadata(&'a str, &'a str),
MetadataUpgradeNotNeeded(&'a str),
ReadMetadataVersion(&'a str),
NonFatalError(&'a anyhow::Error),
UpgradeRemovesToolchains,
/// Both `rust-toolchain` and `rust-toolchain.toml` exist within a directory
DuplicateToolchainFile {
rust_toolchain: &'a Path,
rust_toolchain_toml: &'a Path,
},
}
impl<'a> From<crate::dist::Notification<'a>> for Notification<'a> {
fn from(n: crate::dist::Notification<'a>) -> Self {
Notification::Install(n)
}
}
impl<'a> From<crate::utils::Notification<'a>> for Notification<'a> {
fn from(n: crate::utils::Notification<'a>) -> Self {
Notification::Utils(n)
}
}
impl<'a> From<temp::Notification<'a>> for Notification<'a> {
fn from(n: temp::Notification<'a>) -> Self {
Notification::Temp(n)
}
}
impl<'a> Notification<'a> {
pub(crate) fn level(&self) -> NotificationLevel {
use self::Notification::*;
match self {
Install(n) => n.level(),
Utils(n) => n.level(),
Temp(n) => n.level(),
ToolchainDirectory(_)
| LookingForToolchain(_)
| InstallingToolchain(_)
| UpdatingToolchain(_)
| ReadMetadataVersion(_)
| InstalledToolchain(_)
| UpdateHashMatches => NotificationLevel::Verbose,
SetDefaultToolchain(_)
| SetOverrideToolchain(_, _)
| SetProfile(_)
| SetSelfUpdate(_)
| UsingExistingToolchain(_)
| UninstallingToolchain(_)
| UninstalledToolchain(_)
| UpgradingMetadata(_, _)
| MetadataUpgradeNotNeeded(_) => NotificationLevel::Info,
NonFatalError(_) => NotificationLevel::Error,
UpgradeRemovesToolchains | DuplicateToolchainFile { .. } => NotificationLevel::Warn,
}
}
}
impl<'a> Display for Notification<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::result::Result<(), fmt::Error> {
use self::Notification::*;
match self {
Install(n) => n.fmt(f),
Utils(n) => n.fmt(f),
Temp(n) => n.fmt(f),
SetDefaultToolchain(None) => write!(f, "default toolchain unset"),
SetDefaultToolchain(Some(name)) => write!(f, "default toolchain set to '{name}'"),
SetOverrideToolchain(path, name) => write!(
f,
"override toolchain for '{}' set to '{}'",
path.display(),
name
),
SetProfile(name) => write!(f, "profile set to '{name}'"),
SetSelfUpdate(mode) => write!(f, "auto-self-update mode set to '{mode}'"),
LookingForToolchain(name) => write!(f, "looking for installed toolchain '{name}'"),
ToolchainDirectory(path) => write!(f, "toolchain directory: '{}'", path.display()),
UpdatingToolchain(name) => write!(f, "updating existing install for '{name}'"),
InstallingToolchain(name) => write!(f, "installing toolchain '{name}'"),
InstalledToolchain(name) => write!(f, "toolchain '{name}' installed"),
UsingExistingToolchain(name) => write!(f, "using existing install for '{name}'"),
UninstallingToolchain(name) => write!(f, "uninstalling toolchain '{name}'"),
UninstalledToolchain(name) => write!(f, "toolchain '{name}' uninstalled"),
UpdateHashMatches => write!(f, "toolchain is already up to date"),
UpgradingMetadata(from_ver, to_ver) => write!(
f,
"upgrading metadata version from '{from_ver}' to '{to_ver}'"
),
MetadataUpgradeNotNeeded(ver) => {
write!(f, "nothing to upgrade: metadata version is already '{ver}'")
}
ReadMetadataVersion(ver) => write!(f, "read metadata version: '{ver}'"),
NonFatalError(e) => write!(f, "{e}"),
UpgradeRemovesToolchains => write!(
f,
"this upgrade will remove all existing toolchains. you will need to reinstall them"
),
DuplicateToolchainFile {
rust_toolchain,
rust_toolchain_toml,
} => write!(
f,
"both `{0}` and `{1}` exist. Using `{0}`",
rust_toolchain
.canonicalize()
.unwrap_or_else(|_| PathBuf::from(rust_toolchain))
.display(),
rust_toolchain_toml
.canonicalize()
.unwrap_or_else(|_| PathBuf::from(rust_toolchain_toml))
.display(),
),
}
}
}