diff options
| author | Luke Kanies <luke@madstop.com> | 2007-08-22 18:07:52 -0500 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-08-22 18:07:52 -0500 |
| commit | b9f529a063cabb183966da29739cd924836eb67b (patch) | |
| tree | c0056176c2ff82d0fe90dfc6c97826f6d79917a6 /lib | |
| parent | 0682d7e473cfd8f2fe6bee9eae0868b846fd0d50 (diff) | |
| parent | 282ec893ef895e0d386126ba70494a3b086030b9 (diff) | |
| download | puppet-b9f529a063cabb183966da29739cd924836eb67b.tar.gz puppet-b9f529a063cabb183966da29739cd924836eb67b.tar.xz puppet-b9f529a063cabb183966da29739cd924836eb67b.zip | |
Merging the multi_env branch with master. There are not actually any conflicts, so this commit might only be necessary because I did not pull sufficiently often.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/puppet/util/autoload.rb | 8 | ||||
| -rw-r--r-- | lib/puppet/util/config.rb | 59 | ||||
| -rw-r--r-- | lib/puppet/util/suidmanager.rb | 1 |
3 files changed, 56 insertions, 12 deletions
diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb index 42aa56c32..be9e14671 100644 --- a/lib/puppet/util/autoload.rb +++ b/lib/puppet/util/autoload.rb @@ -141,7 +141,13 @@ class Puppet::Util::Autoload # The list of directories to search through for loadable plugins. def searchpath - [Puppet[:libdir], $:].flatten + # JJM: Search for optional lib directories in each module bundle. + module_lib_dirs = Puppet[:modulepath].split(":").collect do |d| + Dir.glob("%s/*/lib" % d).select do |f| + FileTest.directory?(f) + end + end.flatten + [module_lib_dirs, Puppet[:libdir], $:].flatten end end diff --git a/lib/puppet/util/config.rb b/lib/puppet/util/config.rb index 6d42f0ea6..932314215 100644 --- a/lib/puppet/util/config.rb +++ b/lib/puppet/util/config.rb @@ -1,6 +1,8 @@ require 'puppet' require 'sync' require 'puppet/transportable' +require 'getoptlong' + # The class for handling configuration files. class Puppet::Util::Config @@ -67,19 +69,12 @@ class Puppet::Util::Config # Generate the list of valid arguments, in a format that GetoptLong can # understand, and add them to the passed option list. def addargs(options) - require 'getoptlong' - # Hackish, but acceptable. Copy the current ARGV for restarting. Puppet.args = ARGV.dup # Add all of the config parameters as valid options. - self.each { |param, obj| - if self.boolean?(param) - options << ["--#{param}", GetoptLong::NO_ARGUMENT] - options << ["--no-#{param}", GetoptLong::NO_ARGUMENT] - else - options << ["--#{param}", GetoptLong::REQUIRED_ARGUMENT] - end + self.each { |name, element| + element.getopt_args.each { |args| options << args } } return options @@ -195,10 +190,17 @@ class Puppet::Util::Config @config.include?(name) end + # check to see if a short name is already defined + def shortinclude?(short) + short = short.intern if name.is_a? String + @shortnames.include?(short) + end + # Create a new config object def initialize @order = [] @config = {} + @shortnames = {} @created = [] @returned = {} @@ -499,7 +501,14 @@ class Puppet::Util::Config if @config.include?(name) raise Puppet::Error, "Parameter %s is already defined" % name end - @config[name] = newelement(hash) + tryconfig = newelement(hash) + if short = tryconfig.short + if other = @shortnames[short] + raise ArgumentError, "Parameter %s is already using short name '%s'" % [other.name, short] + end + @shortnames[short] = tryconfig + end + @config[name] = tryconfig } end @@ -858,7 +867,7 @@ Generated on #{Time.now}. # The base element type. class CElement attr_accessor :name, :section, :default, :parent, :setbycli - attr_reader :desc + attr_reader :desc, :short # Unset any set value. def clear @@ -885,6 +894,15 @@ Generated on #{Time.now}. @desc = value.gsub(/^\s*/, '') end + # get the arguments in getopt format + def getopt_args + if short + [["--#{name}", "-#{short}", GetoptLong::REQUIRED_ARGUMENT]] + else + [["--#{name}", GetoptLong::REQUIRED_ARGUMENT]] + end + end + def hook=(block) meta_def :handle, &block end @@ -929,6 +947,14 @@ Generated on #{Time.now}. end end + # short name for the celement + def short=(value) + if value.to_s.length != 1 + raise ArgumentError, "Short names can only be one character." + end + @short = value.to_s + end + # Convert the object to a config statement. def to_config str = @desc.gsub(/^/, "# ") + "\n" @@ -1101,6 +1127,17 @@ Generated on #{Time.now}. # A simple boolean. class CBoolean < CElement + # get the arguments in getopt format + def getopt_args + if short + [["--#{name}", "-#{short}", GetoptLong::NO_ARGUMENT], + ["--no-#{name}", GetoptLong::NO_ARGUMENT]] + else + [["--#{name}", GetoptLong::NO_ARGUMENT], + ["--no-#{name}", GetoptLong::NO_ARGUMENT]] + end + end + def munge(value) case value when true, "true": return true diff --git a/lib/puppet/util/suidmanager.rb b/lib/puppet/util/suidmanager.rb index e15656d77..c1ff66248 100644 --- a/lib/puppet/util/suidmanager.rb +++ b/lib/puppet/util/suidmanager.rb @@ -1,5 +1,6 @@ require 'facter' require 'puppet/util/warnings' +require 'forwardable' module Puppet::Util::SUIDManager include Puppet::Util::Warnings |
