Class: Cadenza::Cli::Options

Inherits:
OptionParser
  • Object
show all
Defined in:
lib/cadenza/cli/options.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Options

Returns a new instance of Options.



12
13
14
15
# File 'lib/cadenza/cli/options.rb', line 12

def initialize(*args)
  @options = {}
  super
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/cadenza/cli/options.rb', line 4

def options
  @options
end

Class Method Details

.parse!Object



6
7
8
9
10
# File 'lib/cadenza/cli/options.rb', line 6

def self.parse!
  parser = new("Cadenza")
  parser.set_opts.parse!
  parser.options
end

Instance Method Details

#add_load_path(path) ⇒ Object



24
25
26
27
# File 'lib/cadenza/cli/options.rb', line 24

def add_load_path(path)
  @options[:load_paths] ||= []
  @options[:load_paths] << path
end

#context_option(context) ⇒ Object



17
18
19
20
21
22
# File 'lib/cadenza/cli/options.rb', line 17

def context_option(context)
  if File.exist?(context)
    context = File.read(context)
  end
  @options[:context] = MultiJson.load(context)
end

#set_optsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cadenza/cli/options.rb', line 29

def set_opts
  on("--context json") do |value|
    context_option value
  end
  on("-c json") do |value|
    context_option value
  end
  on("--root path") do |value|
    @options[:root] = value
  end
  on("-I", "--load-path PATH", "Add a path for the filesystem loader") do |path|
    add_load_path(path)
  end

end