24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/corruption_monkey/cli.rb', line 24
def self.start(args = ARGV)
file_path = args.shift
second_argument = args.shift
if (file_path.nil? && second_argument.nil?) ||
(!File.file?(file_path) && file_path == 'help')
puts DOCS
exit 0
end
unless File.file?(file_path)
$stderr.puts "The file with path=`#{file_path}` does not exist"
exit 1
end
logger = Logger.new(STDOUT)
banner
case second_argument
when 'chaos'
puts 'chaos mode selected'
puts
BitFlipper.random_bit_flip(file_path, logger: logger)
when /([0-9]{1, 2}|100)%/
puts 'percent mode selected'
puts
BitFlipper.flip_in_range(file_path,
percentile: second_argument.to_i,
logger: logger)
when /[0-9]+/
puts 'accurate mode selected'
puts
BitFlipper.flip!(file_path,
bit: second_argument.to_i,
logger: logger)
else
$stderr.puts 'nothing matches!'
$stderr.puts DOCS
end
end
|