Class: Guard::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/guard/cli.rb

Overview

Facade for the Guard command line interface managed by [Thor](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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.help(shell, subcommand = false) ⇒ Object



99
100
101
102
# File 'lib/guard/cli.rb', line 99

def self.help(shell, subcommand = false)
  super
  command_help(shell, default_task)
end

Instance Method Details

#init(*plugin_names) ⇒ Object

Initializes the templates of all installed Guard plugins and adds them to the ‘Guardfile` when no Guard name is passed. When passing Guard plugin names it does the same but only for those Guard plugins.

initialize

Parameters:

  • plugin_names (Array<String>)

    the name of the Guard plugins to

See Also:

  • Guardfile.initialize_template
  • Guardfile.initialize_all_templates


181
182
183
184
185
# File 'lib/guard/cli.rb', line 181

def init(*plugin_names)
  env = Cli::Environments::Valid.new(options)
  exitcode = env.initialize_guardfile(plugin_names)
  exit(exitcode)
end

#listObject

List the Guard plugins that are available for use in your system and marks those that are currently used in your ‘Guardfile`.

See Also:

  • DslDescriber.list


132
133
134
135
# File 'lib/guard/cli.rb', line 132

def list
  Cli::Environments::EvaluateOnly.new(options).evaluate
  DslDescriber.new.list
end

#notifiersObject

List the Notifiers for use in your system.

See Also:

  • DslDescriber.notifiers


143
144
145
146
147
# File 'lib/guard/cli.rb', line 143

def notifiers
  Cli::Environments::EvaluateOnly.new(options).evaluate
  # TODO: pass the data directly to the notifiers?
  DslDescriber.new.notifiers
end

#showObject

Shows all Guard plugins and their options that are defined in the ‘Guardfile`

See Also:

  • DslDescriber.show


195
196
197
198
# File 'lib/guard/cli.rb', line 195

def show
  Cli::Environments::EvaluateOnly.new(options).evaluate
  DslDescriber.new.show
end

#startObject

Start Guard by initializing the defined Guard plugins and watch the file system.

This is the default task, so calling ‘guard` is the same as calling `guard start`.

See Also:

  • Guard.start


112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/guard/cli.rb', line 112

def start
  if defined?(JRUBY_VERSION)
    unless options[:no_interactions]
      abort "\nSorry, JRuby and interactive mode are incompatible.\n"\
        "As a workaround, use the '-i' option instead.\n\n"\
        "More info: \n"\
        " * https://github.com/guard/guard/issues/754\n"\
        " * https://github.com/jruby/jruby/issues/2383\n\n"
    end
  end
  exit(Cli::Environments::Valid.new(options).start_guard)
end

#versionObject

Shows the current version of Guard.

See Also:



156
157
158
# File 'lib/guard/cli.rb', line 156

def version
  $stdout.puts "Guard version #{ VERSION }"
end