From 5111e8594e68d307fb03f6723547c794641a37f2 Mon Sep 17 00:00:00 2001 From: Thibaud Guillaume-Gentil Date: Wed, 12 Oct 2011 22:14:25 +0200 Subject: [PATCH] Add new cli option - The new cli option (-i / --no-interactions) allow to completely turn off any Guard terminal interactions --- CHANGELOG.md | 1 + README.md | 14 +++++++++++++- lib/guard.rb | 12 ++++++------ lib/guard/cli.rb | 6 ++++++ spec/guard_spec.rb | 11 +++++++++++ 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70b52db..fc9e3b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Improvements +- Add cli option (-i / --no-interactions) to turn off Guard terminal interactions. ([@thibaudgg][]) - Add support for Growl Notification Transport Protocol. ([@netzpirat][]) - [#157](https://github.com/guard/guard/pull/157): Allow any return from the Guard watchers. ([@earlonrails][]) - [#156](https://github.com/guard/guard/pull/156): Log error and diagnostic messages to STDERR. ([@sunaku][]) diff --git a/README.md b/README.md index d201ad2..a0727a5 100644 --- a/README.md +++ b/README.md @@ -194,10 +194,22 @@ $ guard start -A $ guard start --watch-all-modifications ``` +### `-i`/`--no-interactions` option + +Turn off completely any Guard terminal [interactions](#interactions) with: + +``` bash +$ guard start -i +$ guard start --no-interactions +``` + An exhaustive list of options is available with: - $ guard help [TASK] +``` bash +$ guard help [TASK] +``` + Interactions ------------ diff --git a/lib/guard.rb b/lib/guard.rb index 7cae01e..bae4220 100644 --- a/lib/guard.rb +++ b/lib/guard.rb @@ -16,7 +16,7 @@ module Guard autoload :Hook, 'guard/hook' class << self - attr_accessor :options, :interactor, :listener + attr_accessor :options, :interactor, :listener, :lock # Creates the initial Guardfile template or add a Guard implementation # Guardfile template to an existing Guardfile. @@ -56,7 +56,7 @@ module Guard @options = options @guards = [] @groups = [Group.new(:default)] - @interactor = Interactor.new + @interactor = Interactor.new unless @options[:no_interactions] @listener = Listener.select_and_init(@options[:watchdir] ? File.expand_path(@options[:watchdir]) : Dir.pwd, options) @options[:notify] && ENV['GUARD_NOTIFY'] != 'false' ? Notifier.turn_on : Notifier.turn_off @@ -140,7 +140,7 @@ module Guard run_guard_task(:start) - interactor.start + interactor.start if interactor listener.start end @@ -200,14 +200,14 @@ module Guard def run UI.clear if options[:clear] - @lock.synchronize do + lock.synchronize do begin - @interactor.stop_if_not_current + interactor.stop_if_not_current if interactor yield rescue Interrupt end - @interactor.start + interactor.start if interactor end end diff --git a/lib/guard/cli.rb b/lib/guard/cli.rb index a5ee77e..95a41a8 100644 --- a/lib/guard/cli.rb +++ b/lib/guard/cli.rb @@ -53,6 +53,12 @@ module Guard :aliases => '-A', :banner => 'Watch for all file modifications including moves and deletions' + method_option :no_interactions, + :type => :boolean, + :default => false, + :aliases => '-i', + :banner => 'Turn off completely any guard terminal interactions' + # Start Guard by initialize the defined Guards and watch the file system. # This is the default task, so calling `guard` is the same as calling `guard start`. # diff --git a/spec/guard_spec.rb b/spec/guard_spec.rb index 4add2b9..7c37ede 100644 --- a/spec/guard_spec.rb +++ b/spec/guard_spec.rb @@ -93,6 +93,17 @@ describe Guard do ::Guard.should_receive(:debug_command_execution) ::Guard.setup(:debug => true) end + + it "initializes the interactor" do + ::Guard.setup + ::Guard.interactor.should be_kind_of(Guard::Interactor) + end + + it "skips the interactor initalization if no-interactions is true" do + ::Guard.interactor = nil + ::Guard.setup(:no_interactions => true) + ::Guard.interactor.should be_nil + end end describe ".guards" do