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 - +
  1. guard(1)
  2. @@ -75,7 +76,7 @@

    SYNOPSIS

    -

    guard options

    +

    guard command options

    DESCRIPTION

    @@ -92,8 +93,18 @@
    -n flag, --notify flag

    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 flag part can be passed to guard using true/false or t/f.

    -
    -g list of groups, --group list of groups

    Runs 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.

    + + + +

    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.

    diff --git a/man/guard.md b/man/guard.md index 723ab6b..43c6780 100644 --- a/man/guard.md +++ b/man/guard.md @@ -3,7 +3,7 @@ guard(1) -- Guard keeps an eye on your file modifications. ## SYNOPSIS -guard [options] +guard ## 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 part can be passed to guard using true/false or t/f. -* `-g` , `--group` : +* `-g` ..., `--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` diff --git a/spec/guard/dsl_describer_spec.rb b/spec/guard/dsl_describer_spec.rb new file mode 100644 index 0000000..3850186 --- /dev/null +++ b/spec/guard/dsl_describer_spec.rb @@ -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