Sha256: fc47f3ea04d78c8cefd591bd29f7dc46e93a0adace0f465e2020ade4c69af20b

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require_relative '../dirwatch'

module Dirwatch
  class Executor
    def run args
      options = Options.from_args(args)
      send "run_#{options.action}", options
      nil
    end

    private

    def run_exit options; end

    def run_watch options
      require_relative 'watcher'

      watcher = Watcher.new options
      watcher.start

      begin
        watcher.wait_for_stop
      rescue Interrupt
        exit
      ensure
        stop_watcher watcher
      end
    end

    def stop_watcher watcher
      watcher.stop
    end

    def run_init options
      require_relative 'templates'

      hash = options.to_h
      if hash.delete :list
        Templates.list hash
      else
        Templates.create hash
      end
    end
  end

  class Console < Executor
    def run args
      status = catch :exit do
        super
      end
      exit status || 0
    rescue Dirwatch::UserFriendlyError => e
      $stderr.puts e.user_friendly_message
      exit 1
    end

    private

    def stop_watcher watcher
      puts 'shutting down...'
      super
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dirwatch-0.0.5 lib/dirwatch/executors.rb