diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 2fba870a71..d63f2d05f7 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -55,6 +55,8 @@ begin end end + Homebrew.args = Homebrew::CLI::Parser.new.parse(ignore_invalid_options: true) + path = PATH.new(ENV["PATH"]) homebrew_path = PATH.new(ENV["HOMEBREW_PATH"]) @@ -117,16 +119,17 @@ begin odie "Unknown command: #{cmd}" if !possible_tap || possible_tap.installed? # Unset HOMEBREW_HELP to avoid confusing the tap - ENV.delete("HOMEBREW_HELP") if help_flag - tap_commands = [] - cgroup = Utils.popen_read("cat", "/proc/1/cgroup") - if %w[azpl_job actions_job docker garden kubepods].none? { |container| cgroup.include?(container) } - brew_uid = HOMEBREW_BREW_FILE.stat.uid - tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] if Process.uid.zero? && !brew_uid.zero? + with_env HOMEBREW_HELP: nil do + tap_commands = [] + cgroup = Utils.popen_read("cat", "/proc/1/cgroup") + if %w[azpl_job actions_job docker garden kubepods].none? { |container| cgroup.include?(container) } + brew_uid = HOMEBREW_BREW_FILE.stat.uid + tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] if Process.uid.zero? && !brew_uid.zero? + end + tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{possible_tap.name}] + safe_system(*tap_commands) end - tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{possible_tap.name}] - safe_system(*tap_commands) - ENV["HOMEBREW_HELP"] = "1" if help_flag + exec HOMEBREW_BREW_FILE, cmd, *ARGV end rescue UsageError => e diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 5d4eafd519..977d3bd06b 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -336,6 +336,8 @@ fi for arg in "$@" do + [[ $arg = "--" ]] && break + if [[ $arg = "--help" || $arg = "-h" || $arg = "--usage" || $arg = "-?" ]] then export HOMEBREW_HELP="1" diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index 0f5353dc25..a959790afb 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -10,7 +10,7 @@ module Homebrew # undefine tap to allow --tap argument undef tap - def initialize(argv = ARGV.freeze, set_default_args: false) + def initialize(argv = ARGV.dup.freeze, set_default_args: false) super() @processed_options = [] @@ -58,10 +58,6 @@ module Homebrew @flags_only = args_flags_only(cli_args) end - def passthrough - options_only - CLI::Parser.global_options.values.map(&:first).flatten - end - def named named_args || [] end diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 64a5c3c495..5e03c5c81a 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -13,10 +13,6 @@ module Homebrew class Parser attr_reader :processed_options, :hide_from_man_page - def self.parse(argv = ARGV.freeze, allow_no_named_args: false, &block) - new(argv, &block).parse(allow_no_named_args: allow_no_named_args) - end - def self.from_cmd_path(cmd_path) cmd_args_method_name = Commands.args_method_name(cmd_path) @@ -30,15 +26,16 @@ module Homebrew end def self.global_options - { - quiet: [["-q", "--quiet"], :quiet, "Suppress any warnings."], - verbose: [["-v", "--verbose"], :verbose, "Make some output more verbose."], - debug: [["-d", "--debug"], :debug, "Display any debugging information."], - } + [ + ["-q", "--quiet", "Suppress any warnings."], + ["-v", "--verbose", "Make some output more verbose."], + ["-d", "--debug", "Display any debugging information."], + ] end - def initialize(argv = ARGV.freeze, &block) + def initialize(argv = ARGV.dup.freeze, &block) @parser = OptionParser.new + @argv = argv @args = Homebrew::CLI::Args.new(@argv) @@ -50,25 +47,31 @@ module Homebrew @min_named_args = nil @min_named_type = nil @hide_from_man_page = false - instance_eval(&block) + + self.class.global_options.each do |short, long, desc| + switch short, long, description: desc + end + + instance_eval(&block) if block_given? + post_initialize end def post_initialize + # Disable default handling of `--version` switch. + @parser.base.long.delete("version") + + # Disable default handling of `--help` switch. @parser.on_tail("-h", "--help", "Show this message.") do - puts generate_help_text - exit 0 + raise OptionParser::InvalidOption end end def switch(*names, description: nil, env: nil, required_for: nil, depends_on: nil) global_switch = names.first.is_a?(Symbol) - names, env, default_description = common_switch(*names) if global_switch - if description.nil? && global_switch - description = default_description - elsif description.nil? - description = option_to_description(*names) - end + return if global_switch + + description = option_to_description(*names) if description.nil? process_option(*names, description) @parser.on(*names, *wrap_option_desc(description)) do enable_switch(*names, from: :args) @@ -153,31 +156,54 @@ module Homebrew @parser.to_s end - def parse(argv = @argv, allow_no_named_args: false) + def parse(argv = @argv, ignore_invalid_options: false) raise "Arguments were already parsed!" if @args_parsed - begin - named_args = @parser.parse(argv) - rescue OptionParser::InvalidOption => e - $stderr.puts generate_help_text - raise e + i = 0 + remaining = [] + + argv, non_options = split_double_dash(argv) + + while i < argv.count + begin + begin + arg = argv[i] + + remaining << arg unless @parser.parse([arg]).empty? + rescue OptionParser::MissingArgument + raise if i + 1 >= argv.count + + args = argv[i..(i + 1)] + @parser.parse(args) + i += 1 + end + rescue OptionParser::InvalidOption + if ignore_invalid_options + remaining << arg + else + $stderr.puts generate_help_text + raise + end + end + + i += 1 + end + + named_args = if ignore_invalid_options + [] + else + remaining + non_options end check_constraint_violations - check_named_args(named_args, allow_no_named_args: allow_no_named_args) + check_named_args(named_args) @args.freeze_named_args!(named_args) @args.freeze_processed_options!(@processed_options) - Homebrew.args = @args @args_parsed = true @args end - def global_option?(name, desc) - Homebrew::CLI::Parser.global_options.key?(name.to_sym) && - Homebrew::CLI::Parser.global_options[name.to_sym].last == desc - end - def generate_help_text @parser.to_s .sub(/^/, "#{Tty.bold}Usage: brew#{Tty.reset} ") @@ -188,7 +214,7 @@ module Homebrew end def formula_options - formulae.each do |f| + formulae(@argv).each do |f| next if f.options.empty? f.options.each do |o| @@ -256,11 +282,6 @@ module Homebrew end end - # These are common/global switches accessible throughout Homebrew - def common_switch(name) - Homebrew::CLI::Parser.global_options.fetch(name, name) - end - def option_passed?(name) @args[name.to_sym] || @args["#{name}?".to_sym] end @@ -328,8 +349,10 @@ module Homebrew check_constraints end - def check_named_args(args, allow_no_named_args: false) + def check_named_args(args) min_exception = case @min_named_type + when :cask + Cask::CaskUnspecifiedError.new when :formula FormulaUnspecifiedError.new when :keg @@ -337,8 +360,8 @@ module Homebrew else MinNamedArgumentsError.new(@min_named_args) end - raise min_exception if !allow_no_named_args && !@min_named_args.nil? && args.size < @min_named_args - raise MaxNamedArgumentsError, @max_named_args if !@max_named_args.nil? && args.size > @max_named_args + raise min_exception if @min_named_args && args.size < @min_named_args + raise MaxNamedArgumentsError, @max_named_args if @max_named_args && args.size > @max_named_args end def process_option(*args) @@ -346,11 +369,21 @@ module Homebrew @processed_options << [option.short.first, option.long.first, option.arg, option.desc.first] end - def formulae - named_args = @argv.reject { |arg| arg.start_with?("-") } - spec = if @argv.include?("--HEAD") + def split_double_dash(argv) + if sep = argv.index("--") + [argv.take(sep), argv.drop(sep + 1)] + else + [argv, []] + end + end + + def formulae(argv) + argv, named_argv = split_double_dash(argv) + + named_args = argv.reject { |arg| arg.start_with?("-") } + named_argv + spec = if argv.include?("--HEAD") :head - elsif @argv.include?("--devel") + elsif argv.include?("--devel") :devel else :stable diff --git a/Library/Homebrew/cmd/--cellar.rb b/Library/Homebrew/cmd/--cellar.rb index 4b1367cf67..7ef1b6fc39 100644 --- a/Library/Homebrew/cmd/--cellar.rb +++ b/Library/Homebrew/cmd/--cellar.rb @@ -20,7 +20,7 @@ module Homebrew end def __cellar - __cellar_args.parse + args = __cellar_args.parse if args.no_named? puts HOMEBREW_CELLAR diff --git a/Library/Homebrew/cmd/--prefix.rb b/Library/Homebrew/cmd/--prefix.rb index 5269e38d9e..82a0b464a8 100644 --- a/Library/Homebrew/cmd/--prefix.rb +++ b/Library/Homebrew/cmd/--prefix.rb @@ -20,7 +20,7 @@ module Homebrew end def __prefix - __prefix_args.parse + args = __prefix_args.parse if args.no_named? puts HOMEBREW_PREFIX diff --git a/Library/Homebrew/cmd/--repository.rb b/Library/Homebrew/cmd/--repository.rb index 8e27a8def4..211f1c0c2f 100644 --- a/Library/Homebrew/cmd/--repository.rb +++ b/Library/Homebrew/cmd/--repository.rb @@ -18,7 +18,7 @@ module Homebrew end def __repository - __repository_args.parse + args = __repository_args.parse if args.no_named? puts HOMEBREW_REPOSITORY diff --git a/Library/Homebrew/cmd/analytics.rb b/Library/Homebrew/cmd/analytics.rb index 1e641e7214..4c8ef458f7 100644 --- a/Library/Homebrew/cmd/analytics.rb +++ b/Library/Homebrew/cmd/analytics.rb @@ -22,14 +22,12 @@ module Homebrew `brew analytics regenerate-uuid`: Regenerate the UUID used for Homebrew's analytics. EOS - switch :verbose - switch :debug max_named 1 end end def analytics - analytics_args.parse + args = analytics_args.parse case args.named.first when nil, "state" diff --git a/Library/Homebrew/cmd/cleanup.rb b/Library/Homebrew/cmd/cleanup.rb index 3f8481c8e6..510b872f03 100644 --- a/Library/Homebrew/cmd/cleanup.rb +++ b/Library/Homebrew/cmd/cleanup.rb @@ -27,13 +27,11 @@ module Homebrew "If you want to delete those too: `rm -rf \"$(brew --cache)\"`" switch "--prune-prefix", description: "Only prune the symlinks and directories from the prefix and remove no other files." - switch :verbose - switch :debug end end def cleanup - cleanup_args.parse + args = cleanup_args.parse cleanup = Cleanup.new(*args.named, dry_run: args.dry_run?, scrub: args.s?, days: args.prune&.to_i) if args.prune_prefix? diff --git a/Library/Homebrew/cmd/commands.rb b/Library/Homebrew/cmd/commands.rb index ab695b436f..29fd687555 100644 --- a/Library/Homebrew/cmd/commands.rb +++ b/Library/Homebrew/cmd/commands.rb @@ -12,19 +12,18 @@ module Homebrew Show lists of built-in and external commands. EOS - switch :quiet, + switch "-q", "--quiet", description: "List only the names of commands without category headers." switch "--include-aliases", depends_on: "--quiet", description: "Include aliases of internal commands." - switch :verbose - switch :debug + max_named 0 end end def commands - commands_args.parse + args = commands_args.parse if args.quiet? puts Formatter.columns(Commands.commands(aliases: args.include_aliases?)) diff --git a/Library/Homebrew/cmd/config.rb b/Library/Homebrew/cmd/config.rb index a95ab42f6f..d0519bf4ac 100644 --- a/Library/Homebrew/cmd/config.rb +++ b/Library/Homebrew/cmd/config.rb @@ -14,8 +14,7 @@ module Homebrew Show Homebrew and system configuration info useful for debugging. If you file a bug report, you will be required to provide this information. EOS - switch :verbose - switch :debug + max_named 0 end end diff --git a/Library/Homebrew/cmd/deps.rb b/Library/Homebrew/cmd/deps.rb index b5b05ce2e5..ed333204bd 100644 --- a/Library/Homebrew/cmd/deps.rb +++ b/Library/Homebrew/cmd/deps.rb @@ -53,15 +53,14 @@ module Homebrew description: "Switch into the mode used by the `--all` option, but only list dependencies "\ "for each provided , one formula per line. This is used for "\ "debugging the `--installed`/`--all` display mode." - switch :verbose - switch :debug + conflicts "--installed", "--all" formula_options end end def deps - deps_args.parse + args = deps_args.parse Formulary.enable_factory_cache! diff --git a/Library/Homebrew/cmd/desc.rb b/Library/Homebrew/cmd/desc.rb index ce505aaa0f..bd5c669459 100644 --- a/Library/Homebrew/cmd/desc.rb +++ b/Library/Homebrew/cmd/desc.rb @@ -28,14 +28,14 @@ module Homebrew switch "-d", "--description", description: "Search just descriptions for . If is flanked by slashes, "\ "it is interpreted as a regular expression." - switch :verbose + conflicts "--search", "--name", "--description" min_named 1 end end def desc - desc_args.parse + args = desc_args.parse search_type = if args.search? :either diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb index 7fc4208926..24da404e6c 100644 --- a/Library/Homebrew/cmd/doctor.rb +++ b/Library/Homebrew/cmd/doctor.rb @@ -23,13 +23,11 @@ module Homebrew "if provided as arguments." switch "-D", "--audit-debug", description: "Enable debugging and profiling of audit methods." - switch :verbose - switch :debug end end def doctor - doctor_args.parse + args = doctor_args.parse inject_dump_stats!(Diagnostic::Checks, /^check_*/) if args.audit_debug? diff --git a/Library/Homebrew/cmd/fetch.rb b/Library/Homebrew/cmd/fetch.rb index fbf45cfcf2..60794c7d85 100644 --- a/Library/Homebrew/cmd/fetch.rb +++ b/Library/Homebrew/cmd/fetch.rb @@ -23,7 +23,7 @@ module Homebrew description: "Fetch development version instead of stable version." switch "-f", "--force", description: "Remove a previously cached version and re-fetch." - switch :verbose, + switch "-v", "--verbose", description: "Do a verbose VCS checkout, if the URL represents a VCS. This is useful for "\ "seeing if an existing VCS cache has been updated." switch "--retry", @@ -38,7 +38,7 @@ module Homebrew switch "--force-bottle", description: "Download a bottle if it exists for the current or newest version of macOS, "\ "even if it would not be used during installation." - switch :debug + conflicts "--devel", "--HEAD" conflicts "--build-from-source", "--build-bottle", "--force-bottle" min_named :formula diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb index 912266b6df..5bebb3ee1a 100644 --- a/Library/Homebrew/cmd/gist-logs.rb +++ b/Library/Homebrew/cmd/gist-logs.rb @@ -28,8 +28,7 @@ module Homebrew switch "-p", "--private", description: "The Gist will be marked private and will not appear in listings but will "\ "be accessible with its link." - switch :verbose - switch :debug + named :formula end end @@ -142,7 +141,7 @@ module Homebrew end def gist_logs - gist_logs_args.parse + args = gist_logs_args.parse Install.perform_preinstall_checks(all_fatal: true) Install.perform_build_from_source_checks(all_fatal: true) diff --git a/Library/Homebrew/cmd/home.rb b/Library/Homebrew/cmd/home.rb index e567febfab..8b37d3810c 100644 --- a/Library/Homebrew/cmd/home.rb +++ b/Library/Homebrew/cmd/home.rb @@ -15,12 +15,11 @@ module Homebrew Open 's homepage in a browser, or open Homebrew's own homepage if no formula is provided. EOS - switch :debug end end def home - home_args.parse + args = home_args.parse if args.no_named? exec_browser HOMEBREW_WWW diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index c43101e7f7..d975d131f9 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -52,15 +52,15 @@ module Homebrew switch "--all", depends_on: "--json", description: "Print JSON of all available formulae." - switch :verbose, + switch "-v", "--verbose", description: "Show more verbose analytics data for ." - switch :debug + conflicts "--installed", "--all" end end def info - info_args.parse + args = info_args.parse if args.days.present? raise UsageError, "--days must be one of #{VALID_DAYS.join(", ")}" unless VALID_DAYS.include?(args.days) @@ -83,17 +83,17 @@ module Homebrew raise FormulaUnspecifiedError if args.no_named? end - print_json + print_json(args: args) elsif args.github? raise FormulaUnspecifiedError if args.no_named? exec_browser(*args.formulae.map { |f| github_info(f) }) else - print_info + print_info(args: args) end end - def print_info + def print_info(args:) if args.no_named? if args.analytics? Utils::Analytics.output(args: args) @@ -126,7 +126,7 @@ module Homebrew end end - def print_json + def print_json(args:) ff = if args.all? Formula.sort elsif args.installed? diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 893ec43a93..e920ab35f0 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -24,7 +24,7 @@ module Homebrew Unless `HOMEBREW_NO_INSTALL_CLEANUP` is set, `brew cleanup` will then be run for the installed formulae or, every 30 days, for all formulae. EOS - switch :debug, + switch "-d", "--debug", description: "If brewing fails, open an interactive debugging session with access to IRB "\ "or a shell inside the temporary build directory." flag "--env=", @@ -74,7 +74,7 @@ module Homebrew switch "-f", "--force", description: "Install without checking for previously installed keg-only or "\ "non-migrated versions." - switch :verbose, + switch "-v", "--verbose", description: "Print the verification and postinstall steps." switch "--display-times", env: :display_install_times, diff --git a/Library/Homebrew/cmd/leaves.rb b/Library/Homebrew/cmd/leaves.rb index be4fcdf559..1768227b79 100644 --- a/Library/Homebrew/cmd/leaves.rb +++ b/Library/Homebrew/cmd/leaves.rb @@ -14,7 +14,7 @@ module Homebrew List installed formulae that are not dependencies of another installed formula. EOS - switch :debug + max_named 0 end end diff --git a/Library/Homebrew/cmd/link.rb b/Library/Homebrew/cmd/link.rb index 441cf1de1d..25719e29a8 100644 --- a/Library/Homebrew/cmd/link.rb +++ b/Library/Homebrew/cmd/link.rb @@ -23,14 +23,13 @@ module Homebrew "`brew link --overwrite` without actually linking or deleting any files." switch "-f", "--force", description: "Allow keg-only formulae to be linked." - switch :verbose - switch :debug + min_named :keg end end def link - link_args.parse + args = link_args.parse mode = OpenStruct.new diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 6dda14d46a..87e3d38985 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -45,14 +45,13 @@ module Homebrew description: "Reverse the order of the sort to list the oldest entries first." switch "-t", description: "Sort by time modified, listing most recently modified first." - switch :verbose - switch :debug + ["--unbrewed", "--multiple", "--pinned", "-l", "-r", "-t"].each { |flag| conflicts "--cask", flag } end end def list - list_args.parse + args = list_args.parse return list_casks if args.cask? @@ -76,7 +75,14 @@ module Homebrew puts Formatter.columns(full_names) else ENV["CLICOLOR"] = nil - safe_system "ls", *args.passthrough << HOMEBREW_CELLAR + + ls_args = [] + ls_args << "-1" if args.public_send(:'1?') + ls_args << "-l" if args.l? + ls_args << "-r" if args.r? + ls_args << "-t" if args.t? + + safe_system "ls", *ls_args, HOMEBREW_CELLAR end elsif args.verbose? || !$stdout.tty? system_command! "find", args: args.kegs.map(&:to_s) + %w[-not -type d -print], print_stdout: true diff --git a/Library/Homebrew/cmd/log.rb b/Library/Homebrew/cmd/log.rb index ffee96f468..e49d4bead0 100644 --- a/Library/Homebrew/cmd/log.rb +++ b/Library/Homebrew/cmd/log.rb @@ -27,7 +27,7 @@ module Homebrew end def log - log_args.parse + args = log_args.parse # As this command is simplifying user-run commands then let's just use a # user path, too. diff --git a/Library/Homebrew/cmd/migrate.rb b/Library/Homebrew/cmd/migrate.rb index a9d3619543..c6f12d7831 100644 --- a/Library/Homebrew/cmd/migrate.rb +++ b/Library/Homebrew/cmd/migrate.rb @@ -17,8 +17,7 @@ module Homebrew switch "-f", "--force", description: "Treat installed and provided as if they are from "\ "the same taps and migrate them anyway." - switch :verbose - switch :debug + min_named :formula end end diff --git a/Library/Homebrew/cmd/missing.rb b/Library/Homebrew/cmd/missing.rb index 11714597dd..ee249d5a6e 100644 --- a/Library/Homebrew/cmd/missing.rb +++ b/Library/Homebrew/cmd/missing.rb @@ -20,13 +20,11 @@ module Homebrew comma_array "--hide", description: "Act as if none of the specified are installed. should be "\ "a comma-separated list of formulae." - switch :verbose - switch :debug end end def missing - missing_args.parse + args = missing_args.parse return unless HOMEBREW_CELLAR.exist? diff --git a/Library/Homebrew/cmd/options.rb b/Library/Homebrew/cmd/options.rb index c41d27f149..4665e8e399 100644 --- a/Library/Homebrew/cmd/options.rb +++ b/Library/Homebrew/cmd/options.rb @@ -23,13 +23,13 @@ module Homebrew description: "Show options for all available formulae." flag "--command=", description: "Show options for the specified ." - switch :debug + conflicts "--installed", "--all", "--command" end end def options - options_args.parse + args = options_args.parse if args.all? puts_options Formula.to_a.sort diff --git a/Library/Homebrew/cmd/outdated.rb b/Library/Homebrew/cmd/outdated.rb index 7c5f078716..7ce5a854a0 100644 --- a/Library/Homebrew/cmd/outdated.rb +++ b/Library/Homebrew/cmd/outdated.rb @@ -17,9 +17,9 @@ module Homebrew List installed formulae that have an updated version available. By default, version information is displayed in interactive shells, and suppressed otherwise. EOS - switch :quiet, + switch "-q", "--quiet", description: "List only the names of outdated kegs (takes precedence over `--verbose`)." - switch :verbose, + switch "-v", "--verbose", description: "Include detailed version information." flag "--json", description: "Print output in JSON format. There are two versions: v1 and v2. " \ @@ -35,16 +35,16 @@ module Homebrew description: "Treat all arguments as formulae." switch "--cask", description: "Treat all arguments as casks." - switch :debug + conflicts "--quiet", "--verbose", "--json" conflicts "--formula", "--cask" end end def outdated - outdated_args.parse + args = outdated_args.parse - case json_version + case json_version(args.json) when :v1, :default # TODO: enable for next major/minor release # odeprecated "brew outdated --json#{json_version == :v1 ? "=v1" : ""}", "brew outdated --json=v2" @@ -55,7 +55,7 @@ module Homebrew outdated_casks end - puts JSON.generate(json_info(outdated)) + puts JSON.generate(json_info(outdated, args: args)) when :v2 formulae, casks = if args.formula? @@ -67,8 +67,8 @@ module Homebrew end json = { - "formulae" => json_info(formulae), - "casks" => json_info(casks), + "formulae" => json_info(formulae, args: args), + "casks" => json_info(casks, args: args), } puts JSON.generate(json) @@ -127,7 +127,7 @@ module Homebrew end end - def json_info(formulae_or_casks) + def json_info(formulae_or_casks, args:) formulae_or_casks.map do |formula_or_cask| if formula_or_cask.is_a?(Formula) f = formula_or_cask @@ -156,7 +156,7 @@ module Homebrew ($stdout.tty? || args.verbose?) && !args.quiet? end - def json_version + def json_version(version) version_hash = { nil => nil, true => :default, @@ -164,9 +164,9 @@ module Homebrew "v2" => :v2, } - raise UsageError, "invalid JSON version: #{args.json}" unless version_hash.include? args.json + raise UsageError, "invalid JSON version: #{version}" unless version_hash.include?(version) - version_hash[args.json] + version_hash[version] end def outdated_formulae diff --git a/Library/Homebrew/cmd/pin.rb b/Library/Homebrew/cmd/pin.rb index 37acaed464..a86d4a448e 100644 --- a/Library/Homebrew/cmd/pin.rb +++ b/Library/Homebrew/cmd/pin.rb @@ -14,13 +14,13 @@ module Homebrew Pin the specified , preventing them from being upgraded when issuing the `brew upgrade` command. See also `unpin`. EOS - switch :debug + min_named :formula end end def pin - pin_args.parse + args = pin_args.parse args.resolved_formulae.each do |f| if f.pinned? diff --git a/Library/Homebrew/cmd/postinstall.rb b/Library/Homebrew/cmd/postinstall.rb index 762a97eb47..e0ac1d548c 100644 --- a/Library/Homebrew/cmd/postinstall.rb +++ b/Library/Homebrew/cmd/postinstall.rb @@ -14,8 +14,7 @@ module Homebrew Rerun the post-install steps for . EOS - switch :verbose - switch :debug + min_named :keg end end diff --git a/Library/Homebrew/cmd/readall.rb b/Library/Homebrew/cmd/readall.rb index 7a8a066aaa..a4f1d47a5d 100644 --- a/Library/Homebrew/cmd/readall.rb +++ b/Library/Homebrew/cmd/readall.rb @@ -20,13 +20,11 @@ module Homebrew description: "Verify any alias symlinks in each tap." switch "--syntax", description: "Syntax-check all of Homebrew's Ruby files (if no `` is passed)." - switch :verbose - switch :debug end end def readall - readall_args.parse + args = readall_args.parse if args.syntax? && args.no_named? scan_files = "#{HOMEBREW_LIBRARY_PATH}/**/*.rb" diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index ea1bca1ace..e70106f114 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -26,7 +26,7 @@ module Homebrew Unless `HOMEBREW_NO_INSTALL_CLEANUP` is set, `brew cleanup` will then be run for the reinstalled formulae or, every 30 days, for all formulae. EOS - switch :debug, + switch "-d", "--debug", description: "If brewing fails, open an interactive debugging session with access to IRB "\ "or a shell inside the temporary build directory." switch "-s", "--build-from-source", @@ -43,7 +43,7 @@ module Homebrew switch "-f", "--force", description: "Install without checking for previously installed keg-only or "\ "non-migrated versions." - switch :verbose, + switch "-v", "--verbose", description: "Print the verification and postinstall steps." switch "--display-times", env: :display_install_times, diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 4032e8ea07..5992c73aa5 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -51,14 +51,13 @@ module Homebrew switch s, description: "Search for in the given package manager's list." end - switch :verbose - switch :debug + conflicts(*package_manager_switches) end end def search - search_args.parse + args = search_args.parse if package_manager = PACKAGE_MANAGERS.find { |name,| args[:"#{name}?"] } _, url = package_manager diff --git a/Library/Homebrew/cmd/switch.rb b/Library/Homebrew/cmd/switch.rb index e9103565d3..06feb4badc 100644 --- a/Library/Homebrew/cmd/switch.rb +++ b/Library/Homebrew/cmd/switch.rb @@ -14,14 +14,13 @@ module Homebrew Symlink all of the specified of 's installation into Homebrew's prefix. EOS - switch :verbose - switch :debug + named 2 end end def switch - switch_args.parse + args = switch_args.parse name = args.named.first rack = Formulary.to_rack(name) diff --git a/Library/Homebrew/cmd/tap-info.rb b/Library/Homebrew/cmd/tap-info.rb index 9f3708bd1d..e7d1dbf791 100644 --- a/Library/Homebrew/cmd/tap-info.rb +++ b/Library/Homebrew/cmd/tap-info.rb @@ -20,12 +20,11 @@ module Homebrew description: "Print a JSON representation of . Currently the default and only accepted "\ "value for is `v1`. See the docs for examples of using the JSON "\ "output: " - switch :debug end end def tap_info - tap_info_args.parse + args = tap_info_args.parse taps = if args.installed? Tap diff --git a/Library/Homebrew/cmd/tap.rb b/Library/Homebrew/cmd/tap.rb index bdd396cae2..3dccb1da10 100644 --- a/Library/Homebrew/cmd/tap.rb +++ b/Library/Homebrew/cmd/tap.rb @@ -36,14 +36,13 @@ module Homebrew description: "Migrate tapped formulae from symlink-based to directory-based structure." switch "--list-pinned", description: "List all pinned taps." - switch :quiet - switch :debug + max_named 2 end end def tap - tap_args.parse + args = tap_args.parse if args.repair? Tap.each(&:link_completions_and_manpages) diff --git a/Library/Homebrew/cmd/uninstall.rb b/Library/Homebrew/cmd/uninstall.rb index bc1703acd3..be851d9e85 100644 --- a/Library/Homebrew/cmd/uninstall.rb +++ b/Library/Homebrew/cmd/uninstall.rb @@ -24,7 +24,7 @@ module Homebrew switch "--ignore-dependencies", description: "Don't fail uninstall, even if is a dependency of any installed "\ "formulae." - switch :debug + min_named :formula end end diff --git a/Library/Homebrew/cmd/unlink.rb b/Library/Homebrew/cmd/unlink.rb index 688d1bec59..e31bde919a 100644 --- a/Library/Homebrew/cmd/unlink.rb +++ b/Library/Homebrew/cmd/unlink.rb @@ -18,14 +18,13 @@ module Homebrew switch "-n", "--dry-run", description: "List files which would be unlinked without actually unlinking or "\ "deleting any files." - switch :verbose - switch :debug + min_named :keg end end def unlink - unlink_args.parse + args = unlink_args.parse mode = OpenStruct.new mode.dry_run = true if args.dry_run? diff --git a/Library/Homebrew/cmd/unpin.rb b/Library/Homebrew/cmd/unpin.rb index 4daed2ea06..0a346c967d 100644 --- a/Library/Homebrew/cmd/unpin.rb +++ b/Library/Homebrew/cmd/unpin.rb @@ -14,14 +14,13 @@ module Homebrew Unpin , allowing them to be upgraded by `brew upgrade` . See also `pin`. EOS - switch :verbose - switch :debug + min_named :formula end end def unpin - unpin_args.parse + args = unpin_args.parse args.resolved_formulae.each do |f| if f.pinned? diff --git a/Library/Homebrew/cmd/untap.rb b/Library/Homebrew/cmd/untap.rb index 7afb51c551..5209dd26c3 100644 --- a/Library/Homebrew/cmd/untap.rb +++ b/Library/Homebrew/cmd/untap.rb @@ -12,13 +12,13 @@ module Homebrew Remove a tapped formula repository. EOS - switch :debug + min_named 1 end end def untap - untap_args.parse + args = untap_args.parse args.named.each do |tapname| tap = Tap.fetch(tapname) diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index abe5cc1c75..260db68b59 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -30,9 +30,7 @@ module Homebrew switch "-f", "--force", description: "Treat installed and updated formulae as if they are from "\ "the same taps and migrate them anyway." - switch :quiet - switch :verbose - switch :debug + hide_from_man_page! end end diff --git a/Library/Homebrew/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index aa1a4c51e7..aeaac8669b 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -23,7 +23,7 @@ module Homebrew Unless `HOMEBREW_NO_INSTALL_CLEANUP` is set, `brew cleanup` will then be run for the upgraded formulae or, every 30 days, for all formulae. EOS - switch :debug, + switch "-d", "--debug", description: "If brewing fails, open an interactive debugging session with access to IRB "\ "or a shell inside the temporary build directory." switch "-s", "--build-from-source", @@ -46,7 +46,7 @@ module Homebrew switch "-f", "--force", description: "Install without checking for previously installed keg-only or "\ "non-migrated versions." - switch :verbose, + switch "-v", "--verbose", description: "Print the verification and postinstall steps." switch "--display-times", env: :display_install_times, @@ -71,7 +71,7 @@ module Homebrew named_casks_specified = !casks.empty? && formulae.empty? upgrade_outdated_formulae(formulae, args: args) unless named_casks_specified - upgrade_outdated_casks(casks) unless named_formulae_specified + upgrade_outdated_casks(casks, args: args) unless named_formulae_specified end def upgrade_outdated_formulae(formulae, args:) @@ -132,7 +132,7 @@ module Homebrew Homebrew.messages.display_messages(display_times: args.display_times?) end - def upgrade_outdated_casks(casks) + def upgrade_outdated_casks(casks, args:) cask_upgrade = Cask::Cmd::Upgrade.new(casks) cask_upgrade.force = args.force? cask_upgrade.dry_run = args.dry_run? diff --git a/Library/Homebrew/cmd/uses.rb b/Library/Homebrew/cmd/uses.rb index db8a89c20d..ceda3f9784 100644 --- a/Library/Homebrew/cmd/uses.rb +++ b/Library/Homebrew/cmd/uses.rb @@ -38,14 +38,14 @@ module Homebrew description: "Show usage of by development builds." switch "--HEAD", description: "Show usage of by HEAD builds." - switch :debug + conflicts "--devel", "--HEAD" min_named :formula end end def uses - uses_args.parse + args = uses_args.parse odeprecated "brew uses --devel" if args.devel? odeprecated "brew uses --HEAD" if args.HEAD? diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 0c4568cd94..c1e3ca5dbe 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -61,8 +61,7 @@ module Homebrew comma_array "--except-cops", description: "Specify a comma-separated list to skip checking for violations of the listed "\ "RuboCop cops." - switch :verbose - switch :debug + conflicts "--only", "--except" conflicts "--only-cops", "--except-cops", "--strict" conflicts "--only-cops", "--except-cops", "--only" diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 32cd4e2c6b..6fe8dcb0ef 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -76,15 +76,14 @@ module Homebrew "to the formula file." flag "--root-url=", description: "Use the specified as the root of the bottle's URL instead of Homebrew's default." - switch :verbose - switch :debug + conflicts "--no-rebuild", "--keep-old" min_named 1 end end def bottle - bottle_args.parse + args = bottle_args.parse return merge if args.merge? diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 0e8144dee6..ba3cc5a40a 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -65,9 +65,7 @@ module Homebrew description: "Specify the new git commit corresponding to the specified ." switch "-f", "--force", description: "Ignore duplicate open PRs. Remove all mirrors if --mirror= was not specified." - switch :quiet - switch :verbose - switch :debug + conflicts "--no-audit", "--strict" conflicts "--url", "--tag" max_named 1 @@ -111,7 +109,7 @@ module Homebrew end def bump_formula_pr - bump_formula_pr_args.parse + args = bump_formula_pr_args.parse # As this command is simplifying user-run commands then let's just use a # user path, too. diff --git a/Library/Homebrew/dev-cmd/bump-revision.rb b/Library/Homebrew/dev-cmd/bump-revision.rb index 9a14d661a5..2b71a91d7f 100644 --- a/Library/Homebrew/dev-cmd/bump-revision.rb +++ b/Library/Homebrew/dev-cmd/bump-revision.rb @@ -18,9 +18,7 @@ module Homebrew description: "Print what would be done rather than doing it." flag "--message=", description: "Append to the default commit message." - switch :quiet - switch :verbose - switch :debug + named :formula end end diff --git a/Library/Homebrew/dev-cmd/cat.rb b/Library/Homebrew/dev-cmd/cat.rb index 3bec5c5d99..1c3ee81176 100644 --- a/Library/Homebrew/dev-cmd/cat.rb +++ b/Library/Homebrew/dev-cmd/cat.rb @@ -17,7 +17,7 @@ module Homebrew end def cat - cat_args.parse + args = cat_args.parse cd HOMEBREW_REPOSITORY pager = if Homebrew::EnvConfig.bat? @@ -26,6 +26,6 @@ module Homebrew else "cat" end - safe_system pager, args.formulae_paths.first, *args.passthrough + safe_system pager, args.formulae_paths.first end end diff --git a/Library/Homebrew/dev-cmd/command.rb b/Library/Homebrew/dev-cmd/command.rb index e7c686288d..cb928bc577 100644 --- a/Library/Homebrew/dev-cmd/command.rb +++ b/Library/Homebrew/dev-cmd/command.rb @@ -13,14 +13,13 @@ module Homebrew Display the path to the file being used when invoking `brew` . EOS - switch :verbose - switch :debug + min_named 1 end end def command - command_args.parse + args = command_args.parse args.named.each do |cmd| path = Commands.path(cmd) diff --git a/Library/Homebrew/dev-cmd/create.rb b/Library/Homebrew/dev-cmd/create.rb index d659bf5bdb..85b2f857e7 100644 --- a/Library/Homebrew/dev-cmd/create.rb +++ b/Library/Homebrew/dev-cmd/create.rb @@ -56,8 +56,7 @@ module Homebrew description: "Generate the new formula within the given tap, specified as `/`." switch "-f", "--force", description: "Ignore errors for disallowed formula names and named that shadow aliases." - switch :verbose - switch :debug + conflicts "--autotools", "--cmake", "--crystal", "--go", "--meson", "--node", "--perl", "--python", "--rust" named 1 end diff --git a/Library/Homebrew/dev-cmd/diy.rb b/Library/Homebrew/dev-cmd/diy.rb index 51a7ff4c26..f58ae2fa9c 100644 --- a/Library/Homebrew/dev-cmd/diy.rb +++ b/Library/Homebrew/dev-cmd/diy.rb @@ -19,14 +19,13 @@ module Homebrew description: "Explicitly set the of the package being installed." flag "--version=", description: "Explicitly set the of the package being installed." - switch :verbose - switch :debug + max_named 0 end end def diy - diy_args.parse + args = diy_args.parse path = Pathname.getwd diff --git a/Library/Homebrew/dev-cmd/edit.rb b/Library/Homebrew/dev-cmd/edit.rb index 25ee7cc91f..7b23a6a20a 100644 --- a/Library/Homebrew/dev-cmd/edit.rb +++ b/Library/Homebrew/dev-cmd/edit.rb @@ -14,13 +14,11 @@ module Homebrew Open in the editor set by `EDITOR` or `HOMEBREW_EDITOR`, or open the Homebrew repository for editing if no formula is provided. EOS - switch :verbose - switch :debug end end def edit - edit_args.parse + args = edit_args.parse unless (HOMEBREW_REPOSITORY/".git").directory? raise <<~EOS diff --git a/Library/Homebrew/dev-cmd/extract.rb b/Library/Homebrew/dev-cmd/extract.rb index 7bc6e9e322..9eb432a17c 100644 --- a/Library/Homebrew/dev-cmd/extract.rb +++ b/Library/Homebrew/dev-cmd/extract.rb @@ -91,13 +91,13 @@ module Homebrew description: "Extract the specified of instead of the most recent." switch "-f", "--force", description: "Overwrite the destination formula if it already exists." - switch :debug + named 2 end end def extract - extract_args.parse + args = extract_args.parse if args.named.first !~ HOMEBREW_TAP_FORMULA_REGEX name = args.named.first.downcase diff --git a/Library/Homebrew/dev-cmd/formula.rb b/Library/Homebrew/dev-cmd/formula.rb index 8a782ee4e8..664db4c5e0 100644 --- a/Library/Homebrew/dev-cmd/formula.rb +++ b/Library/Homebrew/dev-cmd/formula.rb @@ -13,14 +13,13 @@ module Homebrew Display the path where is located. EOS - switch :verbose - switch :debug + min_named :formula end end def formula - formula_args.parse + args = formula_args.parse args.formulae_paths.each(&method(:puts)) end diff --git a/Library/Homebrew/dev-cmd/install-bundler-gems.rb b/Library/Homebrew/dev-cmd/install-bundler-gems.rb index 66aeb1087d..20ba27eb71 100644 --- a/Library/Homebrew/dev-cmd/install-bundler-gems.rb +++ b/Library/Homebrew/dev-cmd/install-bundler-gems.rb @@ -13,7 +13,7 @@ module Homebrew Install Homebrew's Bundler gems. EOS - switch :debug + max_named 0 end end diff --git a/Library/Homebrew/dev-cmd/irb.rb b/Library/Homebrew/dev-cmd/irb.rb index e748e6fa19..2f1976e61d 100644 --- a/Library/Homebrew/dev-cmd/irb.rb +++ b/Library/Homebrew/dev-cmd/irb.rb @@ -19,7 +19,7 @@ module Homebrew def irb_args # work around IRB modifying ARGV. - Homebrew::CLI::Parser.new(ARGV.dup.freeze) do + Homebrew::CLI::Parser.new do usage_banner <<~EOS `irb` [] @@ -34,7 +34,7 @@ module Homebrew end def irb - irb_args.parse + args = irb_args.parse if args.examples? puts "'v8'.f # => instance of the v8 formula" @@ -56,6 +56,8 @@ module Homebrew require "keg" require "cask/all" + puts ARGV.inspect + ohai "Interactive Homebrew Shell" puts "Example commands available with: brew irb --examples" if args.pry? diff --git a/Library/Homebrew/dev-cmd/linkage.rb b/Library/Homebrew/dev-cmd/linkage.rb index ddd542c94d..47258dfab1 100644 --- a/Library/Homebrew/dev-cmd/linkage.rb +++ b/Library/Homebrew/dev-cmd/linkage.rb @@ -24,13 +24,11 @@ module Homebrew switch "--cached", description: "Print the cached linkage values stored in `HOMEBREW_CACHE`, set by a previous "\ "`brew linkage` run." - switch :verbose - switch :debug end end def linkage - linkage_args.parse + args = linkage_args.parse CacheStoreDatabase.use(:linkage) do |db| kegs = if args.kegs.empty? diff --git a/Library/Homebrew/dev-cmd/man.rb b/Library/Homebrew/dev-cmd/man.rb index 92f1a88599..295424fd52 100644 --- a/Library/Homebrew/dev-cmd/man.rb +++ b/Library/Homebrew/dev-cmd/man.rb @@ -169,7 +169,7 @@ module Homebrew def cmd_parser_manpage_lines(cmd_parser) lines = [format_usage_banner(cmd_parser.usage_banner_text)] lines += cmd_parser.processed_options.map do |short, long, _, desc| - next if !long.nil? && cmd_parser.global_option?(cmd_parser.option_to_name(long), desc) + next if !long.nil? && Homebrew::CLI::Parser.global_options.include?([short, long, desc]) generate_option_doc(short, long, desc) end.reject(&:blank?) @@ -191,7 +191,7 @@ module Homebrew end # Omit the common global_options documented separately in the man page. - next if line.match?(/--(debug|force|help|quiet|verbose) /) + next if line.match?(/--(debug|help|quiet|verbose) /) # Format one option or a comma-separated pair of short and long options. lines << line.gsub(/^ +(-+[a-z-]+), (-+[a-z-]+) +/, "* `\\1`, `\\2`:\n ") @@ -203,8 +203,7 @@ module Homebrew def global_options_manpage lines = ["These options are applicable across multiple subcommands.\n"] - lines += Homebrew::CLI::Parser.global_options.values.map do |names, _, desc| - short, long = names + lines += Homebrew::CLI::Parser.global_options.map do |short, long, desc| generate_option_doc(short, long, desc) end lines.join("\n") diff --git a/Library/Homebrew/dev-cmd/mirror.rb b/Library/Homebrew/dev-cmd/mirror.rb index 851ad476a9..832707227a 100644 --- a/Library/Homebrew/dev-cmd/mirror.rb +++ b/Library/Homebrew/dev-cmd/mirror.rb @@ -19,8 +19,7 @@ module Homebrew description: "Upload to the specified Bintray repository (default: `mirror`)." switch "--no-publish", description: "Upload to Bintray, but don't publish." - switch :verbose - switch :debug + hide_from_man_page! min_named :formula end diff --git a/Library/Homebrew/dev-cmd/pr-automerge.rb b/Library/Homebrew/dev-cmd/pr-automerge.rb index 62c6db0395..24ed7f5d3d 100644 --- a/Library/Homebrew/dev-cmd/pr-automerge.rb +++ b/Library/Homebrew/dev-cmd/pr-automerge.rb @@ -25,8 +25,7 @@ module Homebrew description: "Run `brew pr-publish` on matching pull requests." switch "--ignore-failures", description: "Include pull requests that have failing status checks." - switch :verbose - switch :debug + max_named 0 end end diff --git a/Library/Homebrew/dev-cmd/pr-publish.rb b/Library/Homebrew/dev-cmd/pr-publish.rb index 68177b0c13..741a8ec011 100644 --- a/Library/Homebrew/dev-cmd/pr-publish.rb +++ b/Library/Homebrew/dev-cmd/pr-publish.rb @@ -18,13 +18,13 @@ module Homebrew description: "Target tap repository (default: `homebrew/core`)." flag "--workflow=", description: "Target workflow filename (default: `publish-commit-bottles.yml`)." - switch :verbose + min_named 1 end end def pr_publish - pr_publish_args.parse + args = pr_publish_args.parse tap = Tap.fetch(Homebrew.args.tap || CoreTap.instance.name) workflow = Homebrew.args.workflow || "publish-commit-bottles.yml" diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index 6a672e4119..ab2a23ebdf 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -49,8 +49,7 @@ module Homebrew flag "--bintray-mirror=", description: "Use the specified Bintray repository to automatically mirror stable URLs "\ "defined in the formulae (default: `mirror`)." - switch :verbose - switch :debug + min_named 1 end end diff --git a/Library/Homebrew/dev-cmd/pr-upload.rb b/Library/Homebrew/dev-cmd/pr-upload.rb index 64cae02ea4..aa83627f63 100644 --- a/Library/Homebrew/dev-cmd/pr-upload.rb +++ b/Library/Homebrew/dev-cmd/pr-upload.rb @@ -27,8 +27,6 @@ module Homebrew description: "Upload to the specified Bintray organisation (default: `homebrew`)." flag "--root-url=", description: "Use the specified as the root of the bottle's URL instead of Homebrew's default." - switch :verbose - switch :debug end end diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index 19318c24e9..d35a42641a 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -37,8 +37,7 @@ module Homebrew description: "Do not warn if pulling to a branch besides master (useful for testing)." switch "--no-pbcopy", description: "Do not copy anything to the system clipboard." - switch :verbose - switch :debug + min_named 1 end end @@ -48,7 +47,7 @@ module Homebrew odie "You meant `git pull --rebase`." if ARGV[0] == "--rebase" - pull_args.parse + args = pull_args.parse # Passthrough Git environment variables for e.g. git am Utils.set_git_name_email!(author: false, committer: true) diff --git a/Library/Homebrew/dev-cmd/release-notes.rb b/Library/Homebrew/dev-cmd/release-notes.rb index fa537cf096..76266028c3 100644 --- a/Library/Homebrew/dev-cmd/release-notes.rb +++ b/Library/Homebrew/dev-cmd/release-notes.rb @@ -21,7 +21,7 @@ module Homebrew end def release_notes - release_notes_args.parse + args = release_notes_args.parse previous_tag = args.named.first previous_tag ||= Utils.popen_read( diff --git a/Library/Homebrew/dev-cmd/ruby.rb b/Library/Homebrew/dev-cmd/ruby.rb index 735fdb7c9a..1c2f3239ea 100644 --- a/Library/Homebrew/dev-cmd/ruby.rb +++ b/Library/Homebrew/dev-cmd/ruby.rb @@ -17,8 +17,6 @@ module Homebrew description: "Load a library using `require`." switch "-e", description: "Execute the given text string as a script." - switch :verbose - switch :debug end end diff --git a/Library/Homebrew/dev-cmd/sh.rb b/Library/Homebrew/dev-cmd/sh.rb index e44a617fcc..5247cbea66 100644 --- a/Library/Homebrew/dev-cmd/sh.rb +++ b/Library/Homebrew/dev-cmd/sh.rb @@ -20,8 +20,7 @@ module Homebrew EOS flag "--env=", description: "Use the standard `PATH` instead of superenv's when `std` is passed." - switch :verbose - switch :debug + max_named 0 end end diff --git a/Library/Homebrew/dev-cmd/style.rb b/Library/Homebrew/dev-cmd/style.rb index a38f5b2363..7bb6fe8e75 100644 --- a/Library/Homebrew/dev-cmd/style.rb +++ b/Library/Homebrew/dev-cmd/style.rb @@ -29,14 +29,13 @@ module Homebrew comma_array "--except-cops", description: "Specify a comma-separated list to skip checking for violations of the "\ "listed RuboCop cops." - switch :verbose - switch :debug + conflicts "--only-cops", "--except-cops" end end def style - style_args.parse + args = style_args.parse target = if args.no_named? nil diff --git a/Library/Homebrew/dev-cmd/tap-new.rb b/Library/Homebrew/dev-cmd/tap-new.rb index 2e75d05515..3506e55dbe 100644 --- a/Library/Homebrew/dev-cmd/tap-new.rb +++ b/Library/Homebrew/dev-cmd/tap-new.rb @@ -13,14 +13,13 @@ module Homebrew Generate the template files for a new tap. EOS - switch :verbose - switch :debug + named 1 end end def tap_new - tap_new_args.parse + args = tap_new_args.parse tap_name = args.named.first tap = Tap.fetch(args.named.first) diff --git a/Library/Homebrew/dev-cmd/test.rb b/Library/Homebrew/dev-cmd/test.rb index 0a2e5b452c..dca26921ed 100644 --- a/Library/Homebrew/dev-cmd/test.rb +++ b/Library/Homebrew/dev-cmd/test.rb @@ -27,15 +27,14 @@ module Homebrew description: "Retain the temporary files created for the test." switch "--retry", description: "Retry if a testing fails." - switch :verbose - switch :debug + conflicts "--devel", "--HEAD" min_named :formula end end def test - test_args.parse + args = test_args.parse require "formula_assertions" require "formula_free_port" diff --git a/Library/Homebrew/dev-cmd/tests.rb b/Library/Homebrew/dev-cmd/tests.rb index e2facbfa5b..8025ffda3e 100644 --- a/Library/Homebrew/dev-cmd/tests.rb +++ b/Library/Homebrew/dev-cmd/tests.rb @@ -29,14 +29,13 @@ module Homebrew "specific line." flag "--seed=", description: "Randomise tests with the specified instead of a random seed." - switch :verbose - switch :debug + max_named 0 end end def tests - tests_args.parse + args = tests_args.parse Homebrew.install_bundler_gems! gem_user_dir = Gem.user_dir diff --git a/Library/Homebrew/dev-cmd/unpack.rb b/Library/Homebrew/dev-cmd/unpack.rb index 1f1360bc25..2fa824d422 100644 --- a/Library/Homebrew/dev-cmd/unpack.rb +++ b/Library/Homebrew/dev-cmd/unpack.rb @@ -24,15 +24,14 @@ module Homebrew "patches for the software." switch "-f", "--force", description: "Overwrite the destination directory if it already exists." - switch :verbose - switch :debug + conflicts "--git", "--patch" min_named :formula end end def unpack - unpack_args.parse + args = unpack_args.parse formulae = args.formulae diff --git a/Library/Homebrew/dev-cmd/update-license-data.rb b/Library/Homebrew/dev-cmd/update-license-data.rb index 456a7b38ec..40584b3b4b 100644 --- a/Library/Homebrew/dev-cmd/update-license-data.rb +++ b/Library/Homebrew/dev-cmd/update-license-data.rb @@ -26,7 +26,7 @@ module Homebrew end def update_license_data - update_license_data_args.parse + args = update_license_data_args.parse ohai "Updating SPDX license data..." latest_tag = GitHub.open_api(SPDX_API_URL)["tag_name"] diff --git a/Library/Homebrew/dev-cmd/update-test.rb b/Library/Homebrew/dev-cmd/update-test.rb index fdf208dd49..d05f445ea5 100644 --- a/Library/Homebrew/dev-cmd/update-test.rb +++ b/Library/Homebrew/dev-cmd/update-test.rb @@ -21,14 +21,13 @@ module Homebrew description: "Use the specified as the start commit." flag "--before=", description: "Use the commit at the specified as the start commit." - switch :verbose - switch :debug + max_named 0 end end def update_test - update_test_args.parse + args = update_test_args.parse ENV["HOMEBREW_UPDATE_TEST"] = "1" diff --git a/Library/Homebrew/dev-cmd/vendor-gems.rb b/Library/Homebrew/dev-cmd/vendor-gems.rb index 428223e38a..d702e7df69 100644 --- a/Library/Homebrew/dev-cmd/vendor-gems.rb +++ b/Library/Homebrew/dev-cmd/vendor-gems.rb @@ -13,7 +13,7 @@ module Homebrew Install and commit Homebrew's vendored gems. EOS - switch :debug + max_named 0 end end diff --git a/Library/Homebrew/help.rb b/Library/Homebrew/help.rb index 57196edf7c..d868c9c828 100644 --- a/Library/Homebrew/help.rb +++ b/Library/Homebrew/help.rb @@ -40,30 +40,30 @@ module Homebrew module Help module_function - def help(cmd = nil, flags = {}) - # Resolve command aliases and find file containing the implementation. - path = Commands.path(cmd) if cmd - - # Display command-specific (or generic) help in response to `UsageError`. - if (error_message = flags[:usage_error]) - $stderr.puts path ? command_help(cmd, path) : HOMEBREW_HELP - $stderr.puts - onoe error_message - exit 1 - end - - # Handle `brew` (no arguments). - if flags[:empty_argv] - $stderr.puts HOMEBREW_HELP - exit 1 - end - - # Handle `brew (-h|--help|--usage|-?|help)` (no other arguments). + def help(cmd = nil, empty_argv: false, usage_error: nil) if cmd.nil? + # Handle `brew` (no arguments). + if empty_argv + $stderr.puts HOMEBREW_HELP + exit 1 + end + + # Handle `brew (-h|--help|--usage|-?|help)` (no other arguments). puts HOMEBREW_HELP exit 0 end + # Resolve command aliases and find file containing the implementation. + path = Commands.path(cmd) + + # Display command-specific (or generic) help in response to `UsageError`. + if usage_error + $stderr.puts path ? command_help(cmd, path) : HOMEBREW_HELP + $stderr.puts + onoe usage_error + exit 1 + end + # Resume execution in `brew.rb` for unknown commands. return if path.nil? diff --git a/Library/Homebrew/test/cli/parser_spec.rb b/Library/Homebrew/test/cli/parser_spec.rb index 0c3a90084d..a54a3d4c43 100644 --- a/Library/Homebrew/test/cli/parser_spec.rb +++ b/Library/Homebrew/test/cli/parser_spec.rb @@ -6,7 +6,6 @@ describe Homebrew::CLI::Parser do describe "test switch options" do subject(:parser) { described_class.new do - switch :verbose, description: "Flag for verbosity" switch "--more-verbose", description: "Flag for higher verbosity" switch "--pry", env: :pry end @@ -17,26 +16,25 @@ describe Homebrew::CLI::Parser do end it "parses short option" do - parser.parse(["-v"]) - expect(Homebrew.args).to be_verbose + args = parser.parse(["-v"]) + expect(args).to be_verbose end it "parses a single valid option" do - parser.parse(["--verbose"]) - expect(Homebrew.args).to be_verbose + args = parser.parse(["--verbose"]) + expect(args).to be_verbose end it "parses a valid option along with few unnamed args" do - args = %w[--verbose unnamed args] - parser.parse(args) - expect(Homebrew.args).to be_verbose - expect(args).to eq %w[--verbose unnamed args] + args = parser.parse(%w[--verbose unnamed args]) + expect(args).to be_verbose + expect(args.named).to eq %w[unnamed args] end it "parses a single option and checks other options to be nil" do - parser.parse(["--verbose"]) - expect(Homebrew.args).to be_verbose - expect(Homebrew.args.more_verbose?).to be nil + args = parser.parse(["--verbose"]) + expect(args).to be_verbose + expect(args.more_verbose?).to be nil end it "raises an exception and outputs help text when an invalid option is passed" do @@ -45,13 +43,8 @@ describe Homebrew::CLI::Parser do end it "maps environment var to an option" do - parser.parse([]) - expect(Homebrew.args.pry?).to be true - end - - it ":verbose with custom description" do - _, _, _, desc = parser.processed_options.find { |short, _| short == "-v" } - expect(desc).to eq "Flag for verbosity" + args = parser.parse([]) + expect(args.pry?).to be true end end @@ -64,8 +57,8 @@ describe Homebrew::CLI::Parser do } it "parses a long flag option with its argument" do - parser.parse(["--filename=random.txt"]) - expect(Homebrew.args.filename).to eq "random.txt" + args = parser.parse(["--filename=random.txt"]) + expect(args.filename).to eq "random.txt" end it "raises an exception when a flag's required value is not passed" do @@ -73,8 +66,8 @@ describe Homebrew::CLI::Parser do end it "parses a comma array flag option" do - parser.parse(["--files=random1.txt,random2.txt"]) - expect(Homebrew.args.files).to eq %w[random1.txt random2.txt] + args = parser.parse(["--files=random1.txt,random2.txt"]) + expect(args.files).to eq %w[random1.txt random2.txt] end end @@ -86,9 +79,9 @@ describe Homebrew::CLI::Parser do } it "parses a short flag option with its argument" do - parser.parse(["--filename=random.txt"]) - expect(Homebrew.args.filename).to eq "random.txt" - expect(Homebrew.args.f).to eq "random.txt" + args = parser.parse(["--filename=random.txt"]) + expect(args.filename).to eq "random.txt" + expect(args.f).to eq "random.txt" end end @@ -118,14 +111,14 @@ describe Homebrew::CLI::Parser do end it "raises no exception" do - parser.parse(["--flag1=flag1", "--flag2=flag2"]) - expect(Homebrew.args.flag1).to eq "flag1" - expect(Homebrew.args.flag2).to eq "flag2" + args = parser.parse(["--flag1=flag1", "--flag2=flag2"]) + expect(args.flag1).to eq "flag1" + expect(args.flag2).to eq "flag2" end it "raises no exception for optional dependency" do - parser.parse(["--flag3=flag3"]) - expect(Homebrew.args.flag3).to eq "flag3" + args = parser.parse(["--flag3=flag3"]) + expect(args.flag3).to eq "flag3" end end @@ -169,22 +162,22 @@ describe Homebrew::CLI::Parser do end it "raises no exception" do - parser.parse(["--switch-a", "--switch-c"]) - expect(Homebrew.args.switch_a?).to be true - expect(Homebrew.args.switch_c?).to be true + args = parser.parse(["--switch-a", "--switch-c"]) + expect(args.switch_a?).to be true + expect(args.switch_c?).to be true end it "raises no exception for optional dependency" do - parser.parse(["--switch-b"]) - expect(Homebrew.args.switch_b?).to be true + args = parser.parse(["--switch-b"]) + expect(args.switch_b?).to be true end it "prioritizes cli arguments over env vars when they conflict" do allow(Homebrew::EnvConfig).to receive(:switch_a?).and_return(true) allow(Homebrew::EnvConfig).to receive(:switch_b?).and_return(false) - parser.parse(["--switch-b"]) - expect(Homebrew.args.switch_a).to be_falsy - expect(Homebrew.args).to be_switch_b + args = parser.parse(["--switch-b"]) + expect(args.switch_a).to be_falsy + expect(args).to be_switch_b end it "raises an exception on constraint violation when both are env vars" do @@ -214,38 +207,32 @@ describe Homebrew::CLI::Parser do switch "--foo" flag "--bar" switch "-s" - switch :verbose end } it "#options_only" do - parser.parse(["--foo", "--bar=value", "-v", "-s", "a", "b", "cdefg"]) - expect(Homebrew.args.options_only).to eq %w[--foo --bar=value -s --verbose] + args = parser.parse(["--foo", "--bar=value", "-v", "-s", "a", "b", "cdefg"]) + expect(args.options_only).to eq %w[--verbose --foo --bar=value -s] end it "#flags_only" do - parser.parse(["--foo", "--bar=value", "-v", "-s", "a", "b", "cdefg"]) - expect(Homebrew.args.flags_only).to eq %w[--foo --bar=value --verbose] - end - - it "#passthrough" do - parser.parse(["--foo", "--bar=value", "-v", "-s", "a", "b", "cdefg"]) - expect(Homebrew.args.passthrough).to eq %w[--foo --bar=value -s] + args = parser.parse(["--foo", "--bar=value", "-v", "-s", "a", "b", "cdefg"]) + expect(args.flags_only).to eq %w[--verbose --foo --bar=value] end it "#formulae raises an error when a Formula is unavailable" do - parser.parse(["mxcl"]) - expect { Homebrew.args.formulae }.to raise_error FormulaUnavailableError + args = parser.parse(["mxcl"]) + expect { args.formulae }.to raise_error FormulaUnavailableError end it "#formulae returns an empty array when there are no Formulae" do - parser.parse([]) - expect(Homebrew.args.formulae).to be_empty + args = parser.parse([]) + expect(args.formulae).to be_empty end it "#casks returns an empty array when there are no matching casks" do - parser.parse([]) - expect(Homebrew.args.casks).to eq [] + args = parser.parse([]) + expect(args.casks).to eq [] end context "kegs" do @@ -255,24 +242,24 @@ describe Homebrew::CLI::Parser do end it "when there are matching kegs returns an array of Kegs" do - parser.parse(["mxcl"]) - expect(Homebrew.args.kegs.length).to eq 1 + args = parser.parse(["mxcl"]) + expect(args.kegs.length).to eq 1 end it "when there are no matching kegs returns an array of Kegs" do - parser.parse([]) - expect(Homebrew.args.kegs).to be_empty + args = parser.parse([]) + expect(args.kegs).to be_empty end end it "#named returns an array of non-option arguments" do - parser.parse(["foo", "-v", "-s"]) - expect(Homebrew.args.named).to eq ["foo"] + args = parser.parse(["foo", "-v", "-s"]) + expect(args.named).to eq ["foo"] end it "#named returns an empty array when there are no named arguments" do - parser.parse([]) - expect(Homebrew.args.named).to be_empty + args = parser.parse([]) + expect(args.named).to be_empty end end end diff --git a/Library/Homebrew/test/cmd/shared_examples/args_parse.rb b/Library/Homebrew/test/cmd/shared_examples/args_parse.rb index c9e8cc1d80..d8b7873b80 100644 --- a/Library/Homebrew/test/cmd/shared_examples/args_parse.rb +++ b/Library/Homebrew/test/cmd/shared_examples/args_parse.rb @@ -14,7 +14,8 @@ shared_examples "parseable arguments" do it "can parse arguments" do require "dev-cmd/#{command_name}" unless require? "cmd/#{command_name}" - expect { Homebrew.send(method_name).parse({}, allow_no_named_args: true) } - .not_to raise_error + parser = Homebrew.public_send(method_name) + + expect(parser).to respond_to(:parse) end end diff --git a/Library/Homebrew/test/formula_installer_bottle_spec.rb b/Library/Homebrew/test/formula_installer_bottle_spec.rb index 87842ff27b..0a6aec0f0b 100644 --- a/Library/Homebrew/test/formula_installer_bottle_spec.rb +++ b/Library/Homebrew/test/formula_installer_bottle_spec.rb @@ -50,7 +50,7 @@ describe FormulaInstaller do specify "basic bottle install" do allow(DevelopmentTools).to receive(:installed?).and_return(false) - Homebrew.install_args.parse("testball_bottle") + Homebrew.install_args.parse(["testball_bottle"]) temporarily_install_bottle(TestballBottle.new) do |f| # Copied directly from formula_installer_spec.rb # as we expect the same behavior. diff --git a/docs/Manpage.md b/docs/Manpage.md index aa331bfb4c..0a82a3a035 100644 --- a/docs/Manpage.md +++ b/docs/Manpage.md @@ -525,6 +525,8 @@ Fetch the newest version of Homebrew and all formulae from GitHub using `git`(1) Use `git merge` to apply updates (rather than `git rebase`). * `--preinstall`: Run on auto-updates (e.g. before `brew install`). Skips some slower steps. +* `-f`, `--force`: + Always do a slower, full update check (even if unnecessary). ### `update-reset` [*`repository`*] @@ -1190,8 +1192,6 @@ flags which will help find keg-only dependencies like `openssl`, `icu4c`, etc. Read the `Brewfile` from this location. Use `--file=-` to pipe to stdin/stdout. * `--global`: Read the `Brewfile` from `~/.Brewfile`. -* `-v`, `--verbose`: - `install` prints output from commands as they are run. `check` lists all missing dependencies. * `--no-upgrade`: `install` won't run `brew upgrade` on outdated dependencies. Note they may still be upgraded by `brew install` if needed. * `-f`, `--force`: diff --git a/manpages/brew.1 b/manpages/brew.1 index 52aa949546..ca4926fff2 100644 --- a/manpages/brew.1 +++ b/manpages/brew.1 @@ -682,6 +682,10 @@ Use \fBgit merge\fR to apply updates (rather than \fBgit rebase\fR)\. \fB\-\-preinstall\fR Run on auto\-updates (e\.g\. before \fBbrew install\fR)\. Skips some slower steps\. . +.TP +\fB\-f\fR, \fB\-\-force\fR +Always do a slower, full update check (even if unnecessary)\. +. .SS "\fBupdate\-reset\fR [\fIrepository\fR]" Fetch and reset Homebrew and all tap repositories (or any specified \fIrepository\fR) using \fBgit\fR(1) to their latest \fBorigin/master\fR\. . @@ -1535,10 +1539,6 @@ Read the \fBBrewfile\fR from this location\. Use \fB\-\-file=\-\fR to pipe to st Read the \fBBrewfile\fR from \fB~/\.Brewfile\fR\. . .TP -\fB\-v\fR, \fB\-\-verbose\fR -\fBinstall\fR prints output from commands as they are run\. \fBcheck\fR lists all missing dependencies\. -. -.TP \fB\-\-no\-upgrade\fR \fBinstall\fR won\'t run \fBbrew upgrade\fR on outdated dependencies\. Note they may still be upgraded by \fBbrew install\fR if needed\. .