Skip to content

Commit

Permalink
completions: Support options-only fish
Browse files Browse the repository at this point in the history
Summary: Like it says in the title, wire this up. For now we return the options only completions even if the user doesn't ask for `--options-only`. That's ok, it's not wrong, it's just less feature-complete

Reviewed By: stepancheg

Differential Revision: D63085150

fbshipit-source-id: 3c65bfb1c759476f5025dc79fc74e9be80610800
  • Loading branch information
JakobDegen authored and facebook-github-bot committed Sep 21, 2024
1 parent 44c2e5a commit 26468dd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app/buck2_client/src/commands/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use clap_complete::generate;
#[clap(rename_all = "kebab-case")]
enum Shell {
Bash,
Fish,
Zsh,
}

Expand Down Expand Up @@ -74,9 +75,10 @@ fn print_completion_script(
let (wrapper, shell) = match shell_arg {
Shell::Bash => (BASH_COMPLETION_WRAPPER, clap_complete::Shell::Bash),
Shell::Zsh => (ZSH_COMPLETION_WRAPPER, clap_complete::Shell::Zsh),
Shell::Fish => ("", clap_complete::Shell::Fish),
};

if options_only {
if options_only || shell == clap_complete::Shell::Fish {
buck2_client_ctx::println!("{}", option_completions(shell, cmd)?)?;
return Ok(());
}
Expand Down
7 changes: 7 additions & 0 deletions shed/completion_verify/packages/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ dnf download "$1" --destdir "$BUCK_SCRATCH_PATH"
rpm=$(echo "$BUCK_SCRATCH_PATH"/*)
mkdir -p "$2"
rpm2archive - < "$rpm" | tar -xvzf - -C "$(realpath "$2")"

if [[ $1 =~ fish ]]; then
# In order to get fish to behave like it's been installed into a relocatable
# directory, we need to move things out of `usr/`
mv "$2/usr/"* "$2"
rmdir "$2/usr"
fi
2 changes: 1 addition & 1 deletion shed/completion_verify/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Shell {
Self::Bash => Ok(Command::new("bash")),
Self::Fish => {
let mut path = buck_resources::get("buck2/shed/completion_verify/fish").unwrap();
path.push("usr/bin/fish");
path.push("bin/fish");
Ok(Command::new(path))
}
Self::Zsh => {
Expand Down
9 changes: 6 additions & 3 deletions tests/e2e/completion/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

IS_LINUX: bool = platform.system() == "Linux"

SHELLS = ["bash", "zsh"]
# Downloading fish on Mac is not straightforward, so only test it on Linux
SHELLS = ["bash", "fish", "zsh"] if IS_LINUX else ["bash", "zsh"]


def completion_test(
Expand All @@ -29,6 +30,9 @@ def completion_test(
options_only: bool = False,
) -> None:
for shell in shells:
if shell == "fish" and not options_only:
# Fish only supports options-only completions
continue

# shell=shell is a trick to get the variable captured by value
async def impl(buck: Buck, shell: str = shell) -> None:
Expand Down Expand Up @@ -81,8 +85,7 @@ async def impl(buck: Buck, shell: str = shell) -> None:
# FIXME(JakobDegen): Should probably not be inconsistent
expected=["test", "targets"] if IS_LINUX else ["targets", "test"],
options_only=True,
# Skip this on zsh because it has fancy formatting with help messages for commands (and nothing
# else)
# Skip this on zsh and fish because they have fancy formatting with help messages for commands
shells=["bash"],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Arguments:
<SHELL>
shell for which to generate completion script

[possible values: bash, zsh]
[possible values: bash, fish, zsh]

Options:
-h, --help
Expand Down

0 comments on commit 26468dd

Please sign in to comment.