lib/adhearsion/cli_commands.rb in adhearsion-2.0.0.alpha1 vs lib/adhearsion/cli_commands.rb in adhearsion-2.0.0.alpha2

- old
+ new

@@ -1,9 +1,20 @@ require 'fileutils' require 'adhearsion/script_ahn_loader' require 'thor' +class Thor + class Task + protected + + def sans_backtrace(backtrace, caller) #:nodoc: + saned = backtrace.reject { |frame| frame =~ FILE_REGEXP || (frame =~ /\.java:/ && RUBY_PLATFORM =~ /java/) } + saned -= caller + end + end +end + module Adhearsion module CLI class AhnCommand < Thor map %w(-h --h -help --help) => :help map %w(-v --v -version --version) => :version @@ -40,11 +51,11 @@ end desc "stop </path/to/directory>", "Stop a running Adhearsion server" method_option :pidfile, :type => :string, :aliases => %w(--pid-file) def stop(path = nil) - execute_from_app_dir! path, ARGV + execute_from_app_dir! path pid_file = if options[:pidfile] File.expand_path File.exists?(File.expand_path(options[:pidfile])) ? options[:pidfile] : File.join(path, options[:pidfile]) @@ -53,14 +64,14 @@ end begin pid = File.read(pid_file).to_i rescue - raise CLIException, "Could not read pid file #{pid_file}" + raise PIDReadError, pid_file end - raise CLIException, "Could not read pid" if pid.nil? + raise PIDReadError, pid_file if pid.nil? say "Stopping Adhearsion server at #{path} with pid #{pid}" waiting_timeout = Time.now + 15 begin ::Process.kill "TERM", pid @@ -71,34 +82,34 @@ end desc "restart </path/to/directory>", "Restart the Adhearsion server" method_option :pidfile, :type => :string, :aliases => %w(--pid-file) def restart(path = nil) - execute_from_app_dir! path, ARGV + execute_from_app_dir! path invoke :stop invoke :daemon end protected def start_app(path, mode, pid_file = nil) - execute_from_app_dir! path, ARGV - say "Starting Adhearsion server at #{path}" + execute_from_app_dir! path + say "Starting Adhearsion server at #{Dir.pwd}" Adhearsion::Initializer.start :mode => mode, :pid_file => pid_file end - def execute_from_app_dir!(path, *args) + def execute_from_app_dir!(path) return if in_app? and running_script_ahn? path ||= '.' if in_app? raise PathRequired, ARGV[0] if path.nil? or path.empty? raise PathInvalid, path unless ScriptAhnLoader.in_ahn_application?(path) Dir.chdir path do - args.flatten! - args[1] = '.' + args = ARGV.dup + args[1] = File.expand_path path ScriptAhnLoader.exec_script_ahn! args end end def running_script_ahn? @@ -134,9 +145,15 @@ end class PathInvalid < Thor::Error def initialize(path) super "Directory #{path} does not belong to an Adhearsion project!" + end + end + + class PIDReadError < Thor::Error + def initialize(path) + super "Could not read pid from the file #{path}" end end end end