From aa3010af915e71b091239be6ca761fe5659ce408 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 21 Jun 2011 09:48:27 -0400 Subject: [PATCH 1/6] show the guards defined in the Guardfile with 'guard show' or 'guard -T' --- lib/guard.rb | 13 ++++++------ lib/guard/cli.rb | 26 ++++++++++++++++++++++++ lib/guard/dsl.rb | 4 ++++ lib/guard/dsl_describer.rb | 29 +++++++++++++++++++++++++++ spec/guard/dsl_describer_spec.rb | 34 ++++++++++++++++++++++++++++++++ spec/guard/dsl_spec.rb | 3 +++ 6 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 lib/guard/dsl_describer.rb create mode 100644 spec/guard/dsl_describer_spec.rb 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..eb724fb 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] + puts "Group #{group[:group]}:" + else + puts "(Global):" + end + + group[:guards].each do |guard| + print " #{guard[:name]}" + + if !guard[:options].empty? + print ": #{guard[:options].collect { |k, v| "#{k} => #{v}" }.join(", ")}" + end + puts + end + end + end + + puts + end + map %w(-T) => :show end end diff --git a/lib/guard/dsl.rb b/lib/guard/dsl.rb index 68b9f8f..9d322b1 100644 --- a/lib/guard/dsl.rb +++ b/lib/guard/dsl.rb @@ -77,6 +77,10 @@ module Guard File.exist?(local_guardfile_path) ? local_guardfile_path : home_guardfile_path end + def guardfile_structure + + end + private def local_guardfile_path 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/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 diff --git a/spec/guard/dsl_spec.rb b/spec/guard/dsl_spec.rb index 5312226..a5474ad 100644 --- a/spec/guard/dsl_spec.rb +++ b/spec/guard/dsl_spec.rb @@ -127,6 +127,9 @@ describe Guard::Dsl do lambda { subject.evaluate_guardfile(:guardfile_contents => invalid_guardfile_string ) }.should raise_error end + it "should generate a displayable structure from the Guardfile data" do + end + describe ".guardfile_default_path" do let(:local_path) { File.join(Dir.pwd, 'Guardfile') } let(:user_path) { File.expand_path(File.join("~", 'Guardfile')) } From ef79b5e720d4628eed80c5016cb4e7d239a78a89 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 21 Jun 2011 09:52:23 -0400 Subject: [PATCH 2/6] use Guard::UI instead of straight puts --- lib/guard/cli.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/guard/cli.rb b/lib/guard/cli.rb index eb724fb..cb913a5 100644 --- a/lib/guard/cli.rb +++ b/lib/guard/cli.rb @@ -44,23 +44,23 @@ module Guard ::Guard::DslDescriber.guardfile_structure.each do |group| if !group[:guards].empty? if group[:group] - puts "Group #{group[:group]}:" + ::Guard::UI.info "Group #{group[:group]}:" else - puts "(Global):" + ::Guard::UI.info "(global):" end group[:guards].each do |guard| - print " #{guard[:name]}" + line = " #{guard[:name]}" if !guard[:options].empty? - print ": #{guard[:options].collect { |k, v| "#{k} => #{v}" }.join(", ")}" + line += ": #{guard[:options].collect { |k, v| "#{k} => #{v}" }.join(", ")}" end - puts + ::Guard::UI.info line end end end - puts + ::Guard::UI.info '' end map %w(-T) => :show end From ae320fe0036bb561b13a124e59523c8d4317e766 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 21 Jun 2011 09:58:02 -0400 Subject: [PATCH 3/6] remove useless method --- lib/guard/dsl.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/guard/dsl.rb b/lib/guard/dsl.rb index 9d322b1..68b9f8f 100644 --- a/lib/guard/dsl.rb +++ b/lib/guard/dsl.rb @@ -77,10 +77,6 @@ module Guard File.exist?(local_guardfile_path) ? local_guardfile_path : home_guardfile_path end - def guardfile_structure - - end - private def local_guardfile_path From c3ddeac36fda37cbd098999a077310766f3d31ed Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 21 Jun 2011 10:33:21 -0400 Subject: [PATCH 4/6] remove empty spec --- spec/guard/dsl_spec.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/spec/guard/dsl_spec.rb b/spec/guard/dsl_spec.rb index a5474ad..5312226 100644 --- a/spec/guard/dsl_spec.rb +++ b/spec/guard/dsl_spec.rb @@ -127,9 +127,6 @@ describe Guard::Dsl do lambda { subject.evaluate_guardfile(:guardfile_contents => invalid_guardfile_string ) }.should raise_error end - it "should generate a displayable structure from the Guardfile data" do - end - describe ".guardfile_default_path" do let(:local_path) { File.join(Dir.pwd, 'Guardfile') } let(:user_path) { File.expand_path(File.join("~", 'Guardfile')) } From 72f31c9eba36a44cc8c5ed1666d234dfcbc7ca68 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 21 Jun 2011 10:34:11 -0400 Subject: [PATCH 5/6] inspect values rather than simply print them, so that strings appear quoted --- lib/guard/cli.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/guard/cli.rb b/lib/guard/cli.rb index cb913a5..9bf323a 100644 --- a/lib/guard/cli.rb +++ b/lib/guard/cli.rb @@ -53,7 +53,7 @@ module Guard line = " #{guard[:name]}" if !guard[:options].empty? - line += ": #{guard[:options].collect { |k, v| "#{k} => #{v}" }.join(", ")}" + line += ": #{guard[:options].collect { |k, v| "#{k} => #{v.inspect}" }.join(", ")}" end ::Guard::UI.info line end From 7ba4819d3bb62d27ced62991fea8f46b034263ba Mon Sep 17 00:00:00 2001 From: John Bintz Date: Tue, 21 Jun 2011 11:00:00 -0400 Subject: [PATCH 6/6] documentation and man page updates --- README.md | 17 +++++++++++++++++ man/guard.1 | 22 ++++++++++++++++++++-- man/guard.1.html | 17 ++++++++++++++--- man/guard.md | 18 ++++++++++++++++-- 4 files changed, 67 insertions(+), 7 deletions(-) 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/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`