mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
parent
9941ac27da
commit
0258711bbc
@ -55,6 +55,14 @@ module CLIHelper
|
||||
:description => "Filter data. An array is specified with\n"<<
|
||||
" "*31<<"column=value pairs."
|
||||
}
|
||||
OPERATOR = {
|
||||
:name => "operator",
|
||||
:large => "--operator operator",
|
||||
:format => String,
|
||||
:description => "Logical operator used on filters: AND, OR."<<
|
||||
" Default: AND."
|
||||
}
|
||||
|
||||
#
|
||||
#HEADER = {
|
||||
# :name => "header",
|
||||
@ -82,7 +90,7 @@ module CLIHelper
|
||||
}
|
||||
|
||||
#OPTIONS = [LIST, ORDER, FILTER, HEADER, DELAY]
|
||||
OPTIONS = [LIST, LISTCONF, DELAY, FILTER, CSV_OPT, NO_PAGER]
|
||||
OPTIONS = [LIST, LISTCONF, DELAY, FILTER, OPERATOR, CSV_OPT, NO_PAGER]
|
||||
|
||||
# Sets bold font
|
||||
def CLIHelper.scr_bold
|
||||
@ -330,7 +338,7 @@ module CLIHelper
|
||||
}
|
||||
|
||||
if options
|
||||
filter_data!(res_data, options[:filter]) if options[:filter]
|
||||
filter_data!(res_data, options) if options[:filter]
|
||||
sort_data!(res_data, options[:order]) if options[:order]
|
||||
end
|
||||
|
||||
@ -393,10 +401,16 @@ module CLIHelper
|
||||
}.compact.join(' ')
|
||||
end
|
||||
|
||||
def filter_data!(data, filter)
|
||||
def filter_data!(data, options)
|
||||
# TBD: add more operators
|
||||
# operators=/(==|=|!=|<|<=|>|>=)/
|
||||
operators=/(=|!=)/
|
||||
filter = options[:filter]
|
||||
if options.key?(:operator)
|
||||
log_operator = options[:operator].upcase
|
||||
else
|
||||
log_operator = "AND"
|
||||
end
|
||||
|
||||
stems=filter.map do |s|
|
||||
m=s.match(/^(.*?)#{operators}(.*?)$/)
|
||||
@ -427,12 +441,19 @@ module CLIHelper
|
||||
stems.each do |s|
|
||||
|
||||
if d[s[:index]].public_send(s[:operator] == "=" ? "==" : s[:operator], s[:right])
|
||||
pass=false
|
||||
break
|
||||
if log_operator == "OR"
|
||||
pass = true
|
||||
break
|
||||
end
|
||||
else
|
||||
pass = false
|
||||
if log_operator == "AND"
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
!pass
|
||||
pass
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user