Add new cli option
- The new cli option (-i / --no-interactions) allow to completely turn off any Guard terminal interactions
This commit is contained in:
parent
1a45a77969
commit
5111e8594e
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
### Improvements
|
### Improvements
|
||||||
|
|
||||||
|
- Add cli option (-i / --no-interactions) to turn off Guard terminal interactions. ([@thibaudgg][])
|
||||||
- Add support for Growl Notification Transport Protocol. ([@netzpirat][])
|
- Add support for Growl Notification Transport Protocol. ([@netzpirat][])
|
||||||
- [#157](https://github.com/guard/guard/pull/157): Allow any return from the Guard watchers. ([@earlonrails][])
|
- [#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][])
|
- [#156](https://github.com/guard/guard/pull/156): Log error and diagnostic messages to STDERR. ([@sunaku][])
|
||||||
|
14
README.md
14
README.md
@ -194,10 +194,22 @@ $ guard start -A
|
|||||||
$ guard start --watch-all-modifications
|
$ 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:
|
An exhaustive list of options is available with:
|
||||||
|
|
||||||
$ guard help [TASK]
|
``` bash
|
||||||
|
$ guard help [TASK]
|
||||||
|
```
|
||||||
|
|
||||||
|
<a name="interactions" />
|
||||||
Interactions
|
Interactions
|
||||||
------------
|
------------
|
||||||
|
|
||||||
|
12
lib/guard.rb
12
lib/guard.rb
@ -16,7 +16,7 @@ module Guard
|
|||||||
autoload :Hook, 'guard/hook'
|
autoload :Hook, 'guard/hook'
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
attr_accessor :options, :interactor, :listener
|
attr_accessor :options, :interactor, :listener, :lock
|
||||||
|
|
||||||
# Creates the initial Guardfile template or add a Guard implementation
|
# Creates the initial Guardfile template or add a Guard implementation
|
||||||
# Guardfile template to an existing Guardfile.
|
# Guardfile template to an existing Guardfile.
|
||||||
@ -56,7 +56,7 @@ module Guard
|
|||||||
@options = options
|
@options = options
|
||||||
@guards = []
|
@guards = []
|
||||||
@groups = [Group.new(:default)]
|
@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)
|
@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
|
@options[:notify] && ENV['GUARD_NOTIFY'] != 'false' ? Notifier.turn_on : Notifier.turn_off
|
||||||
@ -140,7 +140,7 @@ module Guard
|
|||||||
|
|
||||||
run_guard_task(:start)
|
run_guard_task(:start)
|
||||||
|
|
||||||
interactor.start
|
interactor.start if interactor
|
||||||
listener.start
|
listener.start
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -200,14 +200,14 @@ module Guard
|
|||||||
def run
|
def run
|
||||||
UI.clear if options[:clear]
|
UI.clear if options[:clear]
|
||||||
|
|
||||||
@lock.synchronize do
|
lock.synchronize do
|
||||||
begin
|
begin
|
||||||
@interactor.stop_if_not_current
|
interactor.stop_if_not_current if interactor
|
||||||
yield
|
yield
|
||||||
rescue Interrupt
|
rescue Interrupt
|
||||||
end
|
end
|
||||||
|
|
||||||
@interactor.start
|
interactor.start if interactor
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -53,6 +53,12 @@ module Guard
|
|||||||
:aliases => '-A',
|
:aliases => '-A',
|
||||||
:banner => 'Watch for all file modifications including moves and deletions'
|
: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.
|
# 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`.
|
# This is the default task, so calling `guard` is the same as calling `guard start`.
|
||||||
#
|
#
|
||||||
|
@ -93,6 +93,17 @@ describe Guard do
|
|||||||
::Guard.should_receive(:debug_command_execution)
|
::Guard.should_receive(:debug_command_execution)
|
||||||
::Guard.setup(:debug => true)
|
::Guard.setup(:debug => true)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe ".guards" do
|
describe ".guards" do
|
||||||
|
Loading…
Reference in New Issue
Block a user