Class: Metabuild::Options

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/metabuild.rb

Overview

A class for parsing command line options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h) ⇒ Options

By default, the following options are set : –help, and DEFAULT_OPTIONS. So caching and target dependencies tracking are disabled by default. h is a hashmap of tuples option_name => default_value



864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
# File 'lib/metabuild.rb', line 864

def initialize(h)
  @opts = {}
  @help = false
  hash = DEFAULT_OPTIONS.merge(h)
  @parser = OptionParser.new
  @parser.on("--help") {|val| @help = true}
  @from_targets = []
  @restart_at = nil
  @parser.on("--from=[target]", "Disable everything below target in dep tree. Only with dependency=yes") {|val| @from_targets.push val}
  @parser.on("--restart-at=[target]", "Disable everything before target in sequential build order. Only with dependency=yes") {|val| @restart_at = val}
  hash.each do |opt, default|
    if default.kind_of? Array
      @parser.on("--#{opt}=[#{default[0]}]", default[1]) {|val| @opts[opt] = val}
    else 
      @parser.on("--#{opt}=[#{default}]") {|val| @opts[opt] = val}
    end
  end
  if defined? $subscript_argv and not $subscript_argv.nil?
    argv = $subscript_argv
  else
    argv = ARGV
  end
  @rest = @parser.parse(*argv)
  hash.each do |opt, default|
    default = default[0] if default.kind_of? Array
    @opts[opt] = default unless @opts.has_key? opt
  end
end

Instance Attribute Details

#from_targetsObject (readonly)

Returns the value of attribute from_targets.



858
859
860
# File 'lib/metabuild.rb', line 858

def from_targets
  @from_targets
end

#optsObject (readonly)

Returns the value of attribute opts.



858
859
860
# File 'lib/metabuild.rb', line 858

def opts
  @opts
end

#restObject (readonly)

Returns the value of attribute rest.



858
859
860
# File 'lib/metabuild.rb', line 858

def rest
  @rest
end

#restart_atObject (readonly)

Returns the value of attribute restart_at.



858
859
860
# File 'lib/metabuild.rb', line 858

def restart_at
  @restart_at
end

Instance Method Details

#helpObject



897
898
899
# File 'lib/metabuild.rb', line 897

def help
  @parser.to_s
end

#help?Boolean

Returns:

  • (Boolean)


893
894
895
# File 'lib/metabuild.rb', line 893

def help?
  @help
end