Class: CDQ::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/cdq/cli.rb

Direct Known Subclasses

CreateAction, InitAction

Constant Summary collapse

HELP_TEXT =
%{Usage:
cdq [options] <command> [arguments]

Commands:
cdq init                         # Add boilerplate setup to use CDQ
cdq create model <model>         # Create a model and associated files

Options:
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#singleton_options_passedObject (readonly)

Returns the value of attribute singleton_options_passed.



17
18
19
# File 'lib/cdq/cli.rb', line 17

def singleton_options_passed
  @singleton_options_passed
end

Class Method Details

.run_allObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cdq/cli.rb', line 35

def self.run_all

  actions = { "init" => InitAction, "create" => CreateAction }

  cli = self.new
  opts = cli.option_parser
  opts.order!
  action = ARGV.shift

  if actions[action]
    actions[action].new.run
  elsif !cli.singleton_options_passed
    puts opts
  end

end

Instance Method Details

#option_parser(help_text = HELP_TEXT) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/cdq/cli.rb', line 19

def option_parser(help_text = HELP_TEXT)
  OptionParser.new do |opts|
    opts.banner = help_text

    opts.on("-v", "--version", "Print Version") do
      @singleton_options_passed = true
      puts CDQ::VERSION
    end

    opts.on("-h", "--help", "Show this message") do
      @singleton_options_passed = true
      puts opts
    end
  end
end