diff --git a/README.md b/README.md index 56eb228..1979ed8 100644 --- a/README.md +++ b/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 ------------------ diff --git a/lib/guard.rb b/lib/guard.rb index 60f789e..12b8d47 100644 --- a/lib/guard.rb +++ b/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 diff --git a/lib/guard/cli.rb b/lib/guard/cli.rb index c4c8db2..9bf323a 100644 --- a/lib/guard/cli.rb +++ b/lib/guard/cli.rb @@ -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 diff --git a/lib/guard/dsl_describer.rb b/lib/guard/dsl_describer.rb new file mode 100644 index 0000000..db95d8b --- /dev/null +++ b/lib/guard/dsl_describer.rb @@ -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 + diff --git a/man/guard.1 b/man/guard.1 index 69de2c5..5e5f92e 100644 --- a/man/guard.1 +++ b/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 . diff --git a/man/guard.1.html b/man/guard.1.html index 41e6181..538feea 100644 --- a/man/guard.1.html +++ b/man/guard.1.html @@ -58,9 +58,10 @@ DESCRIPTION HOMEPAGE OPTIONS + COMMANDS EXAMPLES AUTHORS / CONTRIBUTORS - +
guard options
+guard command options
-n
flag, --notify
flagDisable 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 flag part can be passed to guard using true/false or t/f.
-g
list of groups, --group
list of groupsRuns only the groups specified.
-g
group ..., --group
group ...Runs only the groups specified.
-d
, --debug
Runs Guard in debug mode.
-h
List all of Guard's available 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.