#!/usr/bin/env ruby require 'smart_cloud' command = ARGV.shift if command == '--version' puts "SmartCloud #{SmartCloud.version}" return end if SmartCloud::Machine.local? if command == 'start' machine = SmartCloud::Machine.new machine.start elsif command == 'stop' machine = SmartCloud::Machine.new machine.stop elsif command == 'ssh' machine = SmartCloud::Machine.new machine.ssh elsif command == 'sync' machine = SmartCloud::Machine.new machine.sync elsif command == 'grid' machine = SmartCloud::Machine.new machine.grid ARGV elsif command == 'app' machine = SmartCloud::Machine.new machine.app ARGV elsif command == 'ps' ssh = SmartCloud::SSH.new ssh.run "smartcloud ps #{ARGV.join(' ')}" elsif command == 'logs' ssh = SmartCloud::SSH.new ssh.run "smartcloud logs #{ARGV.join(' ')}" elsif command == 'credentials:edit' credentials = SmartCloud::Credentials.new credentials.edit else puts "Specify a valid local command to execute." end elsif SmartCloud::Machine.remote? if command == 'run' machine = SmartCloud::Machine.new machine.run ARGV elsif command == 'buildpacker' buildpacker = SmartCloud::Buildpacker.new action = ARGV.shift if action == "install" buildpacker.install elsif action == "uninstall" buildpacker.uninstall end elsif command == 'prereceiver' prereceiver = SmartCloud::Grids::Prereceiver.new action = ARGV.shift if action == "install" prereceiver.install elsif action == "uninstall" prereceiver.uninstall end elsif command == 'ps' exec "docker ps #{ARGV.join(' ')}" elsif command == 'logs' exec "docker logs #{ARGV.join(' ')}" elsif command == 'shell' exec '/bin/sh -c sh' else puts "Specify a valid server command to execute." end else if command == 'new' raise "Please specify a machine name" if ARGV.empty? machine = SmartCloud::Machine.new machine.create ARGV else puts "Specify a valid smartcloud command to execute. Are you in the correct directory to run this command?" end end