|
1 | 1 | use std::path::PathBuf; |
2 | 2 | use std::process::Command; |
3 | 3 |
|
4 | | -use clap_complete::shells; |
5 | | - |
6 | 4 | use crate::builder::{Builder, RunConfig, ShouldRun, Step}; |
7 | 5 | use crate::config::TargetSelection; |
8 | 6 | use crate::dist::distdir; |
@@ -268,23 +266,29 @@ impl Step for GenerateWindowsSys { |
268 | 266 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] |
269 | 267 | pub struct GenerateCompletions; |
270 | 268 |
|
| 269 | +macro_rules! generate_completions { |
| 270 | + ( $( ( $shell:ident, $filename:expr ) ),* ) => { |
| 271 | + $( |
| 272 | + if let Some(comp) = get_completion($shell, &$filename) { |
| 273 | + std::fs::write(&$filename, comp).expect(&format!("writing {} completion", stringify!($shell))); |
| 274 | + } |
| 275 | + )* |
| 276 | + }; |
| 277 | +} |
| 278 | + |
271 | 279 | impl Step for GenerateCompletions { |
272 | 280 | type Output = (); |
273 | 281 |
|
274 | 282 | /// Uses `clap_complete` to generate shell completions. |
275 | 283 | fn run(self, builder: &Builder<'_>) { |
276 | | - // FIXME(clubby789): enable zsh when clap#4898 is fixed |
277 | | - let [bash, fish, powershell] = ["x.py.sh", "x.py.fish", "x.py.ps1"] |
278 | | - .map(|filename| builder.src.join("src/etc/completions").join(filename)); |
279 | | - if let Some(comp) = get_completion(shells::Bash, &bash) { |
280 | | - std::fs::write(&bash, comp).expect("writing bash completion"); |
281 | | - } |
282 | | - if let Some(comp) = get_completion(shells::Fish, &fish) { |
283 | | - std::fs::write(&fish, comp).expect("writing fish completion"); |
284 | | - } |
285 | | - if let Some(comp) = get_completion(shells::PowerShell, &powershell) { |
286 | | - std::fs::write(&powershell, comp).expect("writing powershell completion"); |
287 | | - } |
| 284 | + use clap_complete::shells::{Bash, Fish, PowerShell, Zsh}; |
| 285 | + |
| 286 | + generate_completions!( |
| 287 | + (Bash, builder.src.join("src/etc/completions/x.py.sh")), |
| 288 | + (Zsh, builder.src.join("src/etc/completions/x.py.zsh")), |
| 289 | + (Fish, builder.src.join("src/etc/completions/x.py.fish")), |
| 290 | + (PowerShell, builder.src.join("src/etc/completions/x.py.ps1")) |
| 291 | + ); |
288 | 292 | } |
289 | 293 |
|
290 | 294 | fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { |
|
0 commit comments