Class: Marv::CLI::Server

Inherits:
Base
  • Object
show all
Defined in:
lib/marv/cli/server.rb

Instance Method Summary collapse

Methods inherited from Base

source_root

Instance Method Details

#create(dir) ⇒ Object



46
47
48
49
# File 'lib/marv/cli/server.rb', line 46

def create(dir)
  server = Marv::Server::Server.new(self, dir)
  Marv::Server::Create.new(server)
end

#list(dir = 'all') ⇒ Object



10
11
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
# File 'lib/marv/cli/server.rb', line 10

def list(dir='all')
  servers = Marv::Global.new(self).servers

  if dir == 'all'
    say_info "Available marv servers:", true
    servers.each_with_index do |server_dir, index|
      server = Marv::Server::Server.new(self, server_dir)
      say_message "#{index + 1}. #{server.name} [http://#{server.host}:#{server.port}]", false
    end

    if servers.empty?
      say_warning "No servers found", false
    end
  end

  if dir == 'running'
    index = 0
    say_success "Running marv servers:", true
    servers.each do |server_dir|
      server = Marv::Server::Server.new(self, server_dir)
      action = Marv::Server::Actions.new(server)

      if action.is_server_running?
        say_message "#{index + 1}. #{server.name} [http://#{server.host}:#{server.port}]", false
        index += 1
      end
    end

    if index == 0
      say_warning "No running servers found", false
    end
  end
end

#remove(dir) ⇒ Object



106
107
108
109
110
# File 'lib/marv/cli/server.rb', line 106

def remove(dir)
  server = Marv::Server::Server.new(self, dir)
  action = Marv::Server::Actions.new(server)
  action.remove
end

#restart(dir) ⇒ Object



98
99
100
101
102
# File 'lib/marv/cli/server.rb', line 98

def restart(dir)
  server = Marv::Server::Server.new(self, dir)
  action = Marv::Server::Actions.new(server)
  action.restart
end

#start(dir) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/marv/cli/server.rb', line 54

def start(dir)
  servers_path = Marv::Global.new(self).servers_path

  if ::File.directory?(::File.join(servers_path, dir))
    server = Marv::Server::Server.new(self, dir)
    action = Marv::Server::Actions.new(server, options[:debug])
    action.start
  end

  # Create server if it does not exist
  unless ::File.directory?(::File.join(servers_path, dir))
    say_warning "Server #{dir} does not exist."
    if said_yes?("Would you like to create the server?")
      say_empty
      create(dir)
    end
  end
end

#stop(dir) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/marv/cli/server.rb', line 75

def stop(dir)
  unless dir == 'all'
    server = Marv::Server::Server.new(self, dir)
    action = Marv::Server::Actions.new(server)
    action.stop
  end

  if dir == 'all'
    servers = Marv::Global.new(self).servers

    servers.each do |server_dir|
      server = Marv::Server::Server.new(self, server_dir)
      action = Marv::Server::Actions.new(server)

      if action.is_server_running?
        action.stop
      end
    end
  end
end