siderolabs / homebrew-tap

A homebrew repo for our talos tap
Mozilla Public License 2.0
32 stars 20 forks source link

Support autocompletions #55

Open maslyankov opened 5 months ago

maslyankov commented 5 months ago

Hello! I am facing the following issue. Any idea what might be the cause of it?

 ~ % brew install talosctl                           
==> Fetching siderolabs/tap/talosctl
==> Downloading https://github.com/siderolabs/talos/releases/download/v1.6.4/talosctl-darwin-arm64
Already downloaded: /Users/maslyankov/Library/Caches/Homebrew/downloads/485b9ad5cac364a22d306b8aec2e873157cfde360ccac1576ee4e4dfae896eb1--talosctl-darwin-arm64
==> Installing talosctl from siderolabs/tap
brew: exec failed: {"SHELL"=>"bash"}
Error: Failure while executing; `\{\"SHELL\"=\>\"bash\"\} /opt/homebrew/Cellar/talosctl/1.6.4/bin/talosctl completion bash` exited with 1. Here's the output:
frezbo commented 5 months ago

@onedr0p seems to be the recent change. any ideas?

onedr0p commented 5 months ago

I am taking a look now, most of the other CLI apps I see doing this are doing it the same way as I added it here. Maybe there's a strange edge-case I am not seeing.

maslyankov commented 5 months ago

After the failed install, I checked if there is a file installed and:

 ~ % /opt/homebrew/Cellar/talosctl/1.6.4/bin/talosctl
zsh: no such file or directory: /opt/homebrew/Cellar/talosctl/1.6.4/bin/talosctl

My idea is that maybe there might be some file copy issue.

onedr0p commented 5 months ago

Yeah there's a strange issue where the that command runs from /opt/homebrew/Cellar/talosctl/1.6.4/bin/talosctl but /opt/homebrew/bin/talosctl is symlinked to it.

onedr0p commented 5 months ago

I suggest we revert this change until I can sort it out on my end and hopefully get it working

maslyankov commented 5 months ago

When I change:

def install
    if OS.mac? && Hardware::CPU.intel?
      bin.install "talosctl-darwin-amd64" => "talosctl"
    elsif OS.mac? && Hardware::CPU.arm?
      bin.install "talosctl-darwin-arm64" => "talosctl"
    elsif OS.linux? && Hardware::CPU.intel?
      bin.install "talosctl-linux-amd64" => "talosctl"
    elsif OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
      bin.install "talosctl-linux-armv7" => "talosctl"
    elsif OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
      bin.install "talosctl-linux-arm64" => "talosctl"
    end
    generate_completions_from_executable(bin/"talosctl", "completion")
  end

to :

def install
    if OS.mac? && Hardware::CPU.intel?
      bin.install "talosctl-darwin-amd64" => "talosctl"
    elsif OS.mac? && Hardware::CPU.arm?
      bin.install "talosctl-darwin-arm64" => "talosctl"
    elsif OS.linux? && Hardware::CPU.intel?
      bin.install "talosctl-linux-amd64" => "talosctl"
    elsif OS.linux? && Hardware::CPU.arm? && !Hardware::CPU.is_64_bit?
      bin.install "talosctl-linux-armv7" => "talosctl"
    elsif OS.linux? && Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
      bin.install "talosctl-linux-arm64" => "talosctl"
    end
  end

  def post_install
    generate_completions_from_executable(bin/"talosctl", "completion")
  end

It installs as expected. Not sure if the completitions work though.

onedr0p commented 5 months ago

@maslyankov nice find! It works here:

❯ brew install siderolabs/tap/talosctl
==> Fetching siderolabs/tap/talosctl
==> Downloading https://github.com/siderolabs/talos/releases/download/v1.6.4/talosctl-darwin-arm64
...
fish completions have been installed to:
  /opt/homebrew/share/fish/vendor_completions.d
...

Do you want to PR that change, or want me to?

maslyankov commented 5 months ago

@maslyankov nice find! It works here:

❯ brew install siderolabs/tap/talosctl
==> Fetching siderolabs/tap/talosctl
==> Downloading https://github.com/siderolabs/talos/releases/download/v1.6.4/talosctl-darwin-arm64
...
fish completions have been installed to:
  /opt/homebrew/share/fish/vendor_completions.d
...

Do you want to PR that change, or want me to?

I will do a PR, I have it locally.

maslyankov commented 5 months ago

https://github.com/siderolabs/homebrew-tap/pull/56

onedr0p commented 5 months ago

Well interesting, even though it says the completions were installed I do not see them in /opt/homebrew/share/fish/vendor_completions.d so this isn't fixed unfortunately.

onedr0p commented 5 months ago

I am completely lost to why it's not working the way it was before...

I don't see how what we are doing here is really any different than ... https://github.com/fluxcd/homebrew-tap/blob/master/Formula/flux.rb

Here's the full debug log

✖ brew install -vd siderolabs/tap/talosctl
/opt/homebrew/Library/Homebrew/brew.rb (Formulary::TapLoader): loading /opt/homebrew/Library/Taps/siderolabs/homebrew-tap/Formula/talosctl.rb
/opt/homebrew/Library/Homebrew/brew.rb (Cask::CaskLoader::FromTapLoader): loading siderolabs/tap/talosctl
==> Fetching siderolabs/tap/talosctl
==> Downloading https://github.com/siderolabs/talos/releases/download/v1.6.4/talosctl-darwin-arm64
/usr/bin/env /opt/homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --show-error --user-agent Homebrew/4.2.7\ \(Macintosh\;\ arm64\ Mac\ OS\ X\ 14.3.1\)\ curl/8.4.0 --header Accept-Language:\ en --retry 3 --fail --location --silent --head https://github.com/siderolabs/talos/releases/download/v1.6.4/talosctl-darwin-arm64
Already downloaded: /Users/devin/Library/Caches/Homebrew/downloads/485b9ad5cac364a22d306b8aec2e873157cfde360ccac1576ee4e4dfae896eb1--talosctl-darwin-arm64
==> Verifying checksum for '485b9ad5cac364a22d306b8aec2e873157cfde360ccac1576ee4e4dfae896eb1--talosctl-darwin-arm64'
==> Installing talosctl from siderolabs/tap
/usr/bin/env /opt/homebrew/Library/Homebrew/shims/shared/git --version
/usr/bin/env hdiutil imageinfo -format /Users/devin/Library/Caches/Homebrew/downloads/485b9ad5cac364a22d306b8aec2e873157cfde360ccac1576ee4e4dfae896eb1--talosctl-darwin-arm64
cp -p /Users/devin/Library/Caches/Homebrew/downloads/485b9ad5cac364a22d306b8aec2e873157cfde360ccac1576ee4e4dfae896eb1--talosctl-darwin-arm64 /private/tmp/talosctl-20240212-37030-ufp5en/talosctl-darwin-arm64
brew: exec failed: {"SHELL"=>"bash"}
/opt/homebrew/Library/Homebrew/ignorable.rb:29:in `block in raise'
ErrorDuringExecution: Failure while executing; `\{\"SHELL\"=\>\"bash\"\} /opt/homebrew/Cellar/talosctl/1.6.4/bin/talosctl completion bash` exited with 1.
onedr0p commented 5 months ago

We should rename this issue to "Support autocompletions" or something similar, I am at my wits end trying to get it to work though 😄