Class: ImapArchiver::CLI

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

Class Method Summary collapse

Class Method Details

.execute(stdout, stdin, arguments = []) ⇒ Object



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
# File 'lib/imap_archiver/cli.rb', line 5

def self.execute(stdout,stdin, arguments=[])

  # NOTE: the option -p/--path= is given as an example, and should be replaced in your application.
  options = {
    :config_file => "~/.imap_archiver.rb",
    :debug => false
  }
  mandatory_options = %w(  )

  parser = OptionParser.new do |opts|
    opts.banner = <<-BANNER.gsub(/^          /,'')
      Usage: #{File.basename($0)} [options]

      Options are:
    BANNER
    opts.separator ""
    opts.on("-h", "--help",
            "Show this help message.") { stdout.puts opts; exit }
    opts.on("-d", "--debug", "Enable debugging.") { options[:debug] = true}
    opts.on("-F PATH", "", String, "Configuration file", "Default: ~/.imap_archiver.yml"){|arg| options[:config_file] = arg}
    opts.parse!(arguments)

    if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
      stdout.puts opts; exit
    end
  end
  
  # Config.load_config(options[:config_file])
  Archiver.run(options[:config_file],options[:debug])
  
  return 0
end