Module: VideoTranscoding::CLI

Defined in:
lib/video_transcoding/cli.rb

Instance Method Summary collapse

Instance Method Details

#runObject



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
45
46
47
48
49
50
51
# File 'lib/video_transcoding/cli.rb', line 12

def run
  begin
    OptionParser.new do |opts|
      define_options opts
      opts.on('-v', '--verbose')  { Console.volume += 1 }
      opts.on('-q', '--quiet')    { Console.volume -= 1 }

      opts.on '-h', '--help' do
        puts usage
        exit
      end

      opts.on '--version' do
        puts about
        exit
      end
    end.parse!
  rescue OptionParser::ParseError => e
    raise UsageError, e
  end

  Console.info about
  configure
  fail UsageError, 'missing argument' if ARGV.empty?
  ARGV.each { |arg| process_input arg }
  complete if self.respond_to? :complete
  Console.info 'Done.'
  terminate if self.respond_to? :terminate
  exit
rescue UsageError => e
  warn "#{$PROGRAM_NAME}: #{e}\nTry `#{$PROGRAM_NAME} --help` for more information."
  exit false
rescue StandardError => e
  Console.error "#{$PROGRAM_NAME}: #{e}"
  exit(-1)
rescue SignalException
  terminate if self.respond_to? :terminate
  puts
  exit(-1)
end