-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
brew.sh: don't autoupdate if --help passed #1190
brew.sh: don't autoupdate if --help passed #1190
Conversation
do | ||
if [[ $arg = "--help" ]] | ||
then | ||
export HOMEBREW_COMMAND_HELP="1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it only persists for the duration of the subshell, should we just set HOMEBREW_NO_AUTO_UPDATE
instead of adding another variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 amending.
8c7b407
to
7c4b8d3
Compare
# Check if user passes --help command which should prevent auto-update. | ||
for arg in "$@" | ||
do | ||
if [[ $arg = "--help" ]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same goes for "-h"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like even more than that. https://github.com/Homebrew/brew/blob/master/Library/Homebrew/brew.rb#L34
help_flag_list = %w[-h --help --usage -?]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. -?
— didn't know that. Weird one.
7c4b8d3
to
bb89c4d
Compare
Can't we set |
By the time you get to |
Ah, ok, let's get rid of |
Getting rid of |
With |
We could completely remove the # check for help flags and call `help` instead
arg_n=0
for arg in "$@"
do
((arg_n++))
if [[ $arg = "--help" || $arg = "-h" || $arg = "--usage" || $arg = "-?" ]]
then
set -- "${@:1:arg_n-1}" "${@:arg_n+1}" && ((arg_n--))
if [ $HOMEBREW_COMMAND != "help" ]
then
set -- "$HOMEBREW_COMMAND" "$@" && ((arg_n++))
HOMEBREW_COMMAND="help"
fi
fi
done |
It's fine to set another environment variable to pass state between Bash and Ruby code. Personally I'd rather see us do that than overload |
@MikeMcQuaid @reitermarkus @zmwangx @dunn What if we transform any command like
Basically we just remove all the help flags and unshift arg_n=0
for arg in "$@"
do
((arg_n++))
if [[ $arg = "--help" || $arg = "-h" || $arg = "--usage" || $arg = "-?" ]]
then
set -- "${@:1:arg_n-1}" "${@:arg_n+1}" && ((arg_n--))
if [[ $1 != "help" ]]
then
set -- "help" "$@" && ((arg_n++))
fi
fi
done
|
Seems like a good idea (even if the Bash code currently makes me want to cry a bit). It may be cleaner to consider just setting |
The idea was to prevent parsing Assuming what you have said, can this be a solution? diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh
index 22ebb87..8ecaadd 100644
--- a/Library/Homebrew/brew.sh
+++ b/Library/Homebrew/brew.sh
@@ -179,6 +179,15 @@ then
set -- "$@" -v
fi
+for arg in "$@"
+do
+ if [[ $arg = "--help" || $arg = "-h" || $arg = "--usage" || $arg = "-?" ]]
+ then
+ HOMEBREW_HELP="1"
+ break
+ fi
+done
+
HOMEBREW_ARG_COUNT="$#"
HOMEBREW_COMMAND="$1"
shift
@@ -268,6 +277,7 @@ setup-analytics
report-analytics-screenview-command
update-preinstall() {
+ [[ "$HOMEBREW_HELP" != "1" ]] || return
[[ -z "$HOMEBREW_NO_AUTO_UPDATE" ]] || return
[[ -z "$HOMEBREW_UPDATE_PREINSTALL" ]] || return
|
Not your bad, this stuff is just far messier to do in Bash/
Yeh, that looks good. You could also |
bb89c4d
to
73d235b
Compare
@@ -32,20 +32,17 @@ def require?(path) | |||
|
|||
empty_argv = ARGV.empty? | |||
help_flag_list = %w[-h --help --usage -?] | |||
help_flag = false | |||
help_flag = ENV["HOMEBREW_HELP"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!ENV["HOMEBREW_HELP"].nil?
, maybe, so we get a nice boolean.
73d235b
to
d92a1ad
Compare
Thanks @vladshablinsky! |
brew tests
with your changes locally?Seems to fix #1188.