Skip to content
Browse files

Add new cli option

- The new cli option (-i / --no-interactions) allow to completely turn off any Guard terminal interactions
  • Loading branch information...
1 parent 1a45a77 commit 5111e8594e68d307fb03f6723547c794641a37f2 Thibaud Guillaume-Gentil committed Oct 12, 2011
Showing with 37 additions and 7 deletions.
  1. +1 −0 CHANGELOG.md
  2. +13 −1 README.md
  3. +6 −6 lib/guard.rb
  4. +6 −0 lib/guard/cli.rb
  5. +11 −0 spec/guard_spec.rb
View
1 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][])
View
14 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]
+```
+<a name="interactions" />
Interactions
------------
View
12 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 @@ def setup(options = {})
@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 @@ def start(options = {})
run_guard_task(:start)
- interactor.start
+ interactor.start if interactor
listener.start
end
@@ -200,14 +200,14 @@ def run_on_change(paths)
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
View
6 lib/guard/cli.rb
@@ -53,6 +53,12 @@ class CLI < Thor
: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`.
#
View
11 spec/guard_spec.rb
@@ -93,6 +93,17 @@ class Guard::TestGuard < Guard::Guard
::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

0 comments on commit 5111e85

Please sign in to comment.
Something went wrong with that request. Please try again.