Class: FileMonitor::CommandLine
- Inherits:
-
Object
- Object
- FileMonitor::CommandLine
- Defined in:
- lib/file_monitor/command_line.rb
Instance Method Summary collapse
- #available_commands ⇒ Object
- #file_monitor_banner ⇒ Object
-
#initialize(argv = []) ⇒ CommandLine
constructor
A new instance of CommandLine.
- #parse(_self, argv) ⇒ Object
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_commands ⇒ Object
19 20 21 |
# File 'lib/file_monitor/command_line.rb', line 19 def available_commands %w(start stop) end |
#file_monitor_banner ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/file_monitor/command_line.rb', line 8 def "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::(argv) do _self. 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::(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.(File.join(watch_dir))).run when "stop" else Trollop::die "unknown command #{command.inspect}" end end |