From d0bb051ef7a2cfb4cc1d26e2cf981c4e345269e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Sat, 17 Oct 2020 00:35:06 +0200 Subject: allow xtask install --client-code[=CLIENT] to specify client --- xtask/src/install.rs | 49 ++++++++++++++++++++++++++++++++++++++++--------- xtask/src/main.rs | 15 +++++++++------ 2 files changed, 49 insertions(+), 15 deletions(-) (limited to 'xtask') diff --git a/xtask/src/install.rs b/xtask/src/install.rs index 789e9f27b..78a8af797 100644 --- a/xtask/src/install.rs +++ b/xtask/src/install.rs @@ -13,8 +13,43 @@ pub struct InstallCmd { pub server: Option, } +#[derive(Clone, Copy)] pub enum ClientOpt { VsCode, + VsCodeInsiders, + VsCodium, + VsCodeOss, + Any, +} + +impl ClientOpt { + pub const fn as_cmds(&self) -> &'static [&'static str] { + match self { + ClientOpt::VsCode => &["code"], + ClientOpt::VsCodeInsiders => &["code-insiders"], + ClientOpt::VsCodium => &["codium"], + ClientOpt::VsCodeOss => &["code-oss"], + ClientOpt::Any => &["code", "code-insiders", "codium", "code-oss"], + } + } +} + +impl Default for ClientOpt { + fn default() -> Self { + ClientOpt::Any + } +} + +impl std::str::FromStr for ClientOpt { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + [ClientOpt::VsCode, ClientOpt::VsCodeInsiders, ClientOpt::VsCodium, ClientOpt::VsCodeOss] + .iter() + .copied() + .find(|c| [s] == c.as_cmds()) + .ok_or_else(|| anyhow::format_err!("no such client")) + } } pub struct ServerOpt { @@ -74,17 +109,13 @@ fn fix_path_for_mac() -> Result<()> { Ok(()) } -fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { - let _dir = pushd("./editors/code")?; +fn install_client(client_opt: ClientOpt) -> Result<()> { + let _dir = pushd("./editors/code"); let find_code = |f: fn(&str) -> bool| -> Result<&'static str> { - ["code", "code-insiders", "codium", "code-oss"] - .iter() - .copied() - .find(|bin| f(bin)) - .ok_or_else(|| { - format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?") - }) + client_opt.as_cmds().iter().copied().find(|bin| f(bin)).ok_or_else(|| { + format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?") + }) }; let installed_extensions = if cfg!(unix) { diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 97e5dcd4e..62124041d 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -16,7 +16,7 @@ use xshell::pushd; use xtask::{ codegen::{self, Mode}, dist::DistCmd, - install::{ClientOpt, InstallCmd, Malloc, ServerOpt}, + install::{InstallCmd, Malloc, ServerOpt}, metrics::MetricsCmd, pre_cache::PreCacheCmd, pre_commit, project_root, @@ -46,10 +46,11 @@ USAGE: cargo xtask install [FLAGS] FLAGS: - --client-code Install only VS Code plugin - --server Install only the language server - --mimalloc Use mimalloc for server - -h, --help Prints help information + --client-code[=CLIENT] Install only VS Code plugin. + CLIENT is one of 'code', 'code-insiders', 'codium', or 'code-oss' + --server Install only the language server + --mimalloc Use mimalloc for server + -h, --help Prints help information " ); return Ok(()); @@ -67,10 +68,12 @@ FLAGS: let malloc = if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System }; + let client_opt = args.opt_value_from_str("--client-code")?; + args.finish()?; InstallCmd { - client: if server { None } else { Some(ClientOpt::VsCode) }, + client: if server { None } else { Some(client_opt.unwrap_or_default()) }, server: if client_code { None } else { Some(ServerOpt { malloc }) }, } .run() -- cgit v1.2.3 From c5b1c36b2beeb68c2ede28e78a5aa7b8227a0d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Tue, 20 Oct 2020 22:37:02 +0200 Subject: rename flag --client-code to --client on xtask install --- xtask/src/main.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'xtask') diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 62124041d..536a67047 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -46,20 +46,20 @@ USAGE: cargo xtask install [FLAGS] FLAGS: - --client-code[=CLIENT] Install only VS Code plugin. - CLIENT is one of 'code', 'code-insiders', 'codium', or 'code-oss' - --server Install only the language server - --mimalloc Use mimalloc for server - -h, --help Prints help information + --client[=CLIENT] Install only VS Code plugin. + CLIENT is one of 'code', 'code-insiders', 'codium', or 'code-oss' + --server Install only the language server + --mimalloc Use mimalloc for server + -h, --help Prints help information " ); return Ok(()); } let server = args.contains("--server"); - let client_code = args.contains("--client-code"); + let client_code = args.contains("--client"); if server && client_code { eprintln!( - "error: The argument `--server` cannot be used with `--client-code`\n\n\ + "error: The argument `--server` cannot be used with `--client`\n\n\ For more information try --help" ); return Ok(()); @@ -68,7 +68,7 @@ FLAGS: let malloc = if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System }; - let client_opt = args.opt_value_from_str("--client-code")?; + let client_opt = args.opt_value_from_str("--client")?; args.finish()?; -- cgit v1.2.3