diff --git a/lib/guard.rb b/lib/guard.rb index 8313e9b..72a8518 100644 --- a/lib/guard.rb +++ b/lib/guard.rb @@ -119,6 +119,16 @@ module Guard 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| diff --git a/lib/guard/cli.rb b/lib/guard/cli.rb index 78e45d9..dc539f0 100644 --- a/lib/guard/cli.rb +++ b/lib/guard/cli.rb @@ -17,6 +17,27 @@ module Guard ::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}" diff --git a/spec/guard_spec.rb b/spec/guard_spec.rb index f5caa7c..d85b8fb 100644 --- a/spec/guard_spec.rb +++ b/spec/guard_spec.rb @@ -130,6 +130,13 @@ describe Guard do 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 }