Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch: Use CLI::Parser to parse args #5559

Merged
merged 2 commits into from
Jan 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Library/Homebrew/cli_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 17 additions & 3 deletions Library/Homebrew/cmd/switch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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>"

Expand All @@ -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
Expand Down