Various improvements for brew command
				
					
				
			- Add a (large) speedup by moving some logic to Bash for the typical case of a normal or dev-cmd, Bash or Ruby command. - Make `brew command` a non-developer command, I don't think it makes sense to consider it something needed for developing Homebrew. - Update the manpage/tests/RBI accordingly. Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									c9c8806be8
								
							
						
					
					
						commit
						4ffcd8a110
					
				@ -120,6 +120,11 @@ case "$*" in
 | 
				
			|||||||
    source "${HOMEBREW_LIBRARY}/Homebrew/formula_path.sh"
 | 
					    source "${HOMEBREW_LIBRARY}/Homebrew/formula_path.sh"
 | 
				
			||||||
    homebrew-formula-path "$@" && exit 0
 | 
					    homebrew-formula-path "$@" && exit 0
 | 
				
			||||||
    ;;
 | 
					    ;;
 | 
				
			||||||
 | 
					  # falls back to cmd/command.rb on a non-zero return
 | 
				
			||||||
 | 
					  command*)
 | 
				
			||||||
 | 
					    source "${HOMEBREW_LIBRARY}/Homebrew/command_path.sh"
 | 
				
			||||||
 | 
					    homebrew-command-path "$@" && exit 0
 | 
				
			||||||
 | 
					    ;;
 | 
				
			||||||
esac
 | 
					esac
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#####
 | 
					#####
 | 
				
			||||||
 | 
				
			|||||||
@ -5,7 +5,7 @@ require "abstract_command"
 | 
				
			|||||||
require "commands"
 | 
					require "commands"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module Homebrew
 | 
					module Homebrew
 | 
				
			||||||
  module DevCmd
 | 
					  module Cmd
 | 
				
			||||||
    class Command < AbstractCommand
 | 
					    class Command < AbstractCommand
 | 
				
			||||||
      cmd_args do
 | 
					      cmd_args do
 | 
				
			||||||
        description <<~EOS
 | 
					        description <<~EOS
 | 
				
			||||||
							
								
								
									
										46
									
								
								Library/Homebrew/command_path.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								Library/Homebrew/command_path.sh
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,46 @@
 | 
				
			|||||||
 | 
					# does the quickest output of brew command possible for the basic cases of an
 | 
				
			||||||
 | 
					# official Bash or Ruby normal or dev-cmd command.
 | 
				
			||||||
 | 
					# HOMEBREW_LIBRARY is set by brew.sh
 | 
				
			||||||
 | 
					# shellcheck disable=SC2154
 | 
				
			||||||
 | 
					homebrew-command-path() {
 | 
				
			||||||
 | 
					  case "$1" in
 | 
				
			||||||
 | 
					    # check we actually have command and not e.g. commandsomething
 | 
				
			||||||
 | 
					    command) ;;
 | 
				
			||||||
 | 
					    *) return 1 ;;
 | 
				
			||||||
 | 
					  esac
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  local first_command found_command
 | 
				
			||||||
 | 
					  for arg in "$@"
 | 
				
			||||||
 | 
					  do
 | 
				
			||||||
 | 
					    if [[ -z "${first_command}" && "${arg}" == "command" ]]
 | 
				
			||||||
 | 
					    then
 | 
				
			||||||
 | 
					      first_command=1
 | 
				
			||||||
 | 
					      continue
 | 
				
			||||||
 | 
					    elif [[ -f "${HOMEBREW_LIBRARY}/Homebrew/cmd/${arg}.sh" ]]
 | 
				
			||||||
 | 
					    then
 | 
				
			||||||
 | 
					      echo "${HOMEBREW_LIBRARY}/Homebrew/cmd/${arg}.sh"
 | 
				
			||||||
 | 
					      found_command=1
 | 
				
			||||||
 | 
					    elif [[ -f "${HOMEBREW_LIBRARY}/Homebrew/dev-cmd/${arg}.sh" ]]
 | 
				
			||||||
 | 
					    then
 | 
				
			||||||
 | 
					      echo "${HOMEBREW_LIBRARY}/Homebrew/dev-cmd/${arg}.sh"
 | 
				
			||||||
 | 
					      found_command=1
 | 
				
			||||||
 | 
					    elif [[ -f "${HOMEBREW_LIBRARY}/Homebrew/cmd/${arg}.rb" ]]
 | 
				
			||||||
 | 
					    then
 | 
				
			||||||
 | 
					      echo "${HOMEBREW_LIBRARY}/Homebrew/cmd/${arg}.rb"
 | 
				
			||||||
 | 
					      found_command=1
 | 
				
			||||||
 | 
					    elif [[ -f "${HOMEBREW_LIBRARY}/Homebrew/dev-cmd/${arg}.rb" ]]
 | 
				
			||||||
 | 
					    then
 | 
				
			||||||
 | 
					      echo "${HOMEBREW_LIBRARY}/Homebrew/dev-cmd/${arg}.rb"
 | 
				
			||||||
 | 
					      found_command=1
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					      return 1
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					  done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if [[ -n "${found_command}" ]]
 | 
				
			||||||
 | 
					  then
 | 
				
			||||||
 | 
					    return 0
 | 
				
			||||||
 | 
					  else
 | 
				
			||||||
 | 
					    return 1
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										12
									
								
								Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/command.rbi
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/command.rbi
									
									
									
										generated
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
				
			|||||||
 | 
					# typed: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# DO NOT EDIT MANUALLY
 | 
				
			||||||
 | 
					# This is an autogenerated file for dynamic methods in `Homebrew::Cmd::Command`.
 | 
				
			||||||
 | 
					# Please instead update this file by running `bin/tapioca dsl Homebrew::Cmd::Command`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Homebrew::Cmd::Command
 | 
				
			||||||
 | 
					  sig { returns(Homebrew::Cmd::Command::Args) }
 | 
				
			||||||
 | 
					  def args; end
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class Homebrew::Cmd::Command::Args < Homebrew::CLI::Args; end
 | 
				
			||||||
