Sha256: a92b890e3f35888ea746bda20a30cb1c144e5bc36a46f9e6cf8517eeafdc890d

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

#!/usr/bin/env ruby

require 'pathname'
require 'optparse'

require 'watchr'

module Watchr
  # Namespaced to avoid defining global methods
  module Bin #:nodoc:
    extend self

    def usage
      "Usage: watchr [opts] path/to/script"
    end

    def version
      "watchr version: %s" % Watchr::VERSION
    end

    # Find a partial path name in load path
    #
    # ===== Params
    # path<Pathname>:: partial pathname
    #
    # ===== Returns
    # <Pathname>::
    #   absolute path of first occurence of partial path in load path, or nil if not found
    #--
    # Adds '.' for ruby1.9.2
    def find_in_load_path(path)
      dir = (['.'] + $LOAD_PATH).uniq.detect {|p| Pathname(p).join(path).exist? }
      dir ? path.expand_path(dir) : nil
    end
  end
end

opts = OptionParser.new do |opts|
  opts.banner = Watchr::Bin.usage

  opts.on('-d', '--debug', "Print extra debug info while program runs") {
    Watchr.options.debug = true
    begin
      require 'ruby-debug'
    rescue LoadError, RuntimeError
    end
  }

  opts.on_tail('-h', '--help', "Print inline help") { puts opts; exit }
  opts.on_tail('-v', '--version', "Print version" ) { puts Watchr::Bin.version; exit }

  opts.parse! ARGV
end

relative_path = Pathname( ARGV.first )                   rescue abort(Watchr::Bin.usage)
absolute_path = Watchr::Bin.find_in_load_path(relative_path) or abort("no script found; file #{relative_path.to_s.inspect} is not in path.")

Watchr::Controller.new(Watchr::Script.new(absolute_path), Watchr.handler.new).run

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
watchr-0.5.9 bin/watchr
watchr-0.5.8 bin/watchr