Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formula: conditionally use executable name as completion name #18942

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

cho-m
Copy link
Member

@cho-m cho-m commented Dec 15, 2024

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

In most cases, when running generate_completions_from_executable with a formula's bin/sbin executable, the resulting completion is usually intended for the executable itself.

From a quick glance, this should avoid majority of base_name overrides in Homebrew/core. Formulae that use register-python-argcomplete may still need an override (e.g. azure-cli, commitizen)


For non-bin/sbin executables, the original default of formula name is used as these have higher chance of being an intermediary/helper executable, e.g. libexec/"bin/register-python-argcomplete" (azure-cli) or a helper go script (caddy)

@cho-m cho-m marked this pull request as ready for review December 15, 2024 16:25
@cho-m
Copy link
Member Author

cho-m commented Dec 15, 2024

We could detect register-python-argcomplete and set default to commands.second. This does make the documentation a bit more complicated, but can provide a more useful default and avoid situations like current python-yq https://github.com/Homebrew/homebrew-core/blob/master/Formula/p/python-yq.rb#L49-L52

%w[yq xq tomlq].each do |script|
  generate_completions_from_executable(libexec/"bin/register-python-argcomplete", script,
                                       shell_parameter_format: :arg)
end

Above had unintended result of single set of completion named python-yq (each iteration overwriting same files).


EDIT: However only 6 formulae use this command and 3 of them can use default of formula name. So may be simple enough to handle on Homebrew/core side.

Only need to fix python-yq: Homebrew/homebrew-core#201269

When running `generate_completions_from_executable` with a formula's
`bin`/`sbin` executable, the resulting completion is usually intended
for the executable itself.
@cho-m cho-m force-pushed the completion-base_name branch from 7a4e2f0 to 60b5e06 Compare December 15, 2024 16:59
Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, thanks!

@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Dec 16, 2024
Merged via the queue into master with commit 6c14bcb Dec 16, 2024
28 checks passed
@MikeMcQuaid MikeMcQuaid deleted the completion-base_name branch December 16, 2024 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants