Class: ITRP::Cmd_searchkey
Instance Attribute Summary
Attributes inherited from Cmd
#attach_cmd, #children, #enabled_in_state, #trigger
Instance Method Summary collapse
- #completions(patt) ⇒ Object
- #enter(cmdline) ⇒ Object
-
#initialize(e) ⇒ Cmd_searchkey
constructor
A new instance of Cmd_searchkey.
Methods inherited from Cmd
#appstate, #find_node, #is_root?, #place_node, #print_state, #set_time_window, #treeprint
Constructor Details
#initialize(e) ⇒ Cmd_searchkey
Returns a new instance of Cmd_searchkey.
4 5 6 7 8 9 |
# File 'lib/handlers/searchkey.rb', line 4 def initialize (e) super(e) @enabled_in_state = :counter @attach_cmd = '' @trigger = 'searchkey' end |
Instance Method Details
#completions(patt) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/handlers/searchkey.rb', line 12 def completions(patt) TRP::SearchKeysRequest .fields .values .collect { |a| a.name.to_s } .grep( /^#{Regexp.escape(patt)}/i) end |
#enter(cmdline) ⇒ Object
21 22 23 24 25 26 27 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 53 54 55 56 57 |
# File 'lib/handlers/searchkey.rb', line 21 def enter(cmdline) terms = cmdline.scan( /(\w+)\s*=\s*([\w\-_\.\:,\]\[]+)+/ ) qparams = terms.inject({}) { |acc,t| acc.store( t[0].to_sym, t[1]);acc} [:maxitems, :offset ].each do |a| qparams[a] = qparams[a].to_i if qparams.key? a end [:keys].each do |a| qparams[a] = qparams[a].split(',') if qparams.key? a end p qparams req =mk_request(TRP::Message::Command::SEARCH_KEYS_REQUEST, { :counter_group => appstate(:cgguid), :get_attributes => true }.merge( qparams)) rows = [] get_response_zmq(@appenv.zmq_endpt,req) do |resp| resp.keys.each do |k| attr = k.attributes.collect do |a| "#{a.attr_name}=#{a.attr_value}" end rows << [ k.key, k.label, k.readable, attr.join(",") ] end end table = Terminal::Table.new( :headings => %w(Key Label Readable Attributes ), :rows => rows) puts(table) end |