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
41
42
43
44
|
# File 'lib/srs/cli/get-field.rb', line 4
def run!(arguments)
if not SRS::Workspace.initialised? then
puts "Current directory is not an SRS Workspace"
return 3
end
field = arguments.shift
id = arguments.shift
is_schedule = (id =~ /\d{14}\.\d{3}/)
filename = ""
if is_schedule then
filename = "schedule/#{id}"
filename = "schedule/pending/#{id}" if not File.exists?(filename)
else
filename = "exercises/#{id}"
end
if not File.exists?(filename) then
puts "No content with that ID exists"
return 4
end
File.open(filename, "r") do |file|
while( line = file.gets() ) do
if line.strip.empty? then
break
end
key, *val = line.split(':').map{|e| e.strip}
if key.casecmp(field) == 0 then
puts val.join(':')
return 0
end
end
end
puts "Content #{id} does not contain field \"#{field}\"."
return 4
end
|