Puppet Function: dirname

Defined in:
puppet/modules/stdlib/lib/puppet/parser/functions/dirname.rb
Function type:
Ruby 3.x API

Overview

dirname()Any

Returns the dirname of a path.

Returns:

  • (Any)


2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'puppet/modules/stdlib/lib/puppet/parser/functions/dirname.rb', line 2

newfunction(:dirname, :type => :rvalue, :doc => <<-EOS
  Returns the dirname of a path.
  EOS
) do |arguments|

  if arguments.size < 1 then
    raise(Puppet::ParseError, "dirname(): No arguments given")
  end
  if arguments.size > 1 then
    raise(Puppet::ParseError, "dirname(): Too many arguments given (#{arguments.size})")
  end
  unless arguments[0].is_a?(String)
    raise(Puppet::ParseError, 'dirname(): Requires string as argument')
  end

  return File.dirname(arguments[0])
end