Files
sablink-distro/dev-ruby/twitter/files/flexi_commands.patch
T
wael 21ad6cea63 Add new patches from Benoit Caccinolo.
git-svn-id: http://svn.sabayonlinux.org/overlay@2412 d7aec97c-591d-0410-af39-a8856400b30a
2008-06-21 04:30:39 +00:00

84 lines
2.1 KiB
Diff

Benoit Caccinolo <benoit.caccinolo@gmail.com>
=============================================
Here is a little patch to allow the usage of reduced commands for
example:
twitter p "hello world"
to post a twit
Here is the patch : http://groups.google.com/group/ruby-twitter-gem/web/flexi_commands.patch
diff --git a/lib/twitter/command.rb b/lib/twitter/command.rb
index ea956f4..f0b6999 100644
--- a/lib/twitter/command.rb
+++ b/lib/twitter/command.rb
@@ -3,7 +3,8 @@
module Twitter
class Command
@@commands = [:post, :timeline, :friends, :friend, :followers, :follower, :featured, :important, :follow, :leave, :d]
-
+ @@possible_commands = []
+
@@template = <<EOF
# .twitter
#
@@ -22,7 +23,17 @@ EOF
if !command.nil? && @@commands.include?(command.intern)
send(command)
- else
+ elsif @@possible_commands = @@commands.include_part_of?(command)
+ if @@possible_commands.size != 1
+ puts "\nUsage: twitter <command> [options]\n\nAvailable Commands:"
+ Twitter::Command.commands.each do |c|
+ puts " - #{c}"
+ end
+ else
+ send(@@possible_commands.first)
+ end
+
+ else
puts "\nUsage: twitter <command> [options]\n\nAvailable Commands:"
Twitter::Command.commands.each do |c|
puts " - #{c}"
@@ -246,4 +257,4 @@ EOF
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/twitter/version.rb b/lib/twitter/version.rb
index 1b43e70..96049f7 100644
--- a/lib/twitter/version.rb
+++ b/lib/twitter/version.rb
@@ -1,3 +1,26 @@
+class Array
+
+ def include_part_of?(entry)
+
+ possible_commands = []
+ self.each do |c|
+ r = c.to_s.match(/#{entry}.*/)
+ if !c.to_s.match(/^#{entry}.*/).nil?
+ possible_commands << c
+ end
+ end
+
+ if possible_commands.empty?
+ return false
+ else
+ return possible_commands
+ end
+
+ end
+
+end
+
+
module Twitter #:nodoc:
module VERSION #:nodoc:
MAJOR = 0