Class: Gorgon::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/gorgon/command.rb

Constant Summary collapse

WELCOME_MESSAGE =
"Welcome to Gorgon #{Gorgon::VERSION}"
USAGE =
<<-EOT
USAGE: gorgon <command> [<args>]

COMMANDS:
  start                       remotely run all tests specified in gorgon.json
  listen                      start a listener process using the settings in gorgon_listener.json
  ping                        ping listeners and show hosts and gorgon's version they are running
  init [<framework>]          create initial files for current project
  install_listener            run gorgon listener as a daemon process
  start_rsync <directory>     start rsync daemon. Run this command in File Server
  stop_rsync                  stop rsync daemon.
  gem command [<options>...]  execute the gem command on every listener and shutdown listener.
                          (e.g. 'gorgon gem install bunny --version 1.0.0')

OPTIONS:
  -h, --help       print this message
  -v, --version    print gorgon version
EOT
COMMAND_WHITELIST =
%w(help version start listen start_rsync stop_rsync manage_workers ping gem init install_listener)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Command

Returns a new instance of Command.



39
40
41
42
43
44
45
# File 'lib/gorgon/command.rb', line 39

def initialize(argv)
  if argv.empty?
    @argv = ['start']
  else
    @argv = argv
  end
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



37
38
39
# File 'lib/gorgon/command.rb', line 37

def argv
  @argv
end

Class Method Details

.run(argv = ARGV) ⇒ Object



47
48
49
# File 'lib/gorgon/command.rb', line 47

def self.run(argv = ARGV)
  new(argv).run_command
end

Instance Method Details

#gemObject



108
109
110
111
# File 'lib/gorgon/command.rb', line 108

def gem
  gem_opts = argv.join(" ")
  GemService.new.run(gem_opts)
end

#helpObject



61
62
63
64
# File 'lib/gorgon/command.rb', line 61

def help
  write_usage
  exit(0)
end

#initObject



113
114
115
116
# File 'lib/gorgon/command.rb', line 113

def init
  framework = argv[0]
  Settings::InitialFilesCreator.run(framework)
end

#install_listenerObject



118
119
120
# File 'lib/gorgon/command.rb', line 118

def install_listener
  ListenerInstaller.install
end

#listenObject



76
77
78
79
# File 'lib/gorgon/command.rb', line 76

def listen
  l = Listener.new
  l.listen
end

#manage_workersObject



94
95
96
97
98
99
100
101
102
# File 'lib/gorgon/command.rb', line 94

def manage_workers
  config_path = ENV["GORGON_CONFIG_PATH"]

  manager = WorkerManager.build config_path
  manager.manage

  # For some reason I have to 'exit' here, otherwise WorkerManager process crashes
  exit
end

#pingObject



104
105
106
# File 'lib/gorgon/command.rb', line 104

def ping
  PingService.new.ping_listeners
end

#run_commandObject



51
52
53
54
55
56
57
58
59
# File 'lib/gorgon/command.rb', line 51

def run_command
  command = parse(argv.shift)
  if COMMAND_WHITELIST.include?(command)
    puts WELCOME_MESSAGE unless ['version', 'help'].include?(command)
    send(command)
  else
    write_error_message(command)
  end
end

#startObject



71
72
73
74
# File 'lib/gorgon/command.rb', line 71

def start
  o = Originator.new
  exit o.originate
end

#start_rsyncObject



81
82
83
84
85
86
# File 'lib/gorgon/command.rb', line 81

def start_rsync
  puts "Starting rsync daemon..."
  directory = argv[0]
  exit 1 unless RsyncDaemon.start directory
  puts "Rsync Daemon is running. Use 'gorgon stop_rsync' to kill it."
end

#stop_rsyncObject



88
89
90
91
92
# File 'lib/gorgon/command.rb', line 88

def stop_rsync
  puts "Stopping rsync daemon..."
  exit 1 unless RsyncDaemon.stop
  puts "Done"
end

#versionObject



66
67
68
69
# File 'lib/gorgon/command.rb', line 66

def version
  puts Gorgon::VERSION
  exit(0)
end