Class: LumiaServer::CLI::Exec

Inherits:
Command
  • Object
show all
Defined in:
lib/lumia-server/command/exec.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #options

Instance Method Summary collapse

Methods inherited from Command

#initialize

Constructor Details

This class inherits a constructor from LumiaServer::CLI::Command

Instance Method Details

#runObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lumia-server/command/exec.rb', line 5

def run
  LumiaServer::CLI.error('No script name provided') unless @args[0]

  file = File.join(Dir.pwd, 'scripts', @args[0])
  server = File.join(Dir.pwd, 'server.json')

  Dir.chdir('build') do
    if File.exist?(file)
      exec "bash #{file}"
    else
      LumiaServer::CLI.error('No script name provided') unless @args[0]
      LumiaServer::CLI.error('server.json was not found') unless File.exist?(server)
      @data = JSON.parse(File.read(server))
      line = @data['scripts'][@args[0]]
      LumiaServer::CLI.error("Invalid script name: #{@args[0]}") unless line
      exec line
    end
  end
end