Module: Guard::Commander

Included in:
Guard
Defined in:
lib/guard/commander.rb

Overview

Commands supported by guard

Instance Method Summary collapse

Instance Method Details

#pause(expected = nil) ⇒ Object

Pause Guard listening to file changes.


88
89
90
91
92
93
94
95
96
97
# File 'lib/guard/commander.rb', line 88

def pause(expected = nil)
  paused = listener.paused?
  states = { paused: true, unpaused: false, toggle: !paused }
  pause = states[expected || :toggle]
  fail ArgumentError, "invalid mode: #{expected.inspect}" if pause.nil?
  return if pause == paused

  listener.public_send(pause ? :pause : :start)
  UI.info "File event handling has been #{pause ? 'paused' : 'resumed'}"
end

#reload(scopes = {}) ⇒ Object

Reload Guardfile and all Guard plugins currently enabled. If no scope is given, then the Guardfile will be re-evaluated, which results in a stop/start, which makes the reload obsolete.


70
71
72
73
74
# File 'lib/guard/commander.rb', line 70

def reload(scopes = {})
  UI.clear(force: true)
  UI.action_with_scopes("Reload", scopes)
  Runner.new.run(:reload, scopes)
end

#run_all(scopes = {}) ⇒ Object

Trigger `run_all` on all Guard plugins currently enabled.


80
81
82
83
84
# File 'lib/guard/commander.rb', line 80

def run_all(scopes = {})
  UI.clear(force: true)
  UI.action_with_scopes("Run", scopes)
  Runner.new.run(:run_all, scopes)
end

#showObject


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

def show
  DslDescriber.new.show
end

#start(options = {}) ⇒ Object

Start Guard by evaluating the `Guardfile`, initializing declared Guard plugins and starting the available file change listener. Main method for Guard that is called from the CLI when Guard starts.

  • Setup Guard internals

  • Evaluate the `Guardfile`

  • Configure Notifiers

  • Initialize the declared Guard plugins

  • Start the available file change listener

Options Hash (options):

  • clear (Boolean)

    if auto clear the UI should be done

  • notify (Boolean)

    if system notifications should be shown

  • debug (Boolean)

    if debug output should be shown

  • group (Array<String>)

    the list of groups to start

  • watchdir (String)

    the director to watch

  • guardfile (String)

    the path to the Guardfile

See Also:


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/guard/commander.rb', line 31

def start(options = {})
  setup(options)
  UI.debug "Guard starts all plugins"
  Runner.new.run(:start)
  listener.start

  watched = Guard.state.session.watchdirs.join("', '")
  UI.info "Guard is now watching at '#{ watched }'"

  exitcode = 0
  begin
    while interactor.foreground != :exit
      Guard.queue.process while Guard.queue.pending?
    end
  rescue Interrupt
  rescue SystemExit => e
    exitcode = e.status
  end

  exitcode
ensure
  stop
end

#stopObject


55
56
57
58
59
60
61
62
# File 'lib/guard/commander.rb', line 55

def stop
  listener&.stop
  interactor&.background
  UI.debug "Guard stops all plugins"
  Runner.new.run(:stop)
  Notifier.disconnect
  UI.info "Bye bye...", reset: true
end