Add list command to CLI

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

https://github.com/guard/guard/issues/111
This commit is contained in:
Christian Höltje 2011-08-08 20:11:22 -04:00
parent 9175b33da4
commit 091ecf3322
3 changed files with 38 additions and 0 deletions

View File

@ -119,6 +119,16 @@ module Guard
UI.error "Could not find 'guard-#{name}' gem path." UI.error "Could not find 'guard-#{name}' gem path."
end 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 def debug_command_execution
Kernel.send(:alias_method, :original_system, :system) Kernel.send(:alias_method, :original_system, :system)
Kernel.send(:define_method, :system) do |command, *args| Kernel.send(:define_method, :system) do |command, *args|

View File

@ -17,6 +17,27 @@ module Guard
::Guard.start(options) ::Guard.start(options)
end 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" desc "version", "Prints Guard's version"
def version def version
::Guard::UI.info "Guard version #{Guard::VERSION}" ::Guard::UI.info "Guard version #{Guard::VERSION}"

View File

@ -130,6 +130,13 @@ describe Guard do
end end
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 describe ".supervised_task" do
subject { ::Guard.setup } subject { ::Guard.setup }