Class: ITRP::Cmd
- Inherits:
-
Object
show all
- Defined in:
- lib/cmd_base.rb
Direct Known Subclasses
Cmd_agg_flow, Cmd_alert, Cmd_cglist, Cmd_counter, Cmd_delete_alerts, Cmd_edges, Cmd_flow, Cmd_flow_trackers, Cmd_fts, Cmd_getlabel, Cmd_grep, Cmd_help, Cmd_keyspace, Cmd_list, Cmd_meters, Cmd_metrics_summary, Cmd_options, Cmd_pcap, Cmd_probe, Cmd_query_alerts, Cmd_query_flow, Cmd_query_fts, Cmd_query_resource, Cmd_reset, Cmd_resource, Cmd_root, Cmd_searchkey, Cmd_set, Cmd_setlabel, Cmd_timeslices, Cmd_toppers, Cmd_toptrend, Cmd_traffic, Cmd_volume
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(appenv) ⇒ Cmd
Returns a new instance of Cmd.
12
13
14
15
16
|
# File 'lib/cmd_base.rb', line 12
def initialize(appenv)
@children=[]
@missing=[]
@appenv=appenv
end
|
Instance Attribute Details
#attach_cmd ⇒ Object
Returns the value of attribute attach_cmd.
8
9
10
|
# File 'lib/cmd_base.rb', line 8
def attach_cmd
@attach_cmd
end
|
#children ⇒ Object
Returns the value of attribute children.
10
11
12
|
# File 'lib/cmd_base.rb', line 10
def children
@children
end
|
#enabled_in_state ⇒ Object
Returns the value of attribute enabled_in_state.
7
8
9
|
# File 'lib/cmd_base.rb', line 7
def enabled_in_state
@enabled_in_state
end
|
#trigger ⇒ Object
Returns the value of attribute trigger.
9
10
11
|
# File 'lib/cmd_base.rb', line 9
def trigger
@trigger
end
|
Instance Method Details
#appstate(sym) ⇒ Object
78
79
80
|
# File 'lib/cmd_base.rb', line 78
def appstate(sym)
@appenv.context_data[sym]
end
|
#completions(s) ⇒ Object
18
19
20
|
# File 'lib/cmd_base.rb', line 18
def completions(s)
@children.collect { |c| c.trigger }.grep(/#{s}/)
end
|
#enter(s) ⇒ Object
22
|
# File 'lib/cmd_base.rb', line 22
def enter(s); end
|
#find_node(linebuffer_arr) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/cmd_base.rb', line 28
def find_node(linebuffer_arr)
return self if linebuffer_arr.empty?
@children.each do |c|
if c.trigger == linebuffer_arr.first
return c.find_node(linebuffer_arr.drop(1))
end
end
return self
end
|
#is_root? ⇒ Boolean
24
25
26
|
# File 'lib/cmd_base.rb', line 24
def is_root?
return @trigger.empty?
end
|
#place_node(n) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/cmd_base.rb', line 41
def place_node(n)
@missing.reject! do |m|
if n.trigger == m.attach_cmd
n.children << m
true
else
false
end
end
if n.attach_cmd==@trigger
@children << n
return true
else
@children.each do |c|
return true if c.place_node(n)
end
end
@missing << n
return false
end
|
#print_state ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/cmd_base.rb', line 82
def print_state
print("\n")
tmarr = appstate(:time_window)
print("Server : #{@appenv.zmq_endpt}\n")
print("Time window : #{Time.at(tmarr[0])} to #{Time.at(tmarr[1])} #{tmarr[1]-tmarr[0]} seconds \n");
print("Context : #{@appenv.context}\n");
print("Prompt : #{@appenv.prompt}\n");
if @appenv.context != :any
print("Selected Group : #{appstate(:cgname)}\n");
print("Selected GUID : #{appstate(:cgguid)}\n");
print("Selected Key : #{appstate(:cgkey)}\n");
end
@appenv.context_data.each do |k,v|
unless [:time_window, :time_interval, :cgguid, :cgname, :cgkey].member? k
print("#{k}".ljust(14,' ') + " : #{v}\n" )
end
end
end
|
#set_time_window ⇒ Object
65
66
67
68
69
70
|
# File 'lib/cmd_base.rb', line 65
def set_time_window
@appenv.context_data[:time_window]= TrisulRP::Protocol.get_available_time(@appenv.zmq_endpt)
@appenv.context_data[:time_interval]= mk_time_interval(@appenv.context_data[:time_window])
print("Connected to #{@appenv.zmq_endpt}\n");
end
|
#treeprint(indentation = 0) ⇒ Object
72
73
74
75
76
|
# File 'lib/cmd_base.rb', line 72
def treeprint(indentation=0)
ind=" "*4*indentation
print "#{ind}#{@trigger}\n"
@children.each { |c| c.treeprint(indentation+1) }
end
|