Permalink
Browse files

refactoring topic command

  • Loading branch information...
1 parent 120cb51 commit ae70dcefa9ba5899b80f49b9c99ff392296c18bd @forresty forresty committed Apr 19, 2012
Showing with 14 additions and 5 deletions.
  1. +14 −5 bin/v2ex
View
@@ -28,11 +28,7 @@ command :topic do |c|
c.action do |args, options|
topic_id = args.first.to_i
print_topic V2exCli::Engine.topic(topic_id), :show_content => true
- info "\nreplies:\n"
- V2exCli::Engine.replies(topic_id).each do |reply|
- puts "#{reply[:member][:username]} ".ljust(25, '-')
- print "#{reply[:content]}\n\n"
- end
+ print_topic_replies V2exCli::Engine.replies(topic_id)
end
end
@@ -71,6 +67,19 @@ command :nodes do |c|
end
end
+def print_topic_replies(replies)
+ info "\nreplies:\n"
+
+ if replies.empty?
+ puts "No replies yet."
+ else
+ replies.each do |reply|
+ puts "#{reply[:member][:username]} ".ljust(25, '-')
+ print "#{reply[:content]}\n\n"
+ end
+ end
+end
+
def print_user_meta(user)
puts "#{user[:username]} - V2EX Member ##{user[:id]}"
%w{twitter website location tagline}.map(&:to_sym).each do |key|

0 comments on commit ae70dce

Please sign in to comment.