Class: Cumuli::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/cumuli/cli/cli.rb,
lib/cumuli/cli/args.rb,
lib/cumuli/cli/terminal.rb,
lib/cumuli/cli/commander.rb,
lib/cumuli/cli/remote_command.rb

Defined Under Namespace

Classes: Args, Commander, RemoteCommand, Terminal

Instance Method Summary collapse

Instance Method Details

#argsObject



7
8
9
# File 'lib/cumuli/cli/cli.rb', line 7

def args
  @args ||= Args.new(ARGV.dup)
end

#kill_processObject



34
35
36
# File 'lib/cumuli/cli/cli.rb', line 34

def kill_process
  Process.kill('INT', Process.pid)
end

#listen_for_signalsObject



26
27
28
29
30
31
32
# File 'lib/cumuli/cli/cli.rb', line 26

def listen_for_signals
  signals.each do |signal|
    Signal.trap(signal) do
      kill_process
    end
  end
end

#runObject



3
4
5
# File 'lib/cumuli/cli/cli.rb', line 3

def run
  spawn_app
end

#signalsObject



21
22
23
24
# File 'lib/cumuli/cli/cli.rb', line 21

def signals
  # these are the signals used by Foreman
  ['TERM', 'INT', 'HUP']
end

#spawn_appObject



11
12
13
14
15
16
17
18
19
# File 'lib/cumuli/cli/cli.rb', line 11

def spawn_app
  listen_for_signals

  Dir.chdir(args.dir) do
    command = Commander.new("foreman start #{args.foreman_options}").build
    puts "starting ... #{command}"
    spawn_terminal(command)
  end
end

#spawn_terminal(command) ⇒ Object



38
39
40
# File 'lib/cumuli/cli/cli.rb', line 38

def spawn_terminal(command)
  Terminal.new(command).spawn
end