method
setup
v2_4_6 -
Show latest stable
- Class:
Object
setup(options = "", *long_options)public
:nodoc:
# File lib/un.rb, line 37
def setup(options = "", *long_options)
caller = caller_locations(1, 1)[0].label
opt_hash = {}
argv = []
OptionParser.new do |o|
options.scan(/.:?/) do |s|
opt_name = s.delete(":").intern
o.on("-" + s.tr(":", " ")) do |val|
opt_hash[opt_name] = val
end
end
long_options.each do |s|
opt_name, arg_name = s.split(/(?=[\s=])/, 2)
opt_name.sub!(/\A--/, '')
s = "--#{opt_name.gsub(/([A-Z]+|[a-z])([A-Z])/, '\1-\2').downcase}#{arg_name}"
puts "#{opt_name}=>#{s}" if $DEBUG
opt_name = opt_name.intern
o.on(s) do |val|
opt_hash[opt_name] = val
end
end
o.on("-v") do opt_hash[:verbose] = true end
o.on("--help") do
UN.help([caller])
exit
end
o.order!(ARGV) do |x|
if /[*?\[{]/ =~ x
argv.concat(Dir[x])
else
argv << x
end
end
end
yield argv, opt_hash
end Related methods
- Instance methods
- !~
- <=>
- ===
- =~
- CSV
- DelegateClass
- Digest
- __getobj__
- __setobj__
- chmod
- class
- clone
- cp
- dclone
- default_src_encoding
- define_singleton_method
- display
- dup
- enum_for
- eql?
- extend
- freeze
- frozen?
- help
- httpd
- initialize_clone
- initialize_copy
- initialize_dup
- inspect
- install
- instance_of?
- instance_variable_defined?
- instance_variable_get
- instance_variable_set
- instance_variables
- is_a?
- itself
- kind_of?
- ln
- method
- methods
- mkdir
- mkmf
- mv
- nil?
- object_id
- pretty_print
- pretty_print_cycle
- private_methods
- protected_methods
- psych_to_yaml
- public_method
- public_methods
- public_send
- remove_instance_variable
- respond_to?
- respond_to_missing?
- rm
- rmdir
- send
- setup
- singleton_class
- singleton_method
- singleton_methods
- sysread
- taint
- tainted?
- tap
- timeout
- to_enum
- to_s
- to_yaml
- to_yaml_properties
- touch
- trust
- unknown
- untaint
- untrust
- untrusted?
- wait_writable
- xmp
- Class methods
- yaml_tag
- Protected methods
-
hash