Class: Af::OptionParser::GetOptions
- Inherits:
-
GetoptLong
- Object
- GetoptLong
- Af::OptionParser::GetOptions
- Defined in:
- lib/fiksu-af/option_parser/get_options.rb
Overview
Subclasses Getoptlong from the Ruby standard library. Docs: www.ruby-doc.org/stdlib-1.9.3/libdoc/getoptlong/rdoc/GetoptLong.html. Source: github.com/ruby/ruby/blob/trunk/lib/getoptlong.rb.
Constant Summary collapse
- ARGUMENT_FLAGS =
Local constants which map to superclass argument types.
[ NO_ARGUMENT = GetoptLong::NO_ARGUMENT, REQUIRED_ARGUMENT = GetoptLong::REQUIRED_ARGUMENT, OPTIONAL_ARGUMENT = GetoptLong::OPTIONAL_ARGUMENT ]
Instance Method Summary collapse
-
#initialize(declared_options = []) ⇒ GetOptions
constructor
Instantiate a new long command line option parser with a hash of switches.
Constructor Details
#initialize(declared_options = []) ⇒ GetOptions
Instantiate a new long command line option parser with a hash of switches.
Arguments
* switches - optional hash of command line switches, with long switch as
key to a set of options:
:short => <optional short switch>
:argument => <constant arg type>
:environment_variable => <how do these work???>
:note => <arg description>
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fiksu-af/option_parser/get_options.rb', line 25 def initialize( = []) = [] argv_additions = [] # Iterate through all of the options. .each do |option| # Set aside if option.environment_variable.present? # Add enviroment variables to the front of ARGV. if ENV[option.environment_variable] argv_additions << option.long_name unless ENV[option.environment_variable].empty? # if the envvar is empty we assume this is a switch (no parameter) argv_additions << ENV[option.environment_variable] end end end # Convert hash into array, in format expected by Getoptlong#new. # Example: ['--foo', '-f', GetoptLong::NO_ARGUMENT] = [] << option.long_name if (option.short_name) << option.short_name end << option.requirements << end # add any ARGVs to our list for arg in ARGV do argv_additions << arg end # Rewrite ARGV with environment variable with the new list. argv_additions.each_with_index { |v,i| ARGV[i] = v } super(*) end |