bin/smartcloud in smartcloud-0.2.0.beta2 vs bin/smartcloud in smartcloud-0.2.0

- old
+ new

@@ -2,34 +2,79 @@ require 'smartcloud' command = ARGV.shift -unless command == 'new' - unless Smartcloud::Machine.smartcloud_dir? - raise "This is not a smartcloud directory. Are you in the correct directory?" - end +if command == '--version' + puts "Smartcloud #{Smartcloud.version}" + return end -if command == 'new' - raise "This is already a smartcloud directory. Are you in the correct directory?" if Smartcloud::Machine.smartcloud_dir? - raise "Please specify a machine name" if ARGV.empty? - machine = Smartcloud::Machine.new - machine.create ARGV -elsif command == 'start' - machine = Smartcloud::Machine.new - machine.start -elsif command == 'stop' - machine = Smartcloud::Machine.new - machine.stop -elsif command == 'grid' - machine = Smartcloud::Machine.new - machine.grid ARGV -elsif command == 'ssh' - machine = Smartcloud::Machine.new - machine.ssh -elsif command == 'sync' - machine = Smartcloud::Machine.new - machine.sync +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 - puts "Specify a command to execute." + 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