Class: FileWorker::Cli

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

Class Method Summary collapse

Class Method Details

.build_scannerObject



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
37
38
39
40
41
42
43
44
# File 'lib/file_worker/cli.rb', line 5

def self.build_scanner
  options = {
    :workers => 5
  }

  OptionParser.new do |opts|
    opts.banner = "Usage: #{$0} [options]"

    opts.on("-w", "--workers [NUMBER]", "The number of worker threads") do |workers|
      options[:workers] = workers.to_i
    end

    opts.on("-o", "--out [DIRECTORY]", "The directory to put the files when they have been processed") do |out|
      options[:out_directory] = out
    end

    opts.on("-s", "--sleep [NUMBER]", Float, "The number of seconds to sleep between scanning the in-directory") do |sleep_time|
      options[:sleep] = sleep_time
    end

    opts.on("-q", "--queuesize [NUMBER]", "The maximum queue size to keep in memory") do |max_queue_size|
      options[:max_queue_size] = max_queue_size.to_i
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  end.parse!

  if root = ARGV[0]
    options[:in_directory] = File.expand_path(root, Dir.pwd)
  else
    options[:in_directory] = Dir.pwd
  end

  options[:out_directory] ||= File.expand_path('../done', options[:in_directory])

  DirectoryScanner.new(options)
end