Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/cli/src/options.rs
3309 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
use std::fmt;
7
8
use serde::{Deserialize, Serialize};
9
10
use crate::constants::SERVER_NAME_MAP;
11
12
#[derive(clap::ValueEnum, Copy, Clone, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
13
pub enum Quality {
14
#[serde(rename = "stable")]
15
Stable,
16
#[serde(rename = "exploration")]
17
Exploration,
18
#[serde(other)]
19
Insiders,
20
}
21
22
impl Quality {
23
/// Lowercased quality name in paths and protocol
24
pub fn get_machine_name(&self) -> &'static str {
25
match self {
26
Quality::Insiders => "insiders",
27
Quality::Exploration => "exploration",
28
Quality::Stable => "stable",
29
}
30
}
31
32
/// Uppercased quality display name for humans
33
pub fn get_capitalized_name(&self) -> &'static str {
34
match self {
35
Quality::Insiders => "Insiders",
36
Quality::Exploration => "Exploration",
37
Quality::Stable => "Stable",
38
}
39
}
40
41
/// Server application name
42
pub fn server_entrypoint(&self) -> String {
43
let mut server_name = SERVER_NAME_MAP
44
.as_ref()
45
.and_then(|m| m.get(self))
46
.map(|s| s.server_application_name.as_str())
47
.unwrap_or("code-server-oss")
48
.to_string();
49
50
if cfg!(windows) {
51
server_name.push_str(".cmd");
52
}
53
54
server_name
55
}
56
}
57
58
impl fmt::Display for Quality {
59
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
60
write!(f, "{}", self.get_capitalized_name())
61
}
62
}
63
64
impl TryFrom<&str> for Quality {
65
type Error = String;
66
67
fn try_from(s: &str) -> Result<Self, Self::Error> {
68
match s {
69
"stable" => Ok(Quality::Stable),
70
"insiders" | "insider" => Ok(Quality::Insiders),
71
"exploration" => Ok(Quality::Exploration),
72
_ => Err(format!(
73
"Unknown quality: {s}. Must be one of stable, insiders, or exploration."
74
)),
75
}
76
}
77
}
78
79
#[derive(clap::ValueEnum, Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
80
pub enum TelemetryLevel {
81
Off,
82
Crash,
83
Error,
84
All,
85
}
86
87
impl fmt::Display for TelemetryLevel {
88
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
89
match self {
90
TelemetryLevel::Off => write!(f, "off"),
91
TelemetryLevel::Crash => write!(f, "crash"),
92
TelemetryLevel::Error => write!(f, "error"),
93
TelemetryLevel::All => write!(f, "all"),
94
}
95
}
96
}
97
98