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

Can we make HB flags not interfere with cask? #28977

Closed
vitorgalvao opened this issue Jan 13, 2017 · 6 comments · Fixed by Homebrew/brew#3306
Closed

Can we make HB flags not interfere with cask? #28977

vitorgalvao opened this issue Jan 13, 2017 · 6 comments · Fixed by Homebrew/brew#3306

Comments

@vitorgalvao
Copy link
Member

vitorgalvao commented Jan 13, 2017

I’m building an external command for cask. However, I’m running into a snag caused by Homebrew (related: #16265). Basically, short flag options become not viable.

Steps to reproduce:

# Make a simple temporary executable script
echo '#!/bin/bash
[[ "${1}" == "--flag" ]] && echo "long flag given"
[[ "${1}" == "-a" ]] && echo "short flag given"
[[ -z "${1}" ]] && echo "no flag given"' > /tmp/brewcask-example
chmod +x /tmp/brewcask-example

# Add its directory to your PATH
PATH=/tmp:$PATH

# Run it as an external command, with and without the flags
brew cask example
brew cask example --flag
brew cask example -a

# You’ll get (in order)
no flag given # correct
long flag given # correct
Error: There is more than one possible option that starts with '-a' # incorrect

That last option is being “stolen” by Homebrew itself. Try something like brew cask example --help and you’ll get their help, not even ours.

HB flags shouldn’t interfere with HBC commands. That --help example would be particularly confusing to a user.

Pinging @reitermarkus @claui @jawshooah @mwean.

@MikeMcQuaid
Copy link
Member

Try something like brew cask example --help and you’ll get their help, not even ours.

If you use #: before your comments at the top of a file they will be output by brew --help.

@vitorgalvao
Copy link
Member Author

If you use #: before your comments at the top of a file they will be output by brew --help.

It only works for brew external commands, not brew cask ones.

And this looks like a bug, but I just tried brew services --help and my terminal is filled with the (correct) instructions. I then cannot leave/do anything until I ctrlC.

@MikeMcQuaid
Copy link
Member

It only works for brew external commands, not brew cask ones.

It could be made to work on brew cask external commands fairly easily.

And this looks like a bug, but I just tried brew services --help and my terminal is filled with the (correct) instructions. I then cannot leave/do anything until I ctrlC.

I cannot reproduce this. It could be related to pager (e.g. less) settings.

@vitorgalvao
Copy link
Member Author

I cannot reproduce this. It could be related to pager (e.g. less) settings.

I have no custom settings for less. I can reproduce in both zsh inside iTerm2 (my setup) and bash inside Terminal (pristine and unchanged, that I keep for tests such as this).

In both terminals the title bar (where the current running command is shown) goes crazy, switching between bash and ruby, suggesting there‘s an infinite loop. When you brew services --help, does it fit all at once on your Terminal? In mine it does not (not tall enough).

@MikeMcQuaid
Copy link
Member

@vitorgalvao No idea then, sorry.

@commitay commitay added bug Issue describing a reproducible bug. hacktoberfest labels Sep 28, 2017
@amyspark
Copy link
Contributor

@MikeMcQuaid, I can confirm and reproduce the two bugs described by @vitorgalvao.

The first one:

That last option is being “stolen” by Homebrew itself. Try something like brew cask example --help and you’ll get their help, not even ours.

It's a bug in Cask's cli.rb:
https://github.com/Homebrew/brew/blob/56458f03fcc68ef6d8ee3ee4a7c1d16021aa5800/Library/Homebrew/cask/lib/hbc/cli.rb#L227-L235
Line 234 specifies that it should print the first argument if available, which the example script does (instead of example, which doesn't exist as a command!)

The second one:

And this looks like a bug, but I just tried brew services --help and my terminal is filled with the (correct) instructions. I then cannot leave/do anything until I ctrlC.

This one only happens if homebrew/services has not been previously tapped, because in this case the help request is redirected to the tap command, which always returns the help text without actually tapping the cask 🤦‍♀️ .
The execution flow is roughly like this:

brew services --help

The bug lies in the remarked step: if a tap is required, it should not obey the HOMEBREW_HELP environment variable.

A pull request in Homebrew is forthcoming.

@commitay commitay removed bug Issue describing a reproducible bug. hacktoberfest labels Oct 24, 2017
@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants