Method: WASP::Nest#parse_command!

Defined in:
lib/wasp/nest.rb

#parse_command!Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/wasp/nest.rb', line 152

def parse_command!
  verb = @args.shift
  case verb

  when 'set'
    file = @args.shift
    
    help('nofile') if file.nil?
    
    file = File.absolute_path(file)
    
    begin
      FileUtils.cp(file, ENV["HOME"] + "/.waspaws.yml")
    rescue => ex
      puts "#{ex.message}"
      exit false
    end
    puts "AWS credential is set."
  
  when 'up'   
    if lost_wasps then
      puts "[WARN]".yellow + " There are lost wasps in the air. They need to go home first. [./nest down]"
      exit(false)
    end
  
    
    if @options[:key].nil? then 
      help("nokey")
    end
  
    puts 'Breeding wasps..'
    
    @wasps = WASP::Wasp.new(@options)
    @wasps.ready
    @wasps.breed
        
    #puts 'Breeding queen wasp..'
    #@queenwasp = WASP::QueenWasp.new(num_wasps)
    
  when 'equip'
    puts "Check wasps weapon.."
    
    @wasps = WASP::Wasp.new(@options)
    @wasps.equip
  
  when 'rattack'        
    puts "Connecting to the nest"
    
    if @options[:url].nil? then
      help("nourl")
    end
    
    if @options[:pattern].nil? then
      @options[:pattern] = "5000:60"
    end
    
    pattern = @options[:pattern]
    to, time, keep = pattern.split(":")
    
    help if time.nil? or to.nil?

    if keep == 'keep' then
      keep = true 
    else
      keep = false
    end
    @wasps = WASP::Wasp.new(@options)   
    @wasps.rangeattack(to.to_i, time.to_i, @options[:url], keep)
    
  when 'attack'
    puts "Connecting to the nest"
    
    if @options[:url].nil? then
      help("nourl")
    end
            
    num = if @options[:num].nil? then
            WASP::Const::DEFAULT_NUMBER_OF_REQUESTS
          else
            @options[:num].to_i
          end
    
    time = @options[:time]
            
    # number of requests would be ignored if time parameter have given
    num = nil if not time.nil?
          
    conn = if @options[:conn].nil? then
            WASP::Const::DEFAULT_CONCURRENT_OF_CONNECTIONS
          else
            @options[:conn].to_i
          end
          
    @wasps = WASP::Wasp.new(@options)   
    @wasps.attack(num, conn, @options[:url], time)
  
  
  when 'down'
    puts "Connecting to the nest."
    @wasps = WASP::Wasp.new(@options)
    @wasps.down
  
  when 'status'
    puts 'Report the wasp..'
    @wasps = WASP::Wasp.new(@options)
    @wasps.status
    
  when 'regions'
    puts 'Searching airfield..'
    @wasps = WASP::Wasp.new(@options)
    @wasps.airfield

  when 'help'
    @optionhelp = true
    help
  else
    help
  end
end