forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.rs
More file actions
115 lines (99 loc) · 2.8 KB
/
options.rs
File metadata and controls
115 lines (99 loc) · 2.8 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
use std::fmt;
use serde::{Deserialize, Serialize};
use crate::constants::{APPLICATION_NAME_MAP, PRODUCT_NAME_LONG_MAP, SERVER_NAME_MAP};
#[derive(clap::ArgEnum, Copy, Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
pub enum Quality {
#[serde(rename = "stable")]
Stable,
#[serde(rename = "exploration")]
Exploration,
#[serde(other)]
Insiders,
}
impl Quality {
/// Lowercased quality name in paths and protocol
pub fn get_machine_name(&self) -> &'static str {
match self {
Quality::Insiders => "insiders",
Quality::Exploration => "exploration",
Quality::Stable => "stable",
}
}
/// Uppercased quality display name for humans
pub fn get_capitalized_name(&self) -> &'static str {
match self {
Quality::Insiders => "Insiders",
Quality::Exploration => "Exploration",
Quality::Stable => "Stable",
}
}
/// Product long name
pub fn get_long_name(&self) -> &'static str {
PRODUCT_NAME_LONG_MAP
.as_ref()
.and_then(|m| m.get(self))
.map(|s| s.as_str())
.unwrap_or("Code - OSS")
}
/// Product application name
pub fn get_application_name(&self) -> &'static str {
APPLICATION_NAME_MAP
.as_ref()
.and_then(|m| m.get(self))
.map(|s| s.as_str())
.unwrap_or("code")
}
/// Server application name
pub fn server_entrypoint(&self) -> String {
let mut server_name = SERVER_NAME_MAP
.as_ref()
.and_then(|m| m.get(self))
.map(|s| s.as_str())
.unwrap_or("code-server-oss")
.to_string();
if cfg!(windows) {
server_name.push_str(".cmd");
}
server_name
}
}
impl fmt::Display for Quality {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.get_capitalized_name())
}
}
impl TryFrom<&str> for Quality {
type Error = String;
fn try_from(s: &str) -> Result<Self, Self::Error> {
match s {
"stable" => Ok(Quality::Stable),
"insiders" | "insider" => Ok(Quality::Insiders),
"exploration" => Ok(Quality::Exploration),
_ => Err(format!(
"Unknown quality: {}. Must be one of stable, insiders, or exploration.",
s
)),
}
}
}
#[derive(clap::ArgEnum, Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum TelemetryLevel {
Off,
Crash,
Error,
All,
}
impl fmt::Display for TelemetryLevel {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
TelemetryLevel::Off => write!(f, "off"),
TelemetryLevel::Crash => write!(f, "crash"),
TelemetryLevel::Error => write!(f, "error"),
TelemetryLevel::All => write!(f, "all"),
}
}
}