blob: b86de4f02c1b915d462e75b84ea49d55b4596d66 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# frozen_string_literal: true
mode = ARGV.shift.to_s
stdin = $stdin.read
case mode
when 'upcase_prompt'
prompt = ARGV.fetch(0, '')
print "#{stdin.upcase}|#{prompt}"
when 'reverse_input'
input_path = ARGV.fetch(0)
print File.read(input_path).reverse
when 'basename'
file_path = ARGV.fetch(0)
print File.basename(file_path)
when 'pass_through'
print stdin
when 'upcase'
print stdin.upcase
when 'fail'
warn ARGV.fetch(0, 'boom')
exit Integer(ARGV.fetch(1, '7'))
else
warn "unknown mode: #{mode}"
exit 2
end
|