|
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,26 +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 |
| - let [bash, zsh, fish, powershell] = ["x.py.sh", "x.py.zsh", "x.py.fish", "x.py.ps1"] |
277 |
| - .map(|filename| builder.src.join("src/etc/completions").join(filename)); |
278 |
| - |
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::Zsh, &zsh) { |
283 |
| - std::fs::write(&zsh, comp).expect("writing bash completion"); |
284 |
| - } |
285 |
| - if let Some(comp) = get_completion(shells::Fish, &fish) { |
286 |
| - std::fs::write(&fish, comp).expect("writing fish completion"); |
287 |
| - } |
288 |
| - if let Some(comp) = get_completion(shells::PowerShell, &powershell) { |
289 |
| - std::fs::write(&powershell, comp).expect("writing powershell completion"); |
290 |
| - } |
| 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 | + ); |
291 | 292 | }
|
292 | 293 |
|
293 | 294 | fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
|
0 commit comments