master/lib/guard/cli.rb

114 lines
3.3 KiB
Ruby
Raw Normal View History

2010-10-03 21:00:33 +00:00
require 'thor'
require 'guard/version'
module Guard
2011-09-20 08:05:11 +00:00
# Facade for the Guard command line interface managed by [Thor](https://github.com/wycats/thor).
# This is the main interface to Guard that is called by the Guard binary `bin/guard`.
# Do not put any logic in here, create a class and delegate instead.
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-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-09-20 08:05:11 +00:00
method_option :guardfile,
:type => :string,
:aliases => '-G',
:banner => 'Specify a Guardfile'
method_option :watch_all_modifications,
:type => :boolean,
:default => false,
: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-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`.
#
# @see Guard::DslDescriber.list
#
def list
Guard::DslDescriber.list(options)
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-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-09-20 08:05:11 +00:00
# Appends the Guard template to the `Guardfile`, or creates an initial
# `Guardfile` when no Guard name is passed.
2011-09-20 08:05:11 +00:00
#
# @see Guard.initialize_template
#
2011-09-20 08:05:11 +00:00
# @param [String] guard_name the name of the Guard to initialize
#
def init(guard_name = nil)
Guard.initialize_template(guard_name)
2010-10-07 20:37:30 +00:00
end
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`.
#
# @see Guard::DslDescriber.show
#
def show
Guard::DslDescriber.show(options)
end
2011-09-20 08:05:11 +00:00
2010-10-03 21:00:33 +00:00
end
end