diff options
Diffstat (limited to 'xtask/src/main.rs')
-rw-r--r-- | xtask/src/main.rs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 84842b428..7eab1c949 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs | |||
@@ -9,6 +9,7 @@ | |||
9 | //! `.cargo/config`. | 9 | //! `.cargo/config`. |
10 | mod help; | 10 | mod help; |
11 | 11 | ||
12 | use anyhow::Context; | ||
12 | use autocfg; | 13 | use autocfg; |
13 | use core::fmt::Write; | 14 | use core::fmt::Write; |
14 | use core::str; | 15 | use core::str; |
@@ -114,21 +115,21 @@ fn handle_extra_flags(e: pico_args::Error) -> Result<()> { | |||
114 | write!(&mut invalid_flags, "{}, ", flag)?; | 115 | write!(&mut invalid_flags, "{}, ", flag)?; |
115 | } | 116 | } |
116 | let (invalid_flags, _) = invalid_flags.split_at(invalid_flags.len() - 2); | 117 | let (invalid_flags, _) = invalid_flags.split_at(invalid_flags.len() - 2); |
117 | Err(format!("Invalid flags: {}", invalid_flags).into()) | 118 | anyhow::bail!("Invalid flags: {}", invalid_flags) |
118 | } else { | 119 | } else { |
119 | Err(e.to_string().into()) | 120 | anyhow::bail!(e.to_string()) |
120 | } | 121 | } |
121 | } | 122 | } |
122 | 123 | ||
123 | fn install(opts: InstallOpt) -> Result<()> { | 124 | fn install(opts: InstallOpt) -> Result<()> { |
124 | if cfg!(target_os = "macos") { | 125 | if cfg!(target_os = "macos") { |
125 | fix_path_for_mac()? | 126 | fix_path_for_mac().context("Fix path for mac")? |
126 | } | 127 | } |
127 | if let Some(server) = opts.server { | 128 | if let Some(server) = opts.server { |
128 | install_server(server)?; | 129 | install_server(server).context("install server")?; |
129 | } | 130 | } |
130 | if let Some(client) = opts.client { | 131 | if let Some(client) = opts.client { |
131 | install_client(client)?; | 132 | install_client(client).context("install client")?; |
132 | } | 133 | } |
133 | Ok(()) | 134 | Ok(()) |
134 | } | 135 | } |
@@ -140,7 +141,7 @@ fn fix_path_for_mac() -> Result<()> { | |||
140 | const ROOT_DIR: &str = ""; | 141 | const ROOT_DIR: &str = ""; |
141 | let home_dir = match env::var("HOME") { | 142 | let home_dir = match env::var("HOME") { |
142 | Ok(home) => home, | 143 | Ok(home) => home, |
143 | Err(e) => Err(format!("Failed getting HOME from environment with error: {}.", e))?, | 144 | Err(e) => anyhow::bail!("Failed getting HOME from environment with error: {}.", e), |
144 | }; | 145 | }; |
145 | 146 | ||
146 | [ROOT_DIR, &home_dir] | 147 | [ROOT_DIR, &home_dir] |
@@ -154,12 +155,12 @@ fn fix_path_for_mac() -> Result<()> { | |||
154 | if !vscode_path.is_empty() { | 155 | if !vscode_path.is_empty() { |
155 | let vars = match env::var_os("PATH") { | 156 | let vars = match env::var_os("PATH") { |
156 | Some(path) => path, | 157 | Some(path) => path, |
157 | None => Err("Could not get PATH variable from env.")?, | 158 | None => anyhow::bail!("Could not get PATH variable from env."), |
158 | }; | 159 | }; |
159 | 160 | ||
160 | let mut paths = env::split_paths(&vars).collect::<Vec<_>>(); | 161 | let mut paths = env::split_paths(&vars).collect::<Vec<_>>(); |
161 | paths.append(&mut vscode_path); | 162 | paths.append(&mut vscode_path); |
162 | let new_paths = env::join_paths(paths)?; | 163 | let new_paths = env::join_paths(paths).context("build env PATH")?; |
163 | env::set_var("PATH", &new_paths); | 164 | env::set_var("PATH", &new_paths); |
164 | } | 165 | } |
165 | 166 | ||
@@ -198,7 +199,7 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | |||
198 | 199 | ||
199 | let code_binary = match code_binary { | 200 | let code_binary = match code_binary { |
200 | Some(it) => it, | 201 | Some(it) => it, |
201 | None => Err("Can't execute `code --version`. Perhaps it is not in $PATH?")?, | 202 | None => anyhow::bail!("Can't execute `code --version`. Perhaps it is not in $PATH?"), |
202 | }; | 203 | }; |
203 | 204 | ||
204 | Cmd { | 205 | Cmd { |
@@ -219,8 +220,10 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> { | |||
219 | .run_with_output()?; | 220 | .run_with_output()?; |
220 | 221 | ||
221 | if !str::from_utf8(&output.stdout)?.contains("ra-lsp") { | 222 | if !str::from_utf8(&output.stdout)?.contains("ra-lsp") { |
222 | Err("Could not install the Visual Studio Code extension. \ | 223 | anyhow::bail!( |
223 | Please make sure you have at least NodeJS 10.x installed and try again.")?; | 224 | "Could not install the Visual Studio Code extension. \ |
225 | Please make sure you have at least NodeJS 10.x installed and try again." | ||
226 | ); | ||
224 | } | 227 | } |
225 | 228 | ||
226 | Ok(()) | 229 | Ok(()) |