2010-10-03 21:00:33 +00:00
|
|
|
require 'thor'
|
|
|
|
require 'guard/version'
|
|
|
|
|
|
|
|
module Guard
|
2011-09-20 08:05:11 +00:00
|
|
|
|
|
|
|
# Guard command line interface managed by [Thor](https://github.com/wycats/thor).
|
2011-09-20 23:30:35 +00:00
|
|
|
# This is the main interface to Guard that is called by the Guard binary `bin/guard`.
|
2011-09-20 08:05:11 +00:00
|
|
|
#
|
2010-10-03 21:00:33 +00:00
|
|
|
class CLI < Thor
|
2011-09-20 08:05:11 +00:00
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
default_task :start
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-09-20 08:05:11 +00:00
|
|
|
desc 'start', 'Starts Guard'
|
|
|
|
|
|
|
|
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'
|
2011-07-22 21:27:03 +00:00
|
|
|
|
2011-09-20 08:05:11 +00:00
|
|
|
method_option :guardfile,
|
|
|
|
:type => :string,
|
|
|
|
:aliases => '-G',
|
|
|
|
:banner => 'Specify a Guardfile'
|
2011-07-22 21:27:03 +00:00
|
|
|
|
2011-09-21 22:57:40 +00:00
|
|
|
method_option :watch_all_modifications,
|
2011-09-28 22:27:19 +00:00
|
|
|
:type => :boolean,
|
|
|
|
:default => false,
|
2011-09-21 22:57:40 +00:00
|
|
|
:aliases => '-A',
|
|
|
|
:banner => "Watch for all file modifications including moves and deletions"
|
|
|
|
|
2011-09-20 08:05:11 +00:00
|
|
|
# Start Guard by initialize the defined Guards and watch the file system.
|
|
|
|
# This is the default task, so calling `guard` is the same as calling `guard start`.
|
|
|
|
#
|
|
|
|
# @see Guard.start
|
|
|
|
#
|
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-09-20 08:05:11 +00:00
|
|
|
desc 'list', 'Lists guards that can be used with init'
|
|
|
|
|
|
|
|
# List the Guards that are available for use in your system and marks
|
|
|
|
# those that are currently used in your `Guardfile`.
|
|
|
|
#
|
2011-09-20 23:30:35 +00:00
|
|
|
# @example Guard list output
|
2011-09-20 08:05:11 +00:00
|
|
|
#
|
|
|
|
# Available guards:
|
|
|
|
# bundler *
|
|
|
|
# livereload
|
|
|
|
# ronn
|
|
|
|
# rspec *
|
|
|
|
# spork
|
|
|
|
#
|
|
|
|
# See also https://github.com/guard/guard/wiki/List-of-available-Guards
|
|
|
|
# * denotes ones already in your Guardfile
|
|
|
|
#
|
|
|
|
# @see Guard::DslDescriber
|
|
|
|
#
|
2011-08-09 00:11:22 +00:00
|
|
|
def list
|
2011-09-20 08:05:11 +00:00
|
|
|
Guard::DslDescriber.evaluate_guardfile(options)
|
|
|
|
|
|
|
|
installed = Guard::DslDescriber.guardfile_structure.inject([]) do |installed, group|
|
|
|
|
group[:guards].each { |guard| installed << guard[:name] } if group[:guards]
|
|
|
|
installed
|
2011-08-09 00:11:22 +00:00
|
|
|
end
|
|
|
|
|
2011-09-20 08:05:11 +00:00
|
|
|
Guard::UI.info 'Available guards:'
|
|
|
|
|
|
|
|
Guard::guard_gem_names.sort.uniq.each do |name|
|
|
|
|
Guard::UI.info " #{ name } #{ installed.include?(name) ? '*' : '' }"
|
2011-08-09 00:11:22 +00:00
|
|
|
end
|
2011-09-20 08:05:11 +00:00
|
|
|
|
|
|
|
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'
|
2011-08-09 00:11:22 +00:00
|
|
|
end
|
|
|
|
|
2011-09-20 08:05:11 +00:00
|
|
|
desc 'version', 'Show the Guard version'
|
|
|
|
map %w(-v --version) => :version
|
|
|
|
|
|
|
|
# Shows the current version of Guard.
|
|
|
|
#
|
|
|
|
# @see Guard::VERSION
|
|
|
|
#
|
2010-10-03 21:00:33 +00:00
|
|
|
def version
|
2011-09-20 08:05:11 +00:00
|
|
|
Guard::UI.info "Guard version #{ Guard::VERSION }"
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-09-20 08:05:11 +00:00
|
|
|
desc 'init [GUARD]', 'Generates a Guardfile at the current working directory, or insert the given GUARD to an existing Guardfile'
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2011-09-20 08:05:11 +00:00
|
|
|
# Appends the Guard template to the `Guardfile`, or creates an initial
|
2011-09-20 23:30:35 +00:00
|
|
|
# `Guardfile` when no Guard name is passed.
|
2011-09-20 08:05:11 +00:00
|
|
|
#
|
|
|
|
# @param [String] guard_name the name of the Guard to initialize
|
|
|
|
#
|
|
|
|
def init(guard_name = nil)
|
2011-09-28 22:27:19 +00:00
|
|
|
if !File.exist?('Guardfile')
|
2011-10-02 13:15:48 +00:00
|
|
|
puts "Writing new Guardfile to #{Dir.pwd}/Guardfile"
|
2011-09-28 22:27:19 +00:00
|
|
|
FileUtils.cp(File.expand_path('../templates/Guardfile', __FILE__), 'Guardfile')
|
|
|
|
elsif guard_name.nil?
|
|
|
|
Guard::UI.error "Guardfile already exists at #{ Dir.pwd }/Guardfile"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
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-09-20 08:05:11 +00:00
|
|
|
desc 'show', 'Show all defined Guards and their options'
|
|
|
|
map %w(-T) => :show
|
|
|
|
|
|
|
|
# Shows all Guards and their options that are defined in
|
|
|
|
# the `Guardfile`.
|
|
|
|
#
|
|
|
|
# @example guard show output
|
|
|
|
#
|
|
|
|
# (global):
|
|
|
|
# bundler
|
|
|
|
# coffeescript: input => "app/assets/javascripts", noop => true
|
|
|
|
# jasmine
|
|
|
|
# rspec: cli => "--fail-fast --format Fuubar
|
|
|
|
#
|
|
|
|
# @see Guard::DslDescriber
|
|
|
|
#
|
2011-06-21 13:48:27 +00:00
|
|
|
def show
|
2011-09-20 08:05:11 +00:00
|
|
|
Guard::DslDescriber.evaluate_guardfile(options)
|
2011-06-21 13:48:27 +00:00
|
|
|
|
2011-09-20 08:05:11 +00:00
|
|
|
Guard::DslDescriber.guardfile_structure.each do |group|
|
|
|
|
unless group[:guards].empty?
|
2011-06-21 13:48:27 +00:00
|
|
|
if group[:group]
|
2011-09-20 08:05:11 +00:00
|
|
|
Guard::UI.info "Group #{ group[:group] }:"
|
2011-06-21 13:48:27 +00:00
|
|
|
else
|
2011-09-20 08:05:11 +00:00
|
|
|
Guard::UI.info '(global):'
|
2011-06-21 13:48:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
group[:guards].each do |guard|
|
2011-09-20 08:05:11 +00:00
|
|
|
line = " #{ guard[:name] }"
|
2011-06-21 13:48:27 +00:00
|
|
|
|
2011-09-20 08:05:11 +00:00
|
|
|
unless guard[:options].empty?
|
|
|
|
line += ": #{ guard[:options].collect { |k, v| "#{ k } => #{ v.inspect }" }.join(', ') }"
|
2011-06-21 13:48:27 +00:00
|
|
|
end
|
2011-09-20 08:05:11 +00:00
|
|
|
|
|
|
|
Guard::UI.info line
|
2011-06-21 13:48:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-20 08:05:11 +00:00
|
|
|
Guard::UI.info ''
|
2011-06-21 13:48:27 +00:00
|
|
|
end
|
2011-09-20 08:05:11 +00:00
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2011-06-19 10:22:32 +00:00
|
|
|
end
|