Class: USaidWat::Application::Log
- Includes:
- FilterCommand
- Defined in:
- lib/usaidwat/commands/log.rb
Instance Attribute Summary
Attributes inherited from Command
Instance Method Summary collapse
-
#initialize(prog) ⇒ Log
constructor
A new instance of Log.
- #process(options, args) ⇒ Object
Methods included from FilterCommand
#ensure_entries, #filter_entries, #grep_entries, #limit_entries
Methods inherited from Command
Methods included from Pager
Constructor Details
#initialize(prog) ⇒ Log
Returns a new instance of Log.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/usaidwat/commands/log.rb', line 12 def initialize(prog) prog.command(:log) do |c| c.alias :l c.option 'date', '--date FORMAT', 'Show dates in "absolute" or "relative" format' c.option 'grep', '--grep STRING', 'Show only comments matching STRING' c.option 'limit', '--limit LIMIT', '-n LIMIT', 'Only show n comments' c.option 'oneline', '--oneline', 'Output log in a more compact form' c.option 'raw', '--raw', 'Print raw comment bodies' c.action do |args, | process(, args) end end super end |
Instance Method Details
#process(options, args) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/usaidwat/commands/log.rb', line 28 def process(, args) raise ArgumentError.new('You must specify a username') if args.empty? username = args.shift subreddits = args.subreddits redditor = client.new(username) comments = redditor.comments res = filter_entries('comments', redditor, comments, subreddits) >> lambda { |r| grep_entries('comments', redditor, r.value, ['grep']) } >> lambda { |r| limit_entries('comments', redditor, r.value, ['limit']) } >> lambda { |r| ensure_entries('comments', redditor, r.value) } quit res.value if res.left? opts = { :date_format => (['date'] || :relative).to_sym, :oneline => !['oneline'].nil?, :pattern => ['grep'], :raw => !['raw'].nil?, } list_comments(res.value, opts) rescue USaidWat::Client::NoSuchUserError quit "No such user: #{username}", :no_such_user end |