1 module Puppet::Parser::Functions
2 newfunction(:basename, :type => :rvalue, :doc => <<-EOS
3 Strips directory (and optional suffix) from a filename
7 if arguments.size < 1 then
8 raise(Puppet::ParseError, "basename(): No arguments given")
9 elsif arguments.size > 2 then
10 raise(Puppet::ParseError, "basename(): Too many arguments given (#{arguments.size})")
13 unless arguments[0].is_a?(String)
14 raise(Puppet::ParseError, 'basename(): Requires string as first argument')
17 if arguments.size == 1 then
18 rv = File.basename(arguments[0])
19 elsif arguments.size == 2 then
21 unless arguments[1].is_a?(String)
22 raise(Puppet::ParseError, 'basename(): Requires string as second argument')
25 rv = File.basename(arguments[0], arguments[1])
34 # vim: set ts=2 sw=2 et :