Class: JRAW::JRawTool

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

Overview

Handles the startup of JRAW with parsing options etc.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse!(args = ARGV) ⇒ Object



151
152
153
# File 'lib/jraw_runner.rb', line 151

def self.parse!(args = ARGV)
  JRawTool.new.parse!(args)
end

Instance Method Details

#loglevel(level) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/jraw_runner.rb', line 155

def loglevel(level)
  case level
    when 'debug'
      Logger::DEBUG
    when 'info'
      Logger::INFO
    when 'warn'
      Logger::WARN
    when 'error'
      Logger::ERROR
    when 'fatal'
      Logger::FATAL
  end
end

#optionsObject

Options and how they are used



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/jraw_runner.rb', line 171

def options
  OptionParser.new do |o|
    o.set_summary_indent('  ')
    o.banner =    "Usage: jraw jraw-script-url [OPTIONS]"
    o.define_head "Ruby ANT Wrapper (JRAW)."

    o.separator ""
    o.separator "GENERAL OPTIONS"

    o.on("-v", "--verbose", "Turn on verbose ant output.") { |verbose| $verbose = verbose }
    o.on("-h", "--help", "Show this help message.") { puts o; exit }
    o.on("-r", "--root directory", "Set the root path of the script. Defaults to '.'") { |root| $root_dir = root}
    o.on("-l", "--loglevel level", "Set the log level. Default is info. Possible values are: error, warn, info, debug") { |level| @loglevel = loglevel(level)}
    o.on("-t", "--target target", "Target to execute with ANT") { |target| @target = target.to_sym}
    o.separator ""
    o.separator "EXAMPLES"
    o.separator "  run example script:"
    o.separator "    jraw scripts/ant.rb -r ../.. -v \n"
    o.separator "  Run a jraw-script from a pastie URL:"
    o.separator "    jraw http://www.pastie.org/508302 -r ../.. -v -l debug \n"
    o.separator "  Run a script without parameters:"
    o.separator "    jraw ant.rb\n"
  end
end

#parse!(args) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/jraw_runner.rb', line 124

def parse!(args)
  if args.length == 0
    puts options
  elsif args.length == 1 && args[0] == ('-h' || '--help')
    options.parse!(args)
  else
    general, sub = split_args(args)
    options.parse!(args)

    if general.empty?
      puts options
    else
      @root_dir = '.' if @root_dir.nil?
      JRawRunner.new(general[0], @root_dir, {:loglevel => @loglevel, :target => @target})
    end
  end
end

#split_args(args) ⇒ Object



142
143
144
145
146
147
148
149
# File 'lib/jraw_runner.rb', line 142

def split_args(args)
  left = []
  while args[0] and args[0] =~ /^-/ do
    left << args.shift
  end
  left << args.shift if args[0]
  return [left, args]
end