Class: Gorgon::Command
- Inherits:
-
Object
- Object
- Gorgon::Command
- 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
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
Class Method Summary collapse
Instance Method Summary collapse
- #gem ⇒ Object
- #help ⇒ Object
- #init ⇒ Object
-
#initialize(argv) ⇒ Command
constructor
A new instance of Command.
- #install_listener ⇒ Object
- #listen ⇒ Object
- #manage_workers ⇒ Object
- #ping ⇒ Object
- #run_command ⇒ Object
- #start ⇒ Object
- #start_rsync ⇒ Object
- #stop_rsync ⇒ Object
- #version ⇒ Object
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
#argv ⇒ Object (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
#gem ⇒ Object
108 109 110 111 |
# File 'lib/gorgon/command.rb', line 108 def gem gem_opts = argv.join(" ") GemService.new.run(gem_opts) end |
#help ⇒ Object
61 62 63 64 |
# File 'lib/gorgon/command.rb', line 61 def help write_usage exit(0) end |
#init ⇒ Object
113 114 115 116 |
# File 'lib/gorgon/command.rb', line 113 def init framework = argv[0] Settings::InitialFilesCreator.run(framework) end |
#install_listener ⇒ Object
118 119 120 |
# File 'lib/gorgon/command.rb', line 118 def install_listener ListenerInstaller.install end |
#listen ⇒ Object
76 77 78 79 |
# File 'lib/gorgon/command.rb', line 76 def listen l = Listener.new l.listen end |
#manage_workers ⇒ Object
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 |
#ping ⇒ Object
104 105 106 |
# File 'lib/gorgon/command.rb', line 104 def ping PingService.new.ping_listeners end |
#run_command ⇒ Object
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 (command) end end |
#start ⇒ Object
71 72 73 74 |
# File 'lib/gorgon/command.rb', line 71 def start o = Originator.new exit o.originate end |
#start_rsync ⇒ Object
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_rsync ⇒ Object
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 |