lib/shelly/cli/main.rb in shelly-0.2.26 vs lib/shelly/cli/main.rb in shelly-0.2.27

- old
+ new

@@ -4,25 +4,27 @@ require "shelly/cli/backup" require "shelly/cli/deploy" require "shelly/cli/config" require "shelly/cli/file" require "shelly/cli/organization" +require "shelly/cli/logs" module Shelly module CLI class Main < Command register_subcommand(User, "user", "user <command>", "Manage collaborators") register_subcommand(Backup, "backup", "backup <command>", "Manage database backups") register_subcommand(Deploy, "deploy", "deploy <command>", "View deploy logs") register_subcommand(Config, "config", "config <command>", "Manage application configuration files") register_subcommand(File, "file", "file <command>", "Upload and download files to and from persistent storage") register_subcommand(Organization, "organization", "organization <command>", "View organizations") + register_subcommand(Logs, "logs", "logs <command>", "View application logs") 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, :dbconsole] + before_hook :logged_in?, :only => [:add, :status, :list, :start, :stop, :delete, :info, :ip, :logout, :execute, :rake, :setup, :console, :dbconsole] before_hook :inside_git_repository?, :only => [:add, :setup, :check] map %w(-v --version) => :version desc "version", "Display shelly version" def version @@ -311,34 +313,9 @@ else say "Missing git remote" end rescue Client::ConflictException => e say_error e[:message] - end - - desc "logs", "Show latest application logs" - method_option :cloud, :type => :string, :aliases => "-c", :desc => "Specify cloud" - method_option :limit, :type => :numeric, :aliases => "-n", :desc => "Amount of messages to show" - method_option :from, :type => :string, :desc => "Time from which to find the logs" - method_option :source, :type => :string, :aliases => "-s", :desc => "Limit logs to a single source, e.g. nginx" - method_option :tail, :type => :boolean, :aliases => "-f", :desc => "Show new logs automatically" - def logs - cloud = options[:cloud] - app = multiple_clouds(cloud, "logs") - limit = options[:limit].to_i <= 0 ? 100 : options[:limit] - query = {:limit => limit, :source => options[:source]} - query.merge!(:from => options[:from]) if options[:from] - - logs = app.application_logs(query) - print_logs(logs) - - if options[:tail] - app.application_logs_tail { |logs| print logs } - end - - rescue Client::APIException => e - raise e unless e.status_code == 416 - say_error "You have requested too many log messages. Try a lower number." end desc "logout", "Logout from Shelly Cloud" def logout user = Shelly::User.new