Sha256: 8404e8ac13b890ed7d44cab68b4f33f4427717a5be378e21f7494ecee0569818

Contents?: true

Size: 830 Bytes

Versions: 3

Compression:

Stored size: 830 Bytes

Contents

require "bundler/setup"
require "thor"
require "pathname"

module SnapshotUI
  class CLI < Thor
    WEBSOCKET_HOST = "localhost:7070"

    desc "watch SNAPSHOT_DIRECTORY", "Watches for snapshot changes in SNAPSHOT_DIRECTORY and broadcasts them on ws://#{WEBSOCKET_HOST}/cable."
    def watch(snapshot_directory)
      unless File.exist?(snapshot_directory)
        puts "The provided directory `#{snapshot_directory}` doesn't exist. Please double check the path."
        exit 1
      end

      websocket_host = "http://#{WEBSOCKET_HOST}"
      config_path = Pathname.new(__dir__).join("cli", "watcher.ru").cleanpath.to_s

      exec "SNAPSHOT_DIRECTORY=#{snapshot_directory} bundle exec falcon serve --bind #{websocket_host} --count 1 --config #{config_path}"
    end

    def self.exit_on_failure?
      true
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
snapshot_ui-0.3.0 lib/snapshot_ui/cli.rb
snapshot_ui-0.2.0 lib/snapshot_ui/cli.rb
snapshot_ui-0.1.0 lib/snapshot_ui/cli.rb