Browse files

Add list command to CLI

This adds a list command, that shows all available
guard gems.

#111
  • Loading branch information...
1 parent 9175b33 commit 091ecf3322b0d794728212050cff6506237f2c58 @docwhat docwhat committed Aug 8, 2011
Showing with 38 additions and 0 deletions.
  1. +10 −0 lib/guard.rb
  2. +21 −0 lib/guard/cli.rb
  3. +7 −0 spec/guard_spec.rb
View
10 lib/guard.rb
@@ -119,6 +119,16 @@ def locate_guard(name)
UI.error "Could not find 'guard-#{name}' gem path."
end
+ ##
+ # Returns a list of guard Gem names installed locally.
+ def guard_gem_names
+ if Gem::Version.create(Gem::VERSION) >= Gem::Version.create('1.8.0')
+ Gem::Specification.find_all.select { |x| x.name =~ /^guard-/ }
+ else
+ Gem.source_index.find_name(/^guard-/)
+ end.map { |x| x.name.sub /^guard-/, '' }
+ end
+
def debug_command_execution
Kernel.send(:alias_method, :original_system, :system)
Kernel.send(:define_method, :system) do |command, *args|
View
21 lib/guard/cli.rb
@@ -17,6 +17,27 @@ def start
::Guard.start(options)
end
+ desc "list", "Lists guards that can be used with init"
+ def list
+ ::Guard::DslDescriber.evaluate_guardfile(options)
+ installed = []
+ ::Guard::DslDescriber.guardfile_structure.each do |group|
+ group[:guards].each {|x| installed << x[:name]} if group[:guards]
+ end
+
+ ::Guard::UI.info "Available guards:"
+ ::Guard::guard_gem_names.sort.each do |name|
+ if installed.include? name
+ ::Guard::UI.info " #{name} *"
+ else
+ ::Guard::UI.info " #{name}"
+ end
+ end
+ ::Guard::UI.info ' '
+ ::Guard::UI.info "See also https://github.com/guard/guard/wiki/List-of-available-Guards"
+ ::Guard::UI.info "* denotes ones already in your Guardfile"
+ end
+
desc "version", "Prints Guard's version"
def version
::Guard::UI.info "Guard version #{Guard::VERSION}"
View
7 spec/guard_spec.rb
@@ -130,6 +130,13 @@ class Inline < Guard
end
end
+ describe ".guard_gem_names" do
+ it "returns the list of guard gems" do
+ gems = Guard.guard_gem_names
+ gems.should include("rspec")
+ end
+ end
+
describe ".supervised_task" do
subject { ::Guard.setup }

0 comments on commit 091ecf3

Please sign in to comment.