290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
# File 'lib/base_chip/cli.rb', line 290
def run_cli(arguments = ARGV)
run_cli_no_command if arguments.size == 0
pass_through = nil
options. append_arguments = nil
options.replace_arguments = nil
arguments.keep_if do |a|
case a
when '--' ; pass_through = (options. append_arguments ||= []); false
when '---' ; pass_through = (options.replace_arguments ||= []); false
else
if pass_through
pass_through << a
false
else
true
end
end
end
cli.options.each do |o,h|
if h[:value]
options.send("#{h[:name]}=",h[:value])
end
end
cli.mine_options(options,arguments)
arguments.size.times do |i|
case a = arguments[i].to_sym
when *(cli.sub_commands.keys)
arguments.delete_at i
cli.sub_commands[a].new.run_cli(arguments)
exit
when *(cli.tasks.keys)
arguments.delete_at i
task = cli.tasks[a]
task.mine_options(options,arguments,true)
if task.required_argument_size > arguments.size
help task.name
fault "\n#{task.name} is missing required arguments"
end
send a, *arguments
break
else
if a[0] == '-'
fault("Could not determine what to run from \"#{arguments.join(' ')}\". Please consider placing dash options at the end of the command line.")
end
task = cli.default_task or fault("Could not determine what to run from \"#{arguments.join(' ')}\".")
task.mine_options(options,arguments,true)
if task.required_argument_size > arguments.size
puts "\n#{task.name} is missing required arguments"
help task.name
exit 1
end
send task.name, *arguments
break
end
end
end
|