Skip to content

Commit 0833484

Browse files
Merge #6259
6259: allow xtask install --client[=CLIENT] to specify client r=Emilgardis a=Emilgardis Co-authored-by: Emil Gardström <[email protected]>
2 parents 08823c8 + c5b1c36 commit 0833484

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

xtask/src/install.rs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,43 @@ pub struct InstallCmd {
1313
pub server: Option<ServerOpt>,
1414
}
1515

16+
#[derive(Clone, Copy)]
1617
pub enum ClientOpt {
1718
VsCode,
19+
VsCodeInsiders,
20+
VsCodium,
21+
VsCodeOss,
22+
Any,
23+
}
24+
25+
impl ClientOpt {
26+
pub const fn as_cmds(&self) -> &'static [&'static str] {
27+
match self {
28+
ClientOpt::VsCode => &["code"],
29+
ClientOpt::VsCodeInsiders => &["code-insiders"],
30+
ClientOpt::VsCodium => &["codium"],
31+
ClientOpt::VsCodeOss => &["code-oss"],
32+
ClientOpt::Any => &["code", "code-insiders", "codium", "code-oss"],
33+
}
34+
}
35+
}
36+
37+
impl Default for ClientOpt {
38+
fn default() -> Self {
39+
ClientOpt::Any
40+
}
41+
}
42+
43+
impl std::str::FromStr for ClientOpt {
44+
type Err = anyhow::Error;
45+
46+
fn from_str(s: &str) -> Result<Self, Self::Err> {
47+
[ClientOpt::VsCode, ClientOpt::VsCodeInsiders, ClientOpt::VsCodium, ClientOpt::VsCodeOss]
48+
.iter()
49+
.copied()
50+
.find(|c| [s] == c.as_cmds())
51+
.ok_or_else(|| anyhow::format_err!("no such client"))
52+
}
1853
}
1954

2055
pub struct ServerOpt {
@@ -74,17 +109,13 @@ fn fix_path_for_mac() -> Result<()> {
74109
Ok(())
75110
}
76111

77-
fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
78-
let _dir = pushd("./editors/code")?;
112+
fn install_client(client_opt: ClientOpt) -> Result<()> {
113+
let _dir = pushd("./editors/code");
79114

80115
let find_code = |f: fn(&str) -> bool| -> Result<&'static str> {
81-
["code", "code-insiders", "codium", "code-oss"]
82-
.iter()
83-
.copied()
84-
.find(|bin| f(bin))
85-
.ok_or_else(|| {
86-
format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?")
87-
})
116+
client_opt.as_cmds().iter().copied().find(|bin| f(bin)).ok_or_else(|| {
117+
format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?")
118+
})
88119
};
89120

90121
let installed_extensions = if cfg!(unix) {

xtask/src/main.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use xshell::pushd;
1616
use xtask::{
1717
codegen::{self, Mode},
1818
dist::DistCmd,
19-
install::{ClientOpt, InstallCmd, Malloc, ServerOpt},
19+
install::{InstallCmd, Malloc, ServerOpt},
2020
metrics::MetricsCmd,
2121
pre_cache::PreCacheCmd,
2222
pre_commit, project_root,
@@ -46,19 +46,20 @@ USAGE:
4646
cargo xtask install [FLAGS]
4747
4848
FLAGS:
49-
--client-code Install only VS Code plugin
50-
--server Install only the language server
51-
--mimalloc Use mimalloc for server
52-
-h, --help Prints help information
49+
--client[=CLIENT] Install only VS Code plugin.
50+
CLIENT is one of 'code', 'code-insiders', 'codium', or 'code-oss'
51+
--server Install only the language server
52+
--mimalloc Use mimalloc for server
53+
-h, --help Prints help information
5354
"
5455
);
5556
return Ok(());
5657
}
5758
let server = args.contains("--server");
58-
let client_code = args.contains("--client-code");
59+
let client_code = args.contains("--client");
5960
if server && client_code {
6061
eprintln!(
61-
"error: The argument `--server` cannot be used with `--client-code`\n\n\
62+
"error: The argument `--server` cannot be used with `--client`\n\n\
6263
For more information try --help"
6364
);
6465
return Ok(());
@@ -67,10 +68,12 @@ FLAGS:
6768
let malloc =
6869
if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System };
6970

71+
let client_opt = args.opt_value_from_str("--client")?;
72+
7073
args.finish()?;
7174

7275
InstallCmd {
73-
client: if server { None } else { Some(ClientOpt::VsCode) },
76+
client: if server { None } else { Some(client_opt.unwrap_or_default()) },
7477
server: if client_code { None } else { Some(ServerOpt { malloc }) },
7578
}
7679
.run()

0 commit comments

Comments
 (0)