Class: FileMonitor::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/file_monitor/command_line.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv = []) ⇒ CommandLine

Returns a new instance of CommandLine.



3
4
5
6
# File 'lib/file_monitor/command_line.rb', line 3

def initialize argv=[]
  require 'trollop'
  parse self, argv if argv.any?
end

Instance Method Details

#available_commandsObject



19
20
21
# File 'lib/file_monitor/command_line.rb', line 19

def available_commands
  %w(start stop)
end

#file_monitor_bannerObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/file_monitor/command_line.rb', line 8

def file_monitor_banner
"Usage: file_monitor -c /path/to/config.yml COMMAND [ARGS]\n\nThe file monitor commands are:\n start          Starts the file monitor and watches a specified directory.\n stop           Stops the file monitor\n --version\n"
end

#parse(_self, argv) ⇒ Object



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_monitor/command_line.rb', line 23

def parse _self, argv
  global_opts = Trollop::options(argv) do
    banner _self.file_monitor_banner
    opt :config_path, "Configuration Path", :short => "-c", :type => :string
    stop_on _self.available_commands
  end

  command  = argv.shift # get the subcommand
  cmd_opts = case command
    when "start"
      Trollop::options(argv) do
        opt :config_path, "Configuration Path", :short => "c"
      end

      watch_dir   = argv.unshift
      config_path = global_opts[:config_path]
      FileMonitor::Core.new(:config_path => config_path, :watch_dir => File.expand_path(File.join(watch_dir))).run
    when "stop"
    else
      Trollop::die "unknown command #{command.inspect}"
    end
end