#!/usr/bin/env ruby require 'smartcloud' command = ARGV.shift if command == '--version' puts "Smartcloud #{Smartcloud.version}" return end if Smartcloud::Machine.smartcloud_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.smartcloud_server? 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