module LaceArgvExtension
Copyright 2009-2014 Max Howell and other contributors.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR “AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Public Instance Methods
# File lib/extend/ARGV.rb, line 51 def debug? flag? '--debug' end
# File lib/extend/ARGV.rb, line 67 def flag? flag options_only.any? do |arg| arg == flag || arg[1..1] != '-' && arg.include?(flag[2..2]) end end
# File lib/extend/ARGV.rb, line 59 def force? flag? '--force' end
self documenting perhaps?
# File lib/extend/ARGV.rb, line 34 def include? arg @n=index arg end
# File lib/extend/ARGV.rb, line 63 def interactive? flag? '--interactive' end
# File lib/extend/ARGV.rb, line 25 def named @named ||= reject{|arg| arg[0..0] == '-'} end
# File lib/extend/ARGV.rb, line 38 def next at @n+1 or raise UsageError end
# File lib/extend/ARGV.rb, line 55 def nohooks? flag? '--no-hooks' end
# File lib/extend/ARGV.rb, line 29 def options_only select {|arg| arg[0..0] == '-'} end
eg. `foo -ns -i –bar` has three switches, n, s and i
# File lib/extend/ARGV.rb, line 74 def switch? switch_character return false if switch_character.length > 1 options_only.any? do |arg| arg[1..1] != '-' && arg.include?(switch_character) end end
# File lib/extend/ARGV.rb, line 42 def value arg arg = find {|o| o =~ /--#{arg}=(.+)/} $1 if arg end
# File lib/extend/ARGV.rb, line 47 def verbose? flag? '--verbose' or !ENV['VERBOSE'].nil? end
Private Instance Methods
# File lib/extend/ARGV.rb, line 83 def downcased_unique_named # Only lowercase names, not paths or URLs @downcased_unique_named ||= named.map do |arg| arg.include?("/") ? arg : arg.downcase end.uniq end