Method: Cisco::Client.filter_cli
- Defined in:
- lib/cisco_node_utils/client/utils.rb
.filter_cli(cli_output: nil, context: nil, value: nil) ⇒ [String]?
Helper function that subclasses may use with get(data_format: :cli) Method for working with hierarchical show command output such as “show running-config”. Searches the given multi-line string for all matches to the given value query. If context is provided, the matches will be filtered to only those that are located “under” the given context sequence (as determined by indentation).
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/cisco_node_utils/client/utils.rb', line 57 def self.filter_cli(cli_output: nil, context: nil, value: nil) return cli_output if cli_output.nil? context ||= [] context.each { |filter| cli_output = find_subconfig(cli_output, filter) } return nil if cli_output.nil? || cli_output.empty? return cli_output if value.nil? value = to_regexp(value) match = cli_output.scan(value) return nil if match.empty? # find matches and return as array of String if it only does one match. # Otherwise return array of array. match.flatten! if match[0].is_a?(Array) && match[0].length == 1 match end |