lib/command_lion/raw.rb in command_lion-1.0.4 vs lib/command_lion/raw.rb in command_lion-2.0.0

- old
+ new

@@ -1,30 +1,61 @@ module CommandLion + # Raw command-line option API module Raw - def self.index_of(string) - ARGV.index(string) + @arguments = ARGV + + def self.arguments + return @arguments unless block_given? + @arguments.each do |argument| + yield argument + end end + def self.arguments=(args) + @arguments = args + end + + def self.arguments? + arguments.size > 0 ? true : false + end + + def self.index_of(flag) + arguments.index(flag) + end + + def self.index_of?(flag) + index_of(flag) ? true : false + end + def self.arguments_to(string, flags) - return unless index_of(string) - args = [] - ARGV.drop(index_of(string)+1).each do |argument| - next if argument == "," - break if flags.include?(argument) - args << argument - yield argument if block_given? + return if string.nil? + return if flags.nil? + return unless index = index_of(string) + if block_given? + arguments.drop(index+1).each do |argument| + # next if argument == "," + break if flags.include?(argument) + yield argument + end + else + args = [] + arguments_to(string, flags) { |arg| args << arg } + return args end - args end - def self.arguments_to?(string) - ARGV[ARGV.index(string) + 1] + def self.arguments_to?(flag) + arguments[arguments.index(flag) + 1] ? true : false end - def self.argument_to(string) - ARGV[ARGV.index(string) + 1] + def self.possible_argument_to(string) + arguments[arguments.index(string) + 1] + end + + def self.clear! + @arguments = [] end end end