Merge pull request #91 from johnbintz/show-guards-in-guardfile
Show Guards in Guardfile
This commit is contained in:
commit
d3f7d8d6a4
17
README.md
17
README.md
@ -273,6 +273,23 @@ Guard::Dsl.evaluate_guardfile(:guardfile_contents => "
|
||||
")
|
||||
```
|
||||
|
||||
### Listing defined guards/groups for the current project
|
||||
|
||||
You can list the defined groups and guards for the current Guardfile from the command line using `guard show` or `guard -T`:
|
||||
|
||||
``` bash
|
||||
# guard -T
|
||||
|
||||
(global):
|
||||
shell
|
||||
Group backend:
|
||||
bundler
|
||||
rspec: cli => "--color --format doc'
|
||||
Group frontend:
|
||||
coffeescript: output => "public/javascripts/compiled"
|
||||
livereload
|
||||
```
|
||||
|
||||
Create a new guard
|
||||
------------------
|
||||
|
||||
|
13
lib/guard.rb
13
lib/guard.rb
@ -1,11 +1,12 @@
|
||||
module Guard
|
||||
|
||||
autoload :UI, 'guard/ui'
|
||||
autoload :Dsl, 'guard/dsl'
|
||||
autoload :Interactor, 'guard/interactor'
|
||||
autoload :Listener, 'guard/listener'
|
||||
autoload :Watcher, 'guard/watcher'
|
||||
autoload :Notifier, 'guard/notifier'
|
||||
autoload :UI, 'guard/ui'
|
||||
autoload :Dsl, 'guard/dsl'
|
||||
autoload :DslDescriber, 'guard/dsl_describer'
|
||||
autoload :Interactor, 'guard/interactor'
|
||||
autoload :Listener, 'guard/listener'
|
||||
autoload :Watcher, 'guard/watcher'
|
||||
autoload :Notifier, 'guard/notifier'
|
||||
|
||||
class << self
|
||||
attr_accessor :options, :guards, :listener
|
||||
|
@ -37,5 +37,31 @@ module Guard
|
||||
end
|
||||
end
|
||||
|
||||
desc "show", "Show all defined Guards and their options"
|
||||
def show
|
||||
::Guard::DslDescriber.evaluate_guardfile(options)
|
||||
|
||||
::Guard::DslDescriber.guardfile_structure.each do |group|
|
||||
if !group[:guards].empty?
|
||||
if group[:group]
|
||||
::Guard::UI.info "Group #{group[:group]}:"
|
||||
else
|
||||
::Guard::UI.info "(global):"
|
||||
end
|
||||
|
||||
group[:guards].each do |guard|
|
||||
line = " #{guard[:name]}"
|
||||
|
||||
if !guard[:options].empty?
|
||||
line += ": #{guard[:options].collect { |k, v| "#{k} => #{v.inspect}" }.join(", ")}"
|
||||
end
|
||||
::Guard::UI.info line
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
::Guard::UI.info ''
|
||||
end
|
||||
map %w(-T) => :show
|
||||
end
|
||||
end
|
||||
|
29
lib/guard/dsl_describer.rb
Normal file
29
lib/guard/dsl_describer.rb
Normal file
@ -0,0 +1,29 @@
|
||||
require 'guard/dsl'
|
||||
|
||||
module Guard
|
||||
class DslDescriber < Dsl
|
||||
@@guardfile_structure = [ { :guards => [] } ]
|
||||
|
||||
class << self
|
||||
def guardfile_structure
|
||||
@@guardfile_structure
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def group(name, &guard_definition)
|
||||
@@guardfile_structure << { :group => name.to_sym, :guards => [] }
|
||||
|
||||
@group = true
|
||||
guard_definition.call
|
||||
@group = false
|
||||
end
|
||||
|
||||
def guard(name, options = {}, &watch_definition)
|
||||
node = (@group ? @@guardfile_structure.last : @@guardfile_structure.first)
|
||||
|
||||
node[:guards] << { :name => name, :options => options }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
22
man/guard.1
22
man/guard.1
@ -7,7 +7,7 @@
|
||||
\fBguard\fR \- Guard keeps an eye on your file modifications\.
|
||||
.
|
||||
.SH "SYNOPSIS"
|
||||
guard \fIoptions\fR
|
||||
guard \fIcommand\fR \fIoptions\fR
|
||||
.
|
||||
.SH "DESCRIPTION"
|
||||
Guard is a command line tool that easily handle events on files modifications\.
|
||||
@ -26,13 +26,31 @@ Clears the Shell after each change\.
|
||||
Disable notifications (Growl or Libnotify depending on your system)\. Note that notifications can also be disabled globally by setting a GUARD_NOTIFY environment variable to false\. The \fIflag\fR part can be passed to guard using true/false or t/f\.
|
||||
.
|
||||
.TP
|
||||
\fB\-g\fR \fIlist of groups\fR, \fB\-\-group\fR \fIlist of groups\fR
|
||||
\fB\-g\fR \fIgroup\fR \.\.\., \fB\-\-group\fR \fIgroup\fR \.\.\.
|
||||
Runs only the groups specified\.
|
||||
.
|
||||
.TP
|
||||
\fB\-d\fR, \fB\-\-debug\fR
|
||||
Runs Guard in debug mode\.
|
||||
.
|
||||
.TP
|
||||
\fB\-h\fR
|
||||
List all of Guard\'s available commands\.
|
||||
.
|
||||
.SH "COMMANDS"
|
||||
.
|
||||
.TP
|
||||
\fBstart\fR
|
||||
Starts Guard\. This is the default command if none is provided\.
|
||||
.
|
||||
.TP
|
||||
\fBinit\fR [guard]
|
||||
Add the requested guard\'s default Guardfile configuration to the current Guardfile\.
|
||||
.
|
||||
.TP
|
||||
\fBshow\fR, \fB\-T\fR
|
||||
List defined groups and guards for the current Guardfile\.
|
||||
.
|
||||
.SH "EXAMPLES"
|
||||
\fB[bundle exec] guard \-\-clear \-\-group backend frontend \-\-notify false \-\-debug\fR
|
||||
.
|
||||
|
@ -58,9 +58,10 @@
|
||||
<a href="#DESCRIPTION">DESCRIPTION</a>
|
||||
<a href="#HOMEPAGE">HOMEPAGE</a>
|
||||
<a href="#OPTIONS">OPTIONS</a>
|
||||
<a href="#COMMANDS">COMMANDS</a>
|
||||
<a href="#EXAMPLES">EXAMPLES</a>
|
||||
<a href="#AUTHORS-CONTRIBUTORS">AUTHORS / CONTRIBUTORS</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ol class='man-decor man-head man head'>
|
||||
<li class='tl'>guard(1)</li>
|
||||
@ -75,7 +76,7 @@
|
||||
|
||||
<h2 id="SYNOPSIS">SYNOPSIS</h2>
|
||||
|
||||
<p>guard <a href="#OPTIONS" title="OPTIONS" data-bare-link="true">options</a></p>
|
||||
<p>guard <var>command</var> <var>options</var></p>
|
||||
|
||||
<h2 id="DESCRIPTION">DESCRIPTION</h2>
|
||||
|
||||
@ -92,8 +93,18 @@
|
||||
<dt><code>-n</code> <var>flag</var>, <code>--notify</code> <var>flag</var></dt><dd><p>Disable notifications (Growl or Libnotify depending on your system).
|
||||
Note that notifications can also be disabled globally by setting a GUARD_NOTIFY environment variable to false.
|
||||
The <var>flag</var> part can be passed to guard using true/false or t/f.</p></dd>
|
||||
<dt><code>-g</code> <var>list of groups</var>, <code>--group</code> <var>list of groups</var></dt><dd><p>Runs only the groups specified.</p></dd>
|
||||
<dt><code>-g</code> <var>group</var> ..., <code>--group</code> <var>group</var> ...</dt><dd><p>Runs only the groups specified.</p></dd>
|
||||
<dt><code>-d</code>, <code>--debug</code></dt><dd><p>Runs Guard in debug mode.</p></dd>
|
||||
<dt class="flush"><code>-h</code></dt><dd><p>List all of Guard's available commands.</p></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
<h2 id="COMMANDS">COMMANDS</h2>
|
||||
|
||||
<dl>
|
||||
<dt class="flush"><code>start</code></dt><dd><p>Starts Guard. This is the default command if none is provided.</p></dd>
|
||||
<dt><code>init</code> [guard]</dt><dd><p>Add the requested guard's default Guardfile configuration to the current Guardfile.</p></dd>
|
||||
<dt><code>show</code>, <code>-T</code></dt><dd><p>List defined groups and guards for the current Guardfile.</p></dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
18
man/guard.md
18
man/guard.md
@ -3,7 +3,7 @@ guard(1) -- Guard keeps an eye on your file modifications.
|
||||
|
||||
## SYNOPSIS
|
||||
|
||||
guard [options]
|
||||
guard <command> <options>
|
||||
|
||||
## DESCRIPTION
|
||||
|
||||
@ -23,12 +23,26 @@ https://github.com/guard/guard
|
||||
Note that notifications can also be disabled globally by setting a GUARD_NOTIFY environment variable to false.
|
||||
The <flag> part can be passed to guard using true/false or t/f.
|
||||
|
||||
* `-g` <list of groups>, `--group` <list of groups>:
|
||||
* `-g` <group> ..., `--group` <group> ...:
|
||||
Runs only the groups specified.
|
||||
|
||||
* `-d`, `--debug`:
|
||||
Runs Guard in debug mode.
|
||||
|
||||
* `-h`:
|
||||
List all of Guard's available commands.
|
||||
|
||||
## COMMANDS
|
||||
|
||||
* `start`:
|
||||
Starts Guard. This is the default command if none is provided.
|
||||
|
||||
* `init` [guard]:
|
||||
Add the requested guard's default Guardfile configuration to the current Guardfile.
|
||||
|
||||
* `show`, `-T`:
|
||||
List defined groups and guards for the current Guardfile.
|
||||
|
||||
## EXAMPLES
|
||||
|
||||
`[bundle exec] guard --clear --group backend frontend --notify false --debug`
|
||||
|
34
spec/guard/dsl_describer_spec.rb
Normal file
34
spec/guard/dsl_describer_spec.rb
Normal file
@ -0,0 +1,34 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Guard::DslDescriber do
|
||||
subject { described_class }
|
||||
|
||||
it 'should evaluate a Guardfile and create the right structure' do
|
||||
mixed_guardfile_string = <<-GUARD
|
||||
guard 'test', :a => :b do
|
||||
watch('c')
|
||||
end
|
||||
|
||||
group :a do
|
||||
guard 'test' do
|
||||
watch('c')
|
||||
end
|
||||
end
|
||||
|
||||
group "b" do
|
||||
guard 'another' do
|
||||
watch('c')
|
||||
end
|
||||
end
|
||||
GUARD
|
||||
|
||||
subject.evaluate_guardfile(:guardfile_contents => mixed_guardfile_string)
|
||||
|
||||
subject.guardfile_structure.should == [
|
||||
{ :guards => [ { :name => 'test', :options => { :a => :b } } ] },
|
||||
{ :group => :a, :guards => [ { :name => 'test', :options => {} } ] },
|
||||
{ :group => :b, :guards => [ { :name => 'another', :options => {} } ] }
|
||||
]
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user