56 lines
1.3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "ostruct"
module Homebrew
module CLI
class Args < OpenStruct
attr_accessor :processed_options
# undefine tap to allow --tap argument
undef tap
def initialize(argv:)
super
@argv = argv
@processed_options = []
end
def option_to_name(option)
option.sub(/\A--?/, "")
.tr("-", "_")
end
def cli_args
2019-09-25 14:21:06 +05:30
return @cli_args if @cli_args
@cli_args = []
processed_options.each do |short, long|
option = long || short
switch = "#{option_to_name(option)}?".to_sym
flag = option_to_name(option).to_sym
2019-09-25 14:21:06 +05:30
if @table[switch] == true || @table[flag] == true
@cli_args << option
elsif @table[flag].instance_of? String
@cli_args << option + "=" + @table[flag]
elsif @table[flag].instance_of? Array
@cli_args << option + "=" + @table[flag].join(",")
end
end
@cli_args
end
def options_only
@options_only ||= cli_args.select { |arg| arg.start_with?("-") }
end
def flags_only
@flags_only ||= cli_args.select { |arg| arg.start_with?("--") }
end
2019-09-25 14:21:06 +05:30
def passthrough
options_only - CLI::Parser.global_options.values.map(&:first).flatten
end
end
end
end