lib/shelly/cli/main.rb in shelly-0.1.6 vs lib/shelly/cli/main.rb in shelly-0.1.7

- old
+ new

@@ -15,11 +15,11 @@ register(Config, "config", "config <command>", "Manage application configuration files") check_unknown_options!(:except => :rake) # FIXME: it should be possible to pass single symbol, instead of one element array before_hook :logged_in?, :only => [:add, :status, :list, :start, :stop, :logs, :delete, :info, :ip, :logout, :execute, :rake, :setup, :console, :upload] - before_hook :inside_git_repository?, :only => [:add, :setup] + before_hook :inside_git_repository?, :only => [:add, :setup, :check] map %w(-v --version) => :version desc "version", "Display shelly version" def version say "shelly version #{Shelly::VERSION}" @@ -69,11 +69,11 @@ end method_option "code-name", :type => :string, :aliases => "-c", :desc => "Unique code-name of your cloud" method_option :databases, :type => :array, :aliases => "-d", - :banner => Shelly::App::DATABASE_KINDS.join(', '), + :banner => Shelly::App::DATABASE_CHOICES.join(', '), :desc => "List of databases of your choice" method_option :size, :type => :string, :aliases => "-s", :desc => "Server size [large, small]" desc "add", "Add a new cloud" def add @@ -148,13 +148,24 @@ print_wrapped "Deployed by: #{app.git_info["deployed_push_author"]}", :ident => 2 say_new_line print_wrapped "Repository URL: #{app.git_info["repository_url"]}", :ident => 2 print_wrapped "Web server IP: #{app.web_server_ip}", :ident => 2 print_wrapped "Mail server IP: #{app.mail_server_ip}", :ident => 2 + say_new_line + if app.statistics.present? + print_wrapped "Statistics:", :ident => 2 + app.statistics.each do |stat| + print_wrapped "#{stat['name']}:", :ident => 4 + print_wrapped "Load average: 1m: #{stat['load']['avg01']}, 5m: #{stat['load']['avg05']}, 15m: #{stat['load']['avg15']}", :ident => 6 + print_wrapped "CPU: #{stat['cpu']['wait']}%, MEM: #{stat['memory']['percent']}%, SWAP: #{stat['swap']['percent']}%", :ident => 6 + end + end rescue Client::NotFoundException => e raise unless e.resource == :cloud say_error "You have no access to '#{app}' cloud defined in Cloudfile" + rescue Client::GatewayTimeoutException + say_error "Server statistics temporarily unavailable" end desc "start", "Start the cloud" method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud" def start @@ -369,10 +380,26 @@ say_error "You have no access to '#{app}' cloud defined in Cloudfile" rescue Client::ConflictException say_error "Cloud #{app} is not running. Cannot upload files." end + require 'bundler' + desc "check", "List all requirements and check which are fulfilled" + def check + s = Shelly::StructureValidator.new + say "Checking dependencies:", :green + print_check s.gemfile_exists?, "Gemfile exists" + print_check s.gems.include?("thin"), "gem 'thin' present in Gemfile" + print_check s.config_ru_exists?, "config.ru exists" + print_check !(s.gems.include?("mysql2") or s.gems.include?("mysql")), + "application doesn't use mysql database" + rescue Bundler::BundlerError => e + say_new_line + say_error e.message, :with_exit => false + say_error "Try to run `bundle install`" + end + # FIXME: move to helpers no_tasks do # Returns valid arguments for rake, removes shelly gem arguments def rake_args(args = ARGV) skip_next = false @@ -404,11 +431,11 @@ sizes.include?(size) end def valid_databases?(databases) return true unless databases.present? - kinds = Shelly::App::DATABASE_KINDS + kinds = Shelly::App::DATABASE_CHOICES databases.all? { |kind| kinds.include?(kind) } end def overwrite_remote?(app) git_remote = app.git_remote_exist? @@ -439,10 +466,10 @@ code_name = ask("Cloud code name (#{Shelly::App.guess_code_name} - default):") code_name.blank? ? default_code_name : code_name end def ask_for_databases - kinds = Shelly::App::DATABASE_KINDS + kinds = Shelly::App::DATABASE_CHOICES databases = ask("Which database do you want to use #{kinds.join(", ")} (postgresql - default):") begin databases = databases.split(/[\s,]/).reject(&:blank?) valid = valid_databases?(databases) break if valid