Class: RAW::RawTool

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

Overview

Handles the startup of RAW with parsing options etc.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse!(args = ARGV) ⇒ Object



133
134
135
# File 'lib/raw_runner.rb', line 133

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

Instance Method Details

#loglevel(level) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/raw_runner.rb', line 137

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



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/raw_runner.rb', line 153

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

    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 "    raw scripts/ant.rb -r ../.. -v \n"
    o.separator "  Run a raw-script from a pastie URL:"
    o.separator "    raw http://www.pastie.org/508302 -r ../.. -v -l debug \n"
    o.separator "  Run a script without parameters:"
    o.separator "    raw ant.rb\n"
  end
end

#parse!(args) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/raw_runner.rb', line 106

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?
      RawRunner.new(general[0], @root_dir, {:loglevel => @loglevel, :target => @target})
    end
  end
end

#split_args(args) ⇒ Object



124
125
126
127
128
129
130
131
# File 'lib/raw_runner.rb', line 124

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