Class: GridCLI::SearchCommand

Inherits:
BaseCommand show all
Defined in:
lib/gridcli/commands/search.rb

Instance Attribute Summary

Attributes inherited from BaseCommand

#cmd, #desc

Instance Method Summary collapse

Methods inherited from BaseCommand

#add_format_option, #add_option, #error, #log, #output_format, #parse_dates, #parse_opts, #pop_arg, #pprint

Constructor Details

#initializeSearchCommand

Returns a new instance of SearchCommand.



3
4
5
6
7
8
9
# File 'lib/gridcli/commands/search.rb', line 3

def initialize
  super "search", "Search posts"
  add_option("-u username", "--from-user username", "Only look at messages from a particular user.") { |u|
    @opts['from'] = u
  }
  add_format_option
end

Instance Method Details

#run(args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gridcli/commands/search.rb', line 15

def run(args)
  usage if args.length < 2
  type = args.shift
  usage if not [ 'like', 'dislike', 'status', 'message', 'all' ].include? type
  query = args.shift
  period = (args.length > 0 and not args.first.start_with? '-') ? args.shift : nil
  dates = parse_dates period
  parse_opts args

  log "Showing #{type} posts in range #{dates.first || 'first'} - #{dates.last || 'last'}"
  GridCLI.storage.search(type, query, dates[0], dates[1], output_format, @opts['from'])
end

#usageObject



11
12
13
# File 'lib/gridcli/commands/search.rb', line 11

def usage
  super "<like|dislike|message|status|all> <query> [<exact day> | <start> to <end>]"
end