X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fgrep.rb;h=2d274838ed6dd2b99bc40b554071c87b35ba2c64;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=c611a7e02d22acfd87e8a0a75d57892e0822ab78;hpb=6963202b4b62c2816655ac9532521b018fdf83bd;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/grep.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/grep.rb index c611a7e02..2d274838e 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/grep.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/grep.rb @@ -1,23 +1,25 @@ # # grep.rb # - module Puppet::Parser::Functions - newfunction(:grep, :type => :rvalue, :doc => <<-EOS -This function searches through an array and returns any elements that match -the provided regular expression. - -*Examples:* - - grep(['aaa','bbb','ccc','aaaddd'], 'aaa') - -Would return: - - ['aaa','aaaddd'] - EOS - ) do |arguments| - - if (arguments.size != 2) then + newfunction(:grep, :type => :rvalue, :doc => <<-DOC + @summary + This function searches through an array and returns any elements that match + the provided regular expression. + + @return + array of elements that match the provided regular expression. + @example Example Usage: + grep(['aaa','bbb','ccc','aaaddd'], 'aaa') # Returns ['aaa','aaaddd'] + + > **Note:** that since Puppet 4.0.0, the built-in + [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function does + the "same" - as any logic can be used to filter, as opposed to just regular expressions: + ```['aaa', 'bbb', 'ccc', 'aaaddd']. filter |$x| { $x =~ 'aaa' }``` + DOC + ) do |arguments| + + if arguments.size != 2 raise(Puppet::ParseError, "grep(): Wrong number of arguments given #{arguments.size} for 2") end @@ -25,7 +27,6 @@ Would return: pattern = Regexp.new(arguments[1]) a.grep(pattern) - end end