2010-10-03 21:00:33 +00:00
|
|
|
require 'thor'
|
|
|
|
require 'guard/version'
|
|
|
|
|
|
|
|
module Guard
|
|
|
|
class CLI < Thor
|
|
|
|
default_task :start
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-07-28 21:59:31 +00:00
|
|
|
method_option :clear, :type => :boolean, :default => false, :aliases => '-c', :banner => "Auto clear shell before each change/run_all/reload"
|
|
|
|
method_option :notify, :type => :boolean, :default => true, :aliases => '-n', :banner => "Notifications feature (growl/libnotify)"
|
|
|
|
method_option :debug, :type => :boolean, :default => false, :aliases => '-d', :banner => "Print debug messages"
|
|
|
|
method_option :group, :type => :array, :default => [], :aliases => '-g', :banner => "Run only the passed groups"
|
|
|
|
method_option :watchdir, :type => :string, :aliases => '-w', :banner => "Specify the directory to watch"
|
|
|
|
method_option :guardfile, :type => :string, :aliases => '-G', :banner => "Specify a Guardfile"
|
2011-07-22 21:27:03 +00:00
|
|
|
|
2010-12-17 17:13:31 +00:00
|
|
|
desc "start", "Starts Guard"
|
2010-10-03 21:00:33 +00:00
|
|
|
def start
|
2010-10-08 13:00:45 +00:00
|
|
|
::Guard.start(options)
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-08-09 00:11:22 +00:00
|
|
|
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
|
|
|
|
|
2011-06-19 10:22:32 +00:00
|
|
|
desc "version", "Prints Guard's version"
|
2010-10-03 21:00:33 +00:00
|
|
|
def version
|
2010-10-08 13:00:45 +00:00
|
|
|
::Guard::UI.info "Guard version #{Guard::VERSION}"
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
|
|
|
map %w(-v --version) => :version
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-06-19 10:22:32 +00:00
|
|
|
desc "init [GUARD]", "Generates a Guardfile into the current working directory, or insert the given GUARD in an existing Guardfile"
|
2010-10-07 20:37:30 +00:00
|
|
|
def init(guard_name = nil)
|
|
|
|
if !File.exist?("Guardfile")
|
|
|
|
puts "Writing new Guardfile to #{Dir.pwd}/Guardfile"
|
|
|
|
FileUtils.cp(File.expand_path('../templates/Guardfile', __FILE__), 'Guardfile')
|
|
|
|
elsif guard_name.nil?
|
2010-10-08 13:00:45 +00:00
|
|
|
::Guard::UI.error "Guardfile already exists at #{Dir.pwd}/Guardfile"
|
2010-10-07 20:37:30 +00:00
|
|
|
exit 1
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-07 20:37:30 +00:00
|
|
|
if guard_name
|
2010-10-08 13:00:45 +00:00
|
|
|
guard_class = ::Guard.get_guard_class(guard_name)
|
2010-10-07 20:37:30 +00:00
|
|
|
guard_class.init(guard_name)
|
|
|
|
end
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-06-21 13:48:27 +00:00
|
|
|
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]
|
2011-06-21 13:52:23 +00:00
|
|
|
::Guard::UI.info "Group #{group[:group]}:"
|
2011-06-21 13:48:27 +00:00
|
|
|
else
|
2011-06-21 13:52:23 +00:00
|
|
|
::Guard::UI.info "(global):"
|
2011-06-21 13:48:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
group[:guards].each do |guard|
|
2011-06-21 13:52:23 +00:00
|
|
|
line = " #{guard[:name]}"
|
2011-06-21 13:48:27 +00:00
|
|
|
|
|
|
|
if !guard[:options].empty?
|
2011-06-21 14:34:11 +00:00
|
|
|
line += ": #{guard[:options].collect { |k, v| "#{k} => #{v.inspect}" }.join(", ")}"
|
2011-06-21 13:48:27 +00:00
|
|
|
end
|
2011-06-21 13:52:23 +00:00
|
|
|
::Guard::UI.info line
|
2011-06-21 13:48:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-21 13:52:23 +00:00
|
|
|
::Guard::UI.info ''
|
2011-06-21 13:48:27 +00:00
|
|
|
end
|
|
|
|
map %w(-T) => :show
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2011-06-19 10:22:32 +00:00
|
|
|
end
|