Skip to content

Commit

Permalink
Added debug start option
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaudgg committed Oct 10, 2010
1 parent 5b4363b commit 8b5ecd9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion guard.gemspec
Expand Up @@ -10,7 +10,7 @@ Gem::Specification.new do |s|
s.email = ['thibaud@thibaud.me']
s.homepage = 'http://rubygems.org/gems/guard'
s.summary = 'Guard keep an eye on your files modifications.'
s.description = 'Guard is a command line tool to easly handle events on files modifications.'
s.description = 'Guard is a command line tool to easily handle events on files modifications.'

s.required_rubygems_version = '>= 1.3.6'
s.rubyforge_project = 'guard'
Expand Down
6 changes: 4 additions & 2 deletions lib/guard.rb
Expand Up @@ -47,17 +47,19 @@ def get_guard_class(name)
require "guard/#{name.downcase}"
guard_class = ObjectSpace.each_object(Class).detect { |c| c.to_s.downcase.match "^guard::#{name.downcase}" }
rescue LoadError
UI.error "#{name} guard gem not found, try to add it to your Gemfile."
UI.error "Could not find gem 'guard-#{name}' in the current Gemfile."
end

def locate_guard(name)
spec = Bundler.load.specs.find{|s| s.name == "guard-#{name}" }
UI.error "Could not find gem '#{name}' in the current Gemfile." unless spec
spec.full_gem_path
rescue
UI.error "Could not find gem 'guard-#{name}' in the current Gemfile."
end

def run
listener.stop
UI.clear if options[:clear]
yield
listener.start
end
Expand Down
3 changes: 2 additions & 1 deletion lib/guard/cli.rb
Expand Up @@ -6,7 +6,8 @@ class CLI < Thor
default_task :start

desc "start", "Starts guard"
method_option :clear, :type => :boolean, :default => false, :aliases => '-c', :banner => "Auto clear shell after each change"
method_option :clear, :type => :boolean, :default => false, :aliases => '-c', :banner => "Auto clear shell before each change/run_all/reload"
method_option :debug, :type => :boolean, :default => false, :aliases => '-d', :banner => "Print debug messages"
def start
::Guard.start(options)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/interactor.rb
Expand Up @@ -13,7 +13,7 @@ def self.init_signal_traps
Signal.trap('INT') do
::Guard.listener.stop
if ::Guard.guards.all?(&:stop)
UI.info "Bye bye...", :reset => true, :clear => false
UI.info "Bye bye...", :reset => true
abort("\n")
else
::Guard.listener.start
Expand Down
11 changes: 8 additions & 3 deletions lib/guard/ui.rb
Expand Up @@ -5,7 +5,6 @@ class << self
def info(message, options = {})
unless ENV["GUARD_ENV"] == "test"
reset_line if options[:reset]
clear if options.key?(:clear) ? options[:clear] : (::Guard.options && ::Guard.options[:clear])
puts reset_color(message) if message != ''
end
end
Expand All @@ -14,16 +13,22 @@ def error(message)
puts "ERROR: #{message}"
end

def debug(message)
unless ENV["GUARD_ENV"] == "test"
puts "DEBUG: #{message}" if ::Guard.options && ::Guard.options[:debug]
end
end

def reset_line
print "\r\e "
end

private

def clear
system("clear;")
end

private

def reset_color(text)
color(text, "\e[0m")
end
Expand Down

0 comments on commit 8b5ecd9

Please sign in to comment.