Method: Faceapp::CLI#run!

Defined in:
lib/faceapp/cli.rb

#run!Object



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/faceapp/cli.rb', line 16

def run!
  print_usage if params.empty? || options[:help]

  options[:logger] = Logger.new(STDERR) if debug?

  filter = params[:filter]
  input = parse_input(params[:input])
  output = parse_output(params[:output])

  client = Faceapp::Client.new(options)

  code = client.upload_photo(input)

  info "Successfuly uploaded input photo. Result code = #{code}"
  info "Applying filter '#{filter}'"

  client.apply_filter(code, filter, output)

  info 'Done.'
rescue => e
  info "Error: #{e.message}"

  debug { e.backtrace.join("\n") }

  exit(-1)
ensure
  input.close if input.is_a?(File)
  output.close if output.is_a?(File)
end