diff options
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/src/install.rs | 49 | ||||
-rw-r--r-- | xtask/src/main.rs | 19 |
2 files changed, 51 insertions, 17 deletions
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 { | |||
13 | pub server: Option<ServerOpt>, | 13 | pub server: Option<ServerOpt>, |
14 | } | 14 | } |
15 | 15 | ||
16 | #[derive(Clone, Copy)] | ||
16 | pub enum ClientOpt { | 17 | pub enum ClientOpt { |
17 | VsCode, | 18 | 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 | } | ||
18 | } | 53 | } |
19 | 54 | ||
20 | pub struct ServerOpt { | 55 | pub struct ServerOpt { |
@@ -74,17 +109,13 @@ fn fix_path_for_mac() -> Result<()> { | |||
74 | Ok(()) | 109 | Ok(()) |
75 | } | 110 | } |
76 | 111 | ||
77 | fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | 112 | fn install_client(client_opt: ClientOpt) -> Result<()> { |
78 | let _dir = pushd("./editors/code")?; | 113 | let _dir = pushd("./editors/code"); |
79 | 114 | ||
80 | let find_code = |f: fn(&str) -> bool| -> Result<&'static str> { | 115 | let find_code = |f: fn(&str) -> bool| -> Result<&'static str> { |
81 | ["code", "code-insiders", "codium", "code-oss"] | 116 | client_opt.as_cmds().iter().copied().find(|bin| f(bin)).ok_or_else(|| { |
82 | .iter() | 117 | format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?") |
83 | .copied() | 118 | }) |
84 | .find(|bin| f(bin)) | ||
85 | .ok_or_else(|| { | ||
86 | format_err!("Can't execute `code --version`. Perhaps it is not in $PATH?") | ||
87 | }) | ||
88 | }; | 119 | }; |
89 | 120 | ||
90 | let installed_extensions = if cfg!(unix) { | 121 | let installed_extensions = if cfg!(unix) { |
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 97e5dcd4e..536a67047 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -16,7 +16,7 @@ use xshell::pushd; | |||
16 | use xtask::{ | 16 | use xtask::{ |
17 | codegen::{self, Mode}, | 17 | codegen::{self, Mode}, |
18 | dist::DistCmd, | 18 | dist::DistCmd, |
19 | install::{ClientOpt, InstallCmd, Malloc, ServerOpt}, | 19 | install::{InstallCmd, Malloc, ServerOpt}, |
20 | metrics::MetricsCmd, | 20 | metrics::MetricsCmd, |
21 | pre_cache::PreCacheCmd, | 21 | pre_cache::PreCacheCmd, |
22 | pre_commit, project_root, | 22 | pre_commit, project_root, |
@@ -46,19 +46,20 @@ USAGE: | |||
46 | cargo xtask install [FLAGS] | 46 | cargo xtask install [FLAGS] |
47 | 47 | ||
48 | FLAGS: | 48 | FLAGS: |
49 | --client-code Install only VS Code plugin | 49 | --client[=CLIENT] Install only VS Code plugin. |
50 | --server Install only the language server | 50 | CLIENT is one of 'code', 'code-insiders', 'codium', or 'code-oss' |
51 | --mimalloc Use mimalloc for server | 51 | --server Install only the language server |
52 | -h, --help Prints help information | 52 | --mimalloc Use mimalloc for server |
53 | -h, --help Prints help information | ||
53 | " | 54 | " |
54 | ); | 55 | ); |
55 | return Ok(()); | 56 | return Ok(()); |
56 | } | 57 | } |
57 | let server = args.contains("--server"); | 58 | let server = args.contains("--server"); |
58 | let client_code = args.contains("--client-code"); | 59 | let client_code = args.contains("--client"); |
59 | if server && client_code { | 60 | if server && client_code { |
60 | eprintln!( | 61 | 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\ |
62 | For more information try --help" | 63 | For more information try --help" |
63 | ); | 64 | ); |
64 | return Ok(()); | 65 | return Ok(()); |
@@ -67,10 +68,12 @@ FLAGS: | |||
67 | let malloc = | 68 | let malloc = |
68 | if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System }; | 69 | if args.contains("--mimalloc") { Malloc::Mimalloc } else { Malloc::System }; |
69 | 70 | ||
71 | let client_opt = args.opt_value_from_str("--client")?; | ||
72 | |||
70 | args.finish()?; | 73 | args.finish()?; |
71 | 74 | ||
72 | InstallCmd { | 75 | InstallCmd { |
73 | client: if server { None } else { Some(ClientOpt::VsCode) }, | 76 | client: if server { None } else { Some(client_opt.unwrap_or_default()) }, |
74 | server: if client_code { None } else { Some(ServerOpt { malloc }) }, | 77 | server: if client_code { None } else { Some(ServerOpt { malloc }) }, |
75 | } | 78 | } |
76 | .run() | 79 | .run() |