From 1748b66615a9bae93303d10c1224ee76d9931cf3 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Fri, 18 Jan 2019 22:03:07 +0530 Subject: [PATCH 1/2] Add alias for `switch` method in CLI::Parser --- Library/Homebrew/cli_parser.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/cli_parser.rb b/Library/Homebrew/cli_parser.rb index 01310d42e3f18..da63133dfbb4e 100644 --- a/Library/Homebrew/cli_parser.rb +++ b/Library/Homebrew/cli_parser.rb @@ -59,6 +59,7 @@ def switch(*names, description: nil, env: nil, required_for: nil, depends_on: ni enable_switch(*names) if !env.nil? && !ENV["HOMEBREW_#{env.to_s.upcase}"].nil? end + alias switch_option switch def usage_banner(text) @parser.banner = "#{text}\n" From f7689b381efd84d19f8ea741e2629b2cb95988d0 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Fri, 18 Jan 2019 22:03:30 +0530 Subject: [PATCH 2/2] switch: Use CLI::Parser to parse args --- Library/Homebrew/cmd/switch.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/cmd/switch.rb b/Library/Homebrew/cmd/switch.rb index bf22f484a578a..7bcc295a4d6ed 100644 --- a/Library/Homebrew/cmd/switch.rb +++ b/Library/Homebrew/cmd/switch.rb @@ -3,12 +3,26 @@ require "formula" require "keg" +require "cli_parser" module Homebrew module_function + def switch_args + Homebrew::CLI::Parser.new do + usage_banner <<~EOS + `switch` + + Symlink all of the specific of 's install to Homebrew prefix. + EOS + switch_option :verbose + switch_option :debug + end + end + def switch - name = ARGV.first + switch_args.parse + name = args.remaining.first usage = "Usage: brew switch " @@ -28,9 +42,9 @@ def switch .map { |d| Keg.new(d).version } .sort .join(", ") - version = ARGV.second + version = args.remaining.second - if !version || ARGV.named.length > 2 + if !version || args.remaining.length > 2 onoe usage puts "#{name} installed versions: #{versions}" exit 1