From 1c411143b18e8b5881f8845aefabd19952d9b788 Mon Sep 17 00:00:00 2001 From: Sebastian Wiesner Date: Mon, 28 Nov 2022 20:36:15 +0100 Subject: [PATCH] Generate completions per subcommand We used to generate completions for the top-level command, but that's not correct in a multicall binary: It includes the subcommands as completable arguments, whereas we actually need to split completions per subcommand. Hence, iterate over the two relevant subcommands aka binary names, and separately generate the completion for each corresponding subcommand. This corrects completions for mdcat, and as a bonus we now also generate completions for mdless which we didn't have before. Closes GH-214 --- CHANGELOG.md | 7 +++++++ build.rs | 9 ++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ecabc89..8c46cfe2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,15 @@ To publish a new release run `scripts/release` from the project directory. ## [Unreleased] +### Added +- Generate completions for `mdless` (see [GH-216]). + ### Fixed - Include generated shell completions in release artifacts. +- Fix completions for mdcat (see [GH-214] and [GH-216]) + +[GH-214]: https://github.com/lunaryorn/mdcat/issues/214 +[GH-216]: https://github.com/lunaryorn/mdcat/pull/216 ## [0.29.0] – 2022-10-21 diff --git a/build.rs b/build.rs index 1540bf97..312922e6 100644 --- a/build.rs +++ b/build.rs @@ -18,9 +18,12 @@ fn gen_completions>(out_dir: P) -> Result<()> { let completions = out_dir.as_ref().join("completions"); std::fs::create_dir_all(&completions).expect("Failed to create $OUT_DIR/completions"); - - for shell in [Shell::Bash, Shell::Zsh, Shell::Fish, Shell::PowerShell] { - generate_to(shell, &mut mdcat::Args::command(), "mdcat", &completions)?; + for program in ["mdcat", "mdless"] { + for shell in [Shell::Bash, Shell::Zsh, Shell::Fish, Shell::PowerShell] { + let mut command = mdcat::Args::command(); + let subcommand = command.find_subcommand_mut(program).unwrap(); + generate_to(shell, subcommand, program, &completions)?; + } } Ok(())