@ -1,12 +0,0 @@
 | 
				
			|||||||
# typed: true
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# DO NOT EDIT MANUALLY
 | 
					 | 
				
			||||||
# This is an autogenerated file for dynamic methods in `Homebrew::DevCmd::Command`.
 | 
					 | 
				
			||||||
# Please instead update this file by running `bin/tapioca dsl Homebrew::DevCmd::Command`.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Homebrew::DevCmd::Command
 | 
					 | 
				
			||||||
  sig { returns(Homebrew::DevCmd::Command::Args) }
 | 
					 | 
				
			||||||
  def args; end
 | 
					 | 
				
			||||||
end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Homebrew::DevCmd::Command::Args < Homebrew::CLI::Args; end
 | 
					 | 
				
			||||||
@ -1,9 +1,9 @@
 | 
				
			|||||||
# frozen_string_literal: true
 | 
					# frozen_string_literal: true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
require "cmd/shared_examples/args_parse"
 | 
					require "cmd/shared_examples/args_parse"
 | 
				
			||||||
require "dev-cmd/command"
 | 
					require "cmd/command"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
RSpec.describe Homebrew::DevCmd::Command do
 | 
					RSpec.describe Homebrew::Cmd::Command do
 | 
				
			||||||
  it_behaves_like "parseable arguments"
 | 
					  it_behaves_like "parseable arguments"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  it "returns the file for a given command", :integration_test do
 | 
					  it "returns the file for a given command", :integration_test do
 | 
				
			||||||
@ -153,6 +153,10 @@ old. This can be adjusted with `HOMEBREW_CLEANUP_MAX_AGE_DAYS`.
 | 
				
			|||||||
: Only prune the symlinks and directories from the prefix and remove no other
 | 
					: Only prune the symlinks and directories from the prefix and remove no other
 | 
				
			||||||
  files.
 | 
					  files.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### `command` *`command`* \[...\]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Display the path to the file being used when invoking `brew` *`cmd`*.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### `commands` \[`--quiet`\] \[`--include-aliases`\]
 | 
					### `commands` \[`--quiet`\] \[`--include-aliases`\]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Show lists of built-in and external commands.
 | 
					Show lists of built-in and external commands.
 | 
				
			||||||
@ -1985,10 +1989,6 @@ Display the source of a *`formula`* or *`cask`*.
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
: Treat all named arguments as casks.
 | 
					: Treat all named arguments as casks.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### `command` *`command`* \[...\]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
Display the path to the file being used when invoking `brew` *`cmd`*.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
### `contributions` \[--user=*`email|username`*\] \[*`--repositories`*`=`\] \[*`--csv`*\]
 | 
					### `contributions` \[--user=*`email|username`*\] \[*`--repositories`*`=`\] \[*`--csv`*\]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Summarise contributions to Homebrew repositories.
 | 
					Summarise contributions to Homebrew repositories.
 | 
				
			||||||
 | 
				
			|||||||
@ -93,6 +93,8 @@ Scrub the cache, including downloads for even the latest versions\. Note that do
 | 
				
			|||||||
.TP
 | 
					.TP
 | 
				
			||||||
\fB\-\-prune\-prefix\fP
 | 
					\fB\-\-prune\-prefix\fP
 | 
				
			||||||
Only prune the symlinks and directories from the prefix and remove no other files\.
 | 
					Only prune the symlinks and directories from the prefix and remove no other files\.
 | 
				
			||||||
 | 
					.SS "\fBcommand\fP \fIcommand\fP \fR[\.\.\.]"
 | 
				
			||||||
 | 
					Display the path to the file being used when invoking \fBbrew\fP \fIcmd\fP\&\.
 | 
				
			||||||
.SS "\fBcommands\fP \fR[\fB\-\-quiet\fP] \fR[\fB\-\-include\-aliases\fP]"
 | 
					.SS "\fBcommands\fP \fR[\fB\-\-quiet\fP] \fR[\fB\-\-include\-aliases\fP]"
 | 
				
			||||||
Show lists of built\-in and external commands\.
 | 
					Show lists of built\-in and external commands\.
 | 
				
			||||||
.TP
 | 
					.TP
 | 
				
			||||||
@ -1259,8 +1261,6 @@ Treat all named arguments as formulae\.
 | 
				
			|||||||
.TP
 | 
					.TP
 | 
				
			||||||
\fB\-\-cask\fP
 | 
					\fB\-\-cask\fP
 | 
				
			||||||
Treat all named arguments as casks\.
 | 
					Treat all named arguments as casks\.
 | 
				
			||||||
.SS "\fBcommand\fP \fIcommand\fP \fR[\.\.\.]"
 | 
					 | 
				
			||||||
Display the path to the file being used when invoking \fBbrew\fP \fIcmd\fP\&\.
 | 
					 | 
				
			||||||
.SS "\fBcontributions\fP \fR[\-\-user=\fIemail|username\fP] \fR[\fI\-\-repositories\fP\fB=\fP] \fR[\fI\-\-csv\fP]"
 | 
					.SS "\fBcontributions\fP \fR[\-\-user=\fIemail|username\fP] \fR[\fI\-\-repositories\fP\fB=\fP] \fR[\fI\-\-csv\fP]"
 | 
				
			||||||
Summarise contributions to Homebrew repositories\.
 | 
					Summarise contributions to Homebrew repositories\.
 | 
				
			||||||
.TP
 | 
					.TP
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user