Skip to content

Commit

Permalink
Add new cli option
Browse files Browse the repository at this point in the history
- The new cli option (-i / --no-interactions) allow to completely turn off any Guard terminal interactions
  • Loading branch information
thibaudgg committed Oct 12, 2011
1 parent 1a45a77 commit 5111e85
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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][])
Expand Down
14 changes: 13 additions & 1 deletion README.md
Expand Up @@ -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
------------

Expand Down
12 changes: 6 additions & 6 deletions lib/guard.rb
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -140,7 +140,7 @@ def start(options = {})

run_guard_task(:start)

interactor.start
interactor.start if interactor
listener.start
end

Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions lib/guard/cli.rb
Expand Up @@ -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`.
#
Expand Down
11 changes: 11 additions & 0 deletions spec/guard_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 5111e85

Please sign in to comment.