-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathargv.rb
More file actions
41 lines (33 loc) · 969 Bytes
/
Copy pathargv.rb
File metadata and controls
41 lines (33 loc) · 969 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/ruby
#language: Ruby
#filename: argv.rb
#descripiton: parsing data from argv with ruby
debug=1
mappings={
"f" => 3,
"ft" => 5,
'st' => 10,
'b' => 20,
}
def help()
puts "help was called"
end
ARGV << '-help' if ARGV.empty?
puts "length of the 'ARGV' array is: " + ARGV.length.to_s if debug==1
for i in 0 ... ARGV.length
puts "MAIN DEBUG#{i}: '#{ARGV[i].chomp}'" if debug==1
if ARGV[i] =~ /-/ and ARGV[i] !~ /-help/ #alternate run 'help' is found
puts "DEBUG#{i}: flag detected '#{ARGV[i].chomp}'" if debug==1
arg_count=i+1
puts "DEBUG#{i}: associated with'#{ARGV[arg_count].chomp}'" if debug==1
elsif ARGV[i].chomp =~ /-help/ or ARGV[i] =~ /\s+/ #need help
puts "DEBUG3: 'help command received'" if debug==1
help()
else
puts ""
#puts "need some error checking here. last line ? #{ARGV[i].chomp}'" if debug==1
end
end
for string in ARGV
puts "You typed `#{string}` as your argument(s)."
end