Class: Vagrant::Notify::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-notify/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.synopsisObject



8
9
10
# File 'lib/vagrant-notify/command.rb', line 8

def self.synopsis
  "plugin: vagrant-notify: forwards notify-send from guest to host machine and notifies provisioning status"
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/vagrant-notify/command.rb', line 12

def execute
  options = {}
  opts = OptionParser.new do |o|
    o.banner = 'Usage: vagrant notify'
    o.separator ''
    o.version = Vagrant::Notify::VERSION
    o.program_name = 'vagrant notify'

    o.on('-h', '--help', 'Display this screen.' )                           { options[:help] = true }
    o.on('--status', 'Show vagrant-notify-server daemon status. (default)') { options[:status] = true }
    o.on('--start', 'Manually start vagrant-notify-server daemon.')         { options[:start] = true }
    o.on('--stop', 'Manually stop vagrant-notify-server daemon.')           { options[:stop] = true }
    o.on('--restart', 'Manually restart vagrant-notify-server daemon.')     { options[:restart] = true }
  end

  argv = parse_options(opts)
 
  with_target_vms(argv, options) do |machine|

    if machine.state.id != :running
      @env.ui.info("Guest '#{machine.name}' is not running.")
      next
    end

    if options[:help]
      @env.ui.info(opts)
    end

    if options[:status] || options.length == 0
      @env.action_runner.run(Vagrant::Notify::Action.action_status_server, {
        :machine => machine,
      })
    end

    if options[:stop]
      @env.action_runner.run(Vagrant::Notify::Action.action_stop_server, {
        :machine => machine,
      })
    end

    if options[:start]
      @env.action_runner.run(Vagrant::Notify::Action.action_start_server, {
        :machine => machine,
      })
    end
    
    if options[:restart]
      @env.action_runner.run(Vagrant::Notify::Action.action_stop_server, {
        :machine => machine,
        :notify_restart => true
      })
      @env.action_runner.run(Vagrant::Notify::Action.action_start_server, {
        :machine => machine,
      })
    end
  end
end