team470 发表于 2018-8-2 09:17:36

puppet函数 多层路径转换数组

module Puppet::Parser::Functions  
newfunction(:path_to_array, :type => :rvalue) do |args|
  

  
    res = args
  

  
    array = []
  
    array.push(args)
  

  
    if args.size == 1
  
      while res != '/' do
  
      res = File.dirname(res)
  
      array.push(res) if res != '/'
  
      end
  
    elsif args.size == 2
  
      e_count = args - 1
  
      e_count.times do
  
      res = File.dirname(res)
  
      array.push(res) if res != '/'
  
      end
  
    end
  

  
    return array
  
end
  
end
  

  
# vim: set ts=2 sw=2 et :
页: [1]
查看完整版本: puppet函数 多层路径转换数组