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.

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


101
102
103
104
# File 'lib/guard/cli.rb', line 101

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

183
184
185
186
187
# File 'lib/guard/cli.rb', line 183

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

134
135
136
137
# File 'lib/guard/cli.rb', line 134

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

145
146
147
148
149
# File 'lib/guard/cli.rb', line 145

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

197
198
199
200
# File 'lib/guard/cli.rb', line 197

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

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

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:


158
159
160
# File 'lib/guard/cli.rb', line 158

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