Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add list command to CLI #112

Merged
merged 2 commits into from

3 participants

@docwhat

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

#111

@docwhat docwhat Add list command to CLI
This adds a list command, that shows all available
guard gems.

guard#111
091ecf3
@thibaudgg
Owner

Looks great thanks. Please can you also update the README before I merged it.

@docwhat

How is that? It was the only logical place I could think of to add it.

Ciao!

@thibaudgg
Owner

Sounds, good. Thanks!

@thibaudgg thibaudgg merged commit db730ee into from
@jasonnoble

This closes #111 ?

@docwhat

yup. I closed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 9, 2011
  1. @docwhat

    Add list command to CLI

    docwhat authored
    This adds a list command, that shows all available
    guard gems.
    
    guard#111
  2. @docwhat
This page is out of date. Refresh to see the latest.
View
6 README.md
@@ -193,6 +193,12 @@ Add it to your Gemfile (inside the `development` group):
gem '<guard-name>'
```
+You can list all guards installed on your system with:
+
+``` bash
+$ guard list
+```
+
Insert default guard's definition to your Guardfile by running this command:
``` bash
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 }
Something went wrong with that request. Please try again.