Class: AlsaBackup::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/alsa_backup/cli.rb

Class Method Summary collapse

Class Method Details

.execute(stdout, *arguments) ⇒ Object



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
45
46
47
48
49
50
51
52
53
54
# File 'lib/alsa_backup/cli.rb', line 6

def self.execute(stdout, *arguments)
  options = {}
  mandatory_options = %w()

  OptionParser.new do |opts|
    opts.banner = "      AlsaBackup : continuous recording with alsa\n\n      Usage: \#{File.basename($0)} [options]\n\n      Options are:\n    BANNER\n    opts.separator \"\"\n    opts.on(\"-f\", \"--file=FILE\", String,\n            \"Recording file\") { |arg| options[:file] = arg }\n    opts.on(\"-l\", \"--length=LENGTH\", String,\n            \"Length in seconds\") { |arg| options[:length] = arg }\n    opts.on(\"-d\", \"--directory=DIRECTORY\", String,\n            \"Base directory\") { |arg| options[:directory] = arg }\n    opts.on(\"-c\", \"--config=CONFIG\", String,\n            \"Configuration file\") { |arg| options[:config] = arg }\n    opts.on(\"-p\", \"--pid=PID_FILE\", String,\n            \"File to write the process pid\") { |arg| options[:pid] = arg }\n    opts.on(\"-b\", \"--background\", nil,\n            \"Daemonize the process\") { |arg| options[:daemonize] = true }\n    opts.on(\"-h\", \"--help\",\n            \"Show this help message.\") { stdout.puts opts; exit }\n    opts.parse!(arguments)\n\n    if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }\n      stdout.puts opts; exit\n    end\n  end\n\n  load File.expand_path(options[:config]) if options[:config]\n\n  AlsaBackup.recorder.file = options[:file] if options[:file]\n  AlsaBackup.recorder.directory = options[:directory] if options[:directory]\n\n  pid_file = File.expand_path(options[:pid]) if options[:pid]\n\n  Daemonize.daemonize(nil, \"alsa-backup\") if options[:daemonize]\n  File.write(pid_file, $$) if pid_file\n  \n  length = options[:length].to_i if options[:length]\n  AlsaBackup.recorder.start(length)\nrescue Exception => e\n  AlsaBackup.logger.fatal(e)\nend\n".gsub(/^          /,'')