From 536c963274b73e5542aecad1ef40e12765597004 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 6 Aug 2020 16:14:07 +0200 Subject: [PATCH] Deprecate global `Homebrew.args`. --- Library/Homebrew/compat.rb | 2 ++ Library/Homebrew/compat/cli/parser.rb | 32 +++++++++++++++++++ .../Homebrew/compat/dependencies_helpers.rb | 17 ++++++++++ 3 files changed, 51 insertions(+) create mode 100644 Library/Homebrew/compat/cli/parser.rb create mode 100644 Library/Homebrew/compat/dependencies_helpers.rb diff --git a/Library/Homebrew/compat.rb b/Library/Homebrew/compat.rb index bc254d9e1c..d14810694a 100644 --- a/Library/Homebrew/compat.rb +++ b/Library/Homebrew/compat.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "compat/dependencies_helpers" +require "compat/cli/parser" require "compat/extend/nil" require "compat/extend/string" require "compat/formula" diff --git a/Library/Homebrew/compat/cli/parser.rb b/Library/Homebrew/compat/cli/parser.rb new file mode 100644 index 0000000000..fccec61a62 --- /dev/null +++ b/Library/Homebrew/compat/cli/parser.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module Homebrew + module CLI + class Parser + module Compat + module DeprecatedArgs + def respond_to_missing?(*) + super + end + + def method_missing(method, *) + if ![:debug?, :quiet?, :verbose?].include?(method) && !@printed_args_warning + odeprecated "Homebrew.args", "`args = _args.parse` and pass `args` along the call chain" + @printed_args_warning = true + end + + super + end + end + + def parse(*) + args = super + Homebrew.args = args.dup.extend(DeprecatedArgs) + args + end + end + + prepend Compat + end + end +end diff --git a/Library/Homebrew/compat/dependencies_helpers.rb b/Library/Homebrew/compat/dependencies_helpers.rb new file mode 100644 index 0000000000..095c891011 --- /dev/null +++ b/Library/Homebrew/compat/dependencies_helpers.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require "cli/args" + +module DependenciesHelpers + module Compat + def argv_includes_ignores(argv = nil) + unless @printed_includes_ignores_warning + odeprecated "Homebrew.argv_includes_ignores", "Homebrew.args_includes_ignores" + @printed_includes_ignores_warning = true + end + args_includes_ignores(argv ? Homebrew::CLI::Args.new : Homebrew.args) + end + end + + prepend Compat +end