115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/cf/cli.rb', line 115
def output
run_title = options['run_title']
if run_title.present?
run_title = run_title.parameterize
line_source = Dir.pwd
yaml_source = "#{line_source}/line.yml"
set_target_uri(false)
set_api_key(yaml_source)
CF.account_name = CF::Account.info.name
run = CF::Run.find(run_title)
if run['errors'].blank? && run.class != NilClass
say("Fetching output for run: #{run_title}", :green)
if options[:station_index].present?
output = CF::Run.output(:title => run_title, :station => options[:station_index])
else
output = CF::Run.final_output(run_title)
end
if !output.empty?
output.each
csv_str = CSVHash(output,output.first.keys)
csv_str = csv_str.gsub("\"\"", '"')
FileUtils.mkdir("#{line_source}/output") unless Dir.exist?("#{line_source}/output") if RUBY_VERSION > "1.9"
FileUtils.mkdir("#{line_source}/output") unless File.directory?("#{line_source}/output") if RUBY_VERSION < "1.9"
csv_file_name = "#{line_source}/output/#{run_title}-#{Time.now.strftime("%e %b %Y %H:%m-%S%p").parameterize}.csv"
File.open(csv_file_name, 'w') {|f| f.write(csv_str) }
say("Output saved at #{csv_file_name}\n", :yellow)
else
say("Run not completed yet", :red)
end
else
say("Error: #{run['errors'].inspect}", :red)
end
else
say("\nThe run title must be provided to get the output.", :red)
say("\te.g. cf output my-run-title\n", :yellow)
end
end
|