zabcon 0.0.6 → 0.0.327
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/libs/argument_processor.rb +430 -567
- data/libs/command_help.rb +11 -61
- data/libs/command_tree.rb +480 -280
- data/libs/lexer.rb +846 -0
- data/libs/printer.rb +25 -25
- data/libs/revision.rb +1 -0
- data/libs/utility_items.rb +137 -0
- data/libs/zabbix_server.rb +379 -0
- data/libs/zabcon_commands.rb +558 -0
- data/libs/zabcon_core.rb +177 -316
- data/libs/zabcon_exceptions.rb +4 -4
- data/libs/zabcon_globals.rb +29 -6
- data/zabcon.conf.default +38 -3
- data/zabcon.rb +72 -50
- metadata +23 -48
- data/libs/zbxcliserver.rb +0 -325
data/libs/command_help.rb
CHANGED
@@ -18,86 +18,36 @@
|
|
18
18
|
|
19
19
|
##########################################
|
20
20
|
# Subversion information
|
21
|
-
# $Id: command_help.rb
|
22
|
-
# $Revision:
|
21
|
+
# $Id: command_help.rb 296 2011-07-11 19:48:46Z nelsonab $
|
22
|
+
# $Revision: 296 $
|
23
23
|
##########################################
|
24
24
|
|
25
|
-
require 'libs/zdebug'
|
26
|
-
|
27
|
-
require 'pp'
|
28
25
|
require 'rexml/document'
|
29
26
|
|
30
|
-
# CommandHelp is the class which behaves as a wrapper to the help text stored in a separate file.
|
31
|
-
# All help functions are dynamically generated by default. This is done through the lambda procedure
|
32
|
-
# in the method "method". The overloaded method "method" attempts to determine if the symbol passed
|
33
|
-
# in matches a pre-existing method. If it does not a local default lambda is created and returned.
|
34
27
|
class CommandHelp
|
35
28
|
|
36
|
-
include ZDebug
|
37
29
|
|
38
|
-
def
|
30
|
+
def self.setup(language)
|
39
31
|
@file = File.new(ZABCON_PATH+"/libs/help.xml")
|
40
32
|
|
41
33
|
@doc=REXML::Document.new(@file).elements["//help[@language='#{language}']"]
|
42
|
-
|
43
|
-
|
34
|
+
|
44
35
|
EnvVars.instance.register_notifier("language",self.method(:language=))
|
36
|
+
|
45
37
|
end
|
46
38
|
|
47
|
-
def language=(language)
|
39
|
+
def self.language=(language)
|
48
40
|
@file.rewind
|
49
41
|
@doc=REXML::Document.new(@file).elements["//help[@language='#{language}']"]
|
50
42
|
end
|
51
43
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
# If the command is found but no help exists, a message stating this is printed
|
57
|
-
def method(sym)
|
58
|
-
debug(8,sym,"CommandHelp.method overload (sym)")
|
59
|
-
methods=self.methods
|
60
|
-
index=methods.index(sym.to_s)
|
61
|
-
if !index.nil?
|
62
|
-
method_local=o_method(sym)
|
44
|
+
def self.get(sym)
|
45
|
+
item=@doc.elements["//item[@command='#{sym.to_s}']"]
|
46
|
+
if item.nil?
|
47
|
+
"Help not available for internal command: #{sym.to_s}"
|
63
48
|
else
|
64
|
-
|
65
|
-
debug(6, sym, "auto generated help func for")
|
66
|
-
item=@doc.elements["//item[@command='#{sym.to_s}']"]
|
67
|
-
if item.nil?
|
68
|
-
puts "Help not available for internal command: #{sym.to_s}"
|
69
|
-
else
|
70
|
-
puts item.text
|
71
|
-
end
|
72
|
-
end
|
49
|
+
item.text
|
73
50
|
end
|
74
|
-
debug(8,method_local,"returning")
|
75
|
-
method_local
|
76
51
|
end
|
77
52
|
|
78
|
-
def help(command_tree,input)
|
79
|
-
input=input.gsub(/^\s*help\s*/,"") #strip out the help statement at the start
|
80
|
-
debug(6,command_tree.commands,"command_tree",350)
|
81
|
-
debug(6,input,"input")
|
82
|
-
|
83
|
-
items=input.split(" ")
|
84
|
-
if items.length==0
|
85
|
-
puts @doc.elements["//item[@command='help']"].text
|
86
|
-
else # more than "help" was typed by the user
|
87
|
-
help_cmd=items.join(" ").lstrip.chomp
|
88
|
-
|
89
|
-
if help_cmd.downcase=="commands"
|
90
|
-
puts @doc.elements["//item[@command='help_commands']"].text
|
91
|
-
else
|
92
|
-
debug(4,help_cmd,"Searching for help on")
|
93
|
-
|
94
|
-
cmd=command_tree.search(help_cmd)[0] #search returns an array
|
95
|
-
if cmd.nil? or cmd[:helpproc].nil?
|
96
|
-
puts "Unable to find help for \"#{help_cmd}\""
|
97
|
-
else
|
98
|
-
cmd[:helpproc].call(nil) #TODO: need to fix, see line 67 above
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end #def help
|
103
53
|
end
|