jugyo / earthquake

Twitter terminal client with streaming API support.
MIT License
661 stars 94 forks source link

direct command line update not working #149

Closed Cutuchiqueno closed 11 years ago

Cutuchiqueno commented 11 years ago

Actually I have to excuse in case the reason for my post is a misunderstanding, but:

In my understanding the -c flag should make possible the direct updating of a status without having to enter earthquake first, so:

earthquake -c :update xxxxxxxxx

should do it. Actually I am also asked if I want to update but in the end after entering 'Y' and the command line appears again, the status is not updated. From within earthquake it is working well. Can anyone confirm this behaviour or demonstrate me my misinterpretation?

no6v commented 11 years ago

I confirmed the behavior. Some commands are invoked within async_e and the earthquake process will end before the command finished. The following patch will fix this.

diff --git a/lib/earthquake/core.rb b/lib/earthquake/core.rb
index 6b3e620..91c07e0 100644
--- a/lib/earthquake/core.rb
+++ b/lib/earthquake/core.rb
@@ -120,7 +120,8 @@ module Earthquake

     def invoke(command, options = {})
       __init(options)
-      input(command)
+      r = input(command)
+      r.join if Thread === r
     end

     def start(options = {})
jugyo commented 11 years ago

is this better?

diff --git a/bin/earthquake b/bin/earthquake
index 29227b0..9d6e7aa 100755
--- a/bin/earthquake
+++ b/bin/earthquake
@@ -33,7 +33,7 @@ end

 require 'earthquake'
 if command
-  Earthquake.invoke(command, options)
+  Earthquake.invoke(command, options).try(:join)
 else
   Earthquake.start(options)
 end
no6v commented 11 years ago

Some commands will return other than a Thread object.

$ ruby bin/earthquake -c ':eval 1 + 1'
2
(snip)/gems/activesupport-3.2.13/lib/active_support/core_ext/object/try.rb:36:in `try': undefined method `join' for 2:Fixnum (NoMethodError)
    from bin/earthquake:36:in `<main>'
jugyo commented 11 years ago

Hmm… It looks strange that the method try raises a NoMethodError :(

no6v commented 11 years ago

Object#try is just equal to __send__, so exception will raise if call a method not respond to. (NilClass#try always returns nil.)

jugyo commented 11 years ago

ah, make sense!

jugyo commented 11 years ago

I realized that the behaviour of Object#try is different between "activesupport 3.2.13" and "activesupport 4.0.4".

activesupport 4.0.4:

def try(*a, &b)
  if a.empty? && block_given?
    yield self
  else
    public_send(*a, &b) if respond_to?(a.first)
  end
end

activesupport 3.2.13:

def try(*a, &b)
  if a.empty? && block_given?
    yield self
  else
    __send__(*a, &b)
  end
end
no6v commented 11 years ago

:thumbsup: