Merge pull request #5559 from GauthamGoli/switch-args
switch: Use CLI::Parser to parse args
This commit is contained in:
commit
f4dff6bcff
@ -59,6 +59,7 @@ module Homebrew
|
||||
|
||||
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"
|
||||
|
||||
@ -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` <formula> <version>
|
||||
|
||||
Symlink all of the specific <version> of <formula>'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 <formula> <version>"
|
||||
|
||||
@ -28,9 +42,9 @@ module Homebrew
|
||||
.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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user