puppet 3.0.2 → 3.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (320) hide show
  1. data/Gemfile +13 -11
  2. data/README.md +9 -7
  3. data/README_DEVELOPER.md +21 -30
  4. data/bin/extlookup2hiera +0 -0
  5. data/conf/auth.conf +42 -26
  6. data/conf/fileserver.conf +41 -0
  7. data/conf/tagmail.conf +16 -0
  8. data/examples/hiera/modules/data/manifests/common.pp +2 -1
  9. data/examples/hiera/modules/ntp/manifests/config.pp +4 -3
  10. data/examples/hiera/modules/ntp/manifests/data.pp +2 -1
  11. data/examples/hiera/modules/users/manifests/common.pp +2 -1
  12. data/examples/hiera/modules/users/manifests/dc1.pp +2 -1
  13. data/examples/hiera/modules/users/manifests/development.pp +2 -1
  14. data/examples/hiera/site.pp +1 -1
  15. data/ext/debian/fileserver.conf +39 -15
  16. data/ext/envpuppet +2 -0
  17. data/ext/gentoo/puppet/fileserver.conf +41 -12
  18. data/ext/ips/puppet-agent +1 -6
  19. data/ext/ips/puppetagent.xml +0 -4
  20. data/ext/osx/postflight.erb +109 -0
  21. data/ext/project_data.yaml +2 -2
  22. data/ext/redhat/fileserver.conf +41 -12
  23. data/ext/redhat/puppet.spec.erb +8 -13
  24. data/install.rb +2 -5
  25. data/lib/puppet.rb +30 -13
  26. data/lib/puppet/application.rb +34 -16
  27. data/lib/puppet/application/agent.rb +4 -4
  28. data/lib/puppet/application/master.rb +25 -5
  29. data/lib/puppet/defaults.rb +11 -7
  30. data/lib/puppet/dsl.rb +7 -3
  31. data/lib/puppet/dsl/actions.rb +283 -0
  32. data/lib/puppet/dsl/blank_slate.rb +55 -0
  33. data/lib/puppet/dsl/context.rb +393 -0
  34. data/lib/puppet/dsl/parser.rb +57 -0
  35. data/lib/puppet/dsl/resource_decorator.rb +56 -0
  36. data/lib/puppet/dsl/resource_reference.rb +95 -0
  37. data/lib/puppet/dsl/type_reference.rb +102 -0
  38. data/lib/puppet/error.rb +1 -1
  39. data/lib/puppet/face/help.rb +2 -4
  40. data/lib/puppet/face/man.rb +8 -2
  41. data/lib/puppet/feature/pson.rb +1 -3
  42. data/lib/puppet/indirector/catalog/active_record.rb +3 -0
  43. data/lib/puppet/indirector/catalog/compiler.rb +1 -2
  44. data/lib/puppet/indirector/catalog/queue.rb +4 -0
  45. data/lib/puppet/indirector/catalog/static_compiler.rb +30 -0
  46. data/lib/puppet/indirector/catalog/store_configs.rb +3 -0
  47. data/lib/puppet/indirector/certificate_request/rest.rb +1 -0
  48. data/lib/puppet/indirector/certificate_revocation_list/rest.rb +1 -0
  49. data/lib/puppet/indirector/certificate_status/file.rb +4 -0
  50. data/lib/puppet/indirector/certificate_status/rest.rb +1 -0
  51. data/lib/puppet/indirector/facts/active_record.rb +3 -0
  52. data/lib/puppet/indirector/facts/couch.rb +3 -0
  53. data/lib/puppet/indirector/facts/inventory_active_record.rb +4 -0
  54. data/lib/puppet/indirector/facts/store_configs.rb +3 -0
  55. data/lib/puppet/indirector/file_metadata/rest.rb +2 -0
  56. data/lib/puppet/indirector/instrumentation_data/local.rb +3 -0
  57. data/lib/puppet/indirector/instrumentation_data/rest.rb +3 -0
  58. data/lib/puppet/indirector/instrumentation_listener/local.rb +3 -0
  59. data/lib/puppet/indirector/instrumentation_listener/rest.rb +3 -0
  60. data/lib/puppet/indirector/instrumentation_probe/local.rb +3 -0
  61. data/lib/puppet/indirector/instrumentation_probe/rest.rb +3 -0
  62. data/lib/puppet/indirector/node/active_record.rb +3 -0
  63. data/lib/puppet/indirector/node/rest.rb +2 -2
  64. data/lib/puppet/indirector/node/store_configs.rb +3 -0
  65. data/lib/puppet/indirector/node/write_only_yaml.rb +32 -0
  66. data/lib/puppet/indirector/queue.rb +0 -1
  67. data/lib/puppet/indirector/request.rb +1 -2
  68. data/lib/puppet/indirector/resource/active_record.rb +4 -0
  69. data/lib/puppet/indirector/resource/ral.rb +3 -0
  70. data/lib/puppet/indirector/resource/rest.rb +3 -0
  71. data/lib/puppet/indirector/resource/store_configs.rb +3 -0
  72. data/lib/puppet/indirector/run/local.rb +3 -0
  73. data/lib/puppet/indirector/ssl_file.rb +16 -14
  74. data/lib/puppet/indirector/status/local.rb +3 -0
  75. data/lib/puppet/indirector/status/rest.rb +4 -0
  76. data/lib/puppet/interface.rb +78 -3
  77. data/lib/puppet/interface/action.rb +39 -3
  78. data/lib/puppet/interface/action_builder.rb +74 -1
  79. data/lib/puppet/interface/action_manager.rb +33 -3
  80. data/lib/puppet/interface/documentation.rb +116 -5
  81. data/lib/puppet/interface/face_collection.rb +6 -7
  82. data/lib/puppet/interface/option.rb +10 -1
  83. data/lib/puppet/interface/option_builder.rb +29 -1
  84. data/lib/puppet/interface/option_manager.rb +21 -6
  85. data/lib/puppet/metatype/manager.rb +47 -9
  86. data/lib/puppet/module_tool.rb +0 -1
  87. data/lib/puppet/network/formats.rb +0 -2
  88. data/lib/puppet/node.rb +2 -3
  89. data/lib/puppet/node/environment.rb +14 -1
  90. data/lib/puppet/parameter.rb +309 -44
  91. data/lib/puppet/parameter/package_options.rb +5 -0
  92. data/lib/puppet/parameter/path.rb +26 -3
  93. data/lib/puppet/parameter/value.rb +30 -6
  94. data/lib/puppet/parameter/value_collection.rb +82 -20
  95. data/lib/puppet/parser.rb +3 -0
  96. data/lib/puppet/parser/ast/definition.rb +2 -5
  97. data/lib/puppet/parser/ast/hostclass.rb +2 -3
  98. data/lib/puppet/parser/ast/node.rb +2 -5
  99. data/lib/puppet/parser/ast/resourceparam.rb +1 -1
  100. data/lib/puppet/parser/compiler.rb +10 -0
  101. data/lib/puppet/parser/functions.rb +111 -7
  102. data/lib/puppet/parser/functions/create_resources.rb +23 -2
  103. data/lib/puppet/parser/functions/defined.rb +1 -1
  104. data/lib/puppet/parser/functions/extlookup.rb +2 -1
  105. data/lib/puppet/parser/functions/fail.rb +1 -1
  106. data/lib/puppet/parser/functions/file.rb +1 -1
  107. data/lib/puppet/parser/functions/fqdn_rand.rb +1 -1
  108. data/lib/puppet/parser/functions/generate.rb +1 -1
  109. data/lib/puppet/parser/functions/hiera.rb +1 -1
  110. data/lib/puppet/parser/functions/hiera_array.rb +1 -1
  111. data/lib/puppet/parser/functions/hiera_hash.rb +1 -1
  112. data/lib/puppet/parser/functions/hiera_include.rb +1 -1
  113. data/lib/puppet/parser/functions/include.rb +1 -1
  114. data/lib/puppet/parser/functions/inline_template.rb +1 -1
  115. data/lib/puppet/parser/functions/md5.rb +1 -1
  116. data/lib/puppet/parser/functions/realize.rb +1 -1
  117. data/lib/puppet/parser/functions/regsubst.rb +54 -57
  118. data/lib/puppet/parser/functions/require.rb +1 -0
  119. data/lib/puppet/parser/functions/search.rb +1 -1
  120. data/lib/puppet/parser/functions/sha1.rb +1 -1
  121. data/lib/puppet/parser/functions/shellquote.rb +1 -1
  122. data/lib/puppet/parser/functions/split.rb +1 -2
  123. data/lib/puppet/parser/functions/sprintf.rb +7 -10
  124. data/lib/puppet/parser/functions/tag.rb +1 -1
  125. data/lib/puppet/parser/functions/tagged.rb +1 -1
  126. data/lib/puppet/parser/functions/template.rb +1 -1
  127. data/lib/puppet/parser/functions/versioncmp.rb +1 -5
  128. data/lib/puppet/parser/parser_support.rb +11 -27
  129. data/lib/puppet/parser/scope.rb +48 -4
  130. data/lib/puppet/parser/type_loader.rb +31 -7
  131. data/lib/puppet/property.rb +304 -70
  132. data/lib/puppet/property/ensure.rb +14 -1
  133. data/lib/puppet/property/keyvalue.rb +17 -8
  134. data/lib/puppet/property/list.rb +3 -0
  135. data/lib/puppet/property/ordered_list.rb +7 -0
  136. data/lib/puppet/provider.rb +275 -53
  137. data/lib/puppet/provider/augeas/augeas.rb +17 -3
  138. data/lib/puppet/provider/confiner.rb +30 -1
  139. data/lib/puppet/provider/group/pw.rb +2 -2
  140. data/lib/puppet/provider/package/pip.rb +0 -1
  141. data/lib/puppet/provider/package/pkgin.rb +2 -0
  142. data/lib/puppet/provider/service/bsd.rb +1 -1
  143. data/lib/puppet/provider/service/freebsd.rb +10 -6
  144. data/lib/puppet/provider/service/init.rb +1 -1
  145. data/lib/puppet/provider/service/service.rb +1 -1
  146. data/lib/puppet/provider/user/pw.rb +2 -2
  147. data/lib/puppet/provider/user/useradd.rb +2 -3
  148. data/lib/puppet/reference/configuration.rb +6 -0
  149. data/lib/puppet/reports.rb +44 -4
  150. data/lib/puppet/reports/tagmail.rb +1 -1
  151. data/lib/puppet/resource.rb +38 -25
  152. data/lib/puppet/resource/type.rb +14 -6
  153. data/lib/puppet/settings.rb +66 -142
  154. data/lib/puppet/settings/config_file.rb +99 -0
  155. data/lib/puppet/settings/file_setting.rb +92 -24
  156. data/lib/puppet/settings/value_translator.rb +15 -0
  157. data/lib/puppet/ssl/certificate_authority/interface.rb +2 -2
  158. data/lib/puppet/test/test_helper.rb +8 -3
  159. data/lib/puppet/transaction.rb +1 -2
  160. data/lib/puppet/transaction/report.rb +122 -13
  161. data/lib/puppet/type.rb +763 -150
  162. data/lib/puppet/type/augeas.rb +4 -0
  163. data/lib/puppet/type/file/ensure.rb +1 -1
  164. data/lib/puppet/type/file/group.rb +1 -1
  165. data/lib/puppet/type/file/mode.rb +2 -0
  166. data/lib/puppet/type/file/selcontext.rb +1 -0
  167. data/lib/puppet/type/group.rb +12 -0
  168. data/lib/puppet/type/mount.rb +2 -2
  169. data/lib/puppet/type/notify.rb +1 -1
  170. data/lib/puppet/type/router.rb +1 -1
  171. data/lib/puppet/type/service.rb +1 -0
  172. data/lib/puppet/type/ssh_authorized_key.rb +3 -1
  173. data/lib/puppet/type/user.rb +8 -1
  174. data/lib/puppet/util.rb +8 -0
  175. data/lib/puppet/util/autoload.rb +7 -10
  176. data/lib/puppet/util/classgen.rb +58 -33
  177. data/lib/puppet/util/command_line.rb +120 -77
  178. data/lib/puppet/util/constant_inflector.rb +2 -0
  179. data/lib/puppet/util/execution.rb +63 -33
  180. data/lib/puppet/util/filetype.rb +1 -1
  181. data/lib/puppet/util/manifest_filetype_helper.rb +22 -0
  182. data/lib/puppet/util/methodhelper.rb +19 -0
  183. data/lib/puppet/util/monkey_patches.rb +46 -0
  184. data/lib/puppet/util/plugins.rb +2 -2
  185. data/lib/puppet/util/provider_features.rb +24 -8
  186. data/lib/puppet/util/rubygems.rb +8 -1
  187. data/lib/puppet/util/zaml.rb +1 -1
  188. data/lib/puppet/version.rb +74 -3
  189. data/spec/integration/application/apply_spec.rb +1 -1
  190. data/spec/integration/defaults_spec.rb +1 -0
  191. data/spec/integration/dsl/classes_spec.rb +191 -0
  192. data/spec/integration/dsl/defaults_spec.rb +38 -0
  193. data/spec/integration/dsl/definitions_spec.rb +73 -0
  194. data/spec/integration/dsl/functions_spec.rb +95 -0
  195. data/spec/integration/dsl/nodes_spec.rb +96 -0
  196. data/spec/integration/dsl/params_spec.rb +146 -0
  197. data/spec/integration/dsl/relationships_spec.rb +46 -0
  198. data/spec/integration/dsl/resources_spec.rb +202 -0
  199. data/spec/integration/dsl/type_loading_spec.rb +64 -0
  200. data/spec/integration/indirector/catalog/queue_spec.rb +1 -1
  201. data/spec/integration/network/formats_spec.rb +32 -45
  202. data/spec/integration/parser/collector_spec.rb +105 -25
  203. data/spec/integration/parser/scope_spec.rb +64 -1
  204. data/spec/integration/resource/catalog_spec.rb +2 -4
  205. data/spec/integration/type/package_spec.rb +1 -1
  206. data/spec/lib/matchers/catalog.rb +50 -0
  207. data/spec/lib/puppet_spec/compiler.rb +11 -0
  208. data/spec/lib/puppet_spec/dsl.rb +29 -0
  209. data/spec/spec_helper.rb +17 -3
  210. data/spec/unit/application/agent_spec.rb +0 -1
  211. data/spec/unit/application/apply_spec.rb +1 -1
  212. data/spec/unit/application/face_base_spec.rb +11 -4
  213. data/spec/unit/application/indirection_base_spec.rb +4 -8
  214. data/spec/unit/application/kick_spec.rb +5 -2
  215. data/spec/unit/application/master_spec.rb +0 -6
  216. data/spec/unit/application_spec.rb +38 -14
  217. data/spec/unit/dsl/actions_spec.rb +402 -0
  218. data/spec/unit/dsl/blank_slate_spec.rb +27 -0
  219. data/spec/unit/dsl/context_spec.rb +678 -0
  220. data/spec/unit/dsl/parser_spec.rb +56 -0
  221. data/spec/unit/dsl/resource_decorator_spec.rb +94 -0
  222. data/spec/unit/dsl/resource_reference_spec.rb +150 -0
  223. data/spec/unit/dsl/type_reference_spec.rb +164 -0
  224. data/spec/unit/face/help_spec.rb +5 -7
  225. data/spec/unit/indirector/certificate_request/rest_spec.rb +4 -0
  226. data/spec/unit/indirector/certificate_revocation_list/rest_spec.rb +4 -0
  227. data/spec/unit/indirector/certificate_status/rest_spec.rb +4 -0
  228. data/spec/unit/indirector/file_metadata/rest_spec.rb +5 -0
  229. data/spec/unit/indirector/hiera_spec.rb +3 -1
  230. data/spec/unit/indirector/queue_spec.rb +1 -7
  231. data/spec/unit/indirector/ssl_file_spec.rb +66 -39
  232. data/spec/unit/module_spec.rb +1 -1
  233. data/spec/unit/network/authstore_spec.rb +22 -1
  234. data/spec/unit/network/formats_spec.rb +1 -1
  235. data/spec/unit/node/environment_spec.rb +13 -0
  236. data/spec/unit/parser/collector_spec.rb +1 -1
  237. data/spec/unit/parser/compiler_spec.rb +26 -0
  238. data/spec/unit/parser/functions/create_resources_spec.rb +12 -1
  239. data/spec/unit/parser/functions/extlookup_spec.rb +4 -4
  240. data/spec/unit/parser/functions/hiera_array_spec.rb +1 -1
  241. data/spec/unit/parser/functions/hiera_hash_spec.rb +1 -1
  242. data/spec/unit/parser/functions/hiera_include_spec.rb +1 -1
  243. data/spec/unit/parser/functions/hiera_spec.rb +1 -1
  244. data/spec/unit/parser/functions/regsubst_spec.rb +4 -4
  245. data/spec/unit/parser/functions/split_spec.rb +4 -4
  246. data/spec/unit/parser/functions/sprintf_spec.rb +2 -2
  247. data/spec/unit/parser/functions/versioncmp_spec.rb +4 -4
  248. data/spec/unit/parser/functions_spec.rb +51 -1
  249. data/spec/unit/parser/parser_spec.rb +0 -14
  250. data/spec/unit/parser/type_loader_spec.rb +15 -1
  251. data/spec/unit/provider/augeas/augeas_spec.rb +31 -0
  252. data/spec/unit/provider/package/apt_spec.rb +0 -2
  253. data/spec/unit/provider/package/pip_spec.rb +12 -2
  254. data/spec/unit/provider/service/freebsd_spec.rb +8 -0
  255. data/spec/unit/provider/service/gentoo_spec.rb +20 -20
  256. data/spec/unit/provider/service/openrc_spec.rb +20 -20
  257. data/spec/unit/provider/service/src_spec.rb +4 -4
  258. data/spec/unit/provider/service/systemd_spec.rb +0 -8
  259. data/spec/unit/provider/service/windows_spec.rb +1 -1
  260. data/spec/unit/provider/user/useradd_spec.rb +2 -9
  261. data/spec/unit/relationship_spec.rb +2 -2
  262. data/spec/unit/resource/catalog_spec.rb +2 -2
  263. data/spec/unit/resource/type_spec.rb +49 -25
  264. data/spec/unit/resource_spec.rb +34 -2
  265. data/spec/unit/settings/config_file_spec.rb +100 -0
  266. data/spec/unit/settings/file_setting_spec.rb +87 -84
  267. data/spec/unit/settings/value_translator_spec.rb +77 -0
  268. data/spec/unit/settings_spec.rb +96 -29
  269. data/spec/unit/type/file/ensure_spec.rb +75 -36
  270. data/spec/unit/type/file_spec.rb +0 -68
  271. data/spec/unit/type/group_spec.rb +10 -0
  272. data/spec/unit/util/autoload_spec.rb +6 -0
  273. data/spec/unit/util/command_line_spec.rb +54 -62
  274. data/spec/unit/util/manifest_filetype_helper_spec.rb +29 -0
  275. data/spec/unit/util/metric_spec.rb +0 -9
  276. data/spec/unit/util/posix_spec.rb +0 -4
  277. data/spec/unit/util/rdoc_spec.rb +0 -12
  278. data/spec/unit/util/zaml_spec.rb +188 -130
  279. data/spec/unit/version_spec.rb +42 -0
  280. metadata +123 -90
  281. data/README_HIERA.md +0 -148
  282. data/conf/epm.list +0 -8
  283. data/conf/namespaceauth.conf +0 -20
  284. data/conf/puppet-queue.conf +0 -10
  285. data/examples/allatonce +0 -13
  286. data/examples/assignments +0 -11
  287. data/examples/components +0 -73
  288. data/examples/etc/init.d/sleeper +0 -70
  289. data/examples/etc/otherfile +0 -0
  290. data/examples/etc/puppet/fileserver.conf +0 -13
  291. data/examples/etc/puppet/namespaceauth.conf +0 -20
  292. data/examples/etc/puppet/puppet.conf +0 -10
  293. data/examples/etc/puppet/tagmail.conf +0 -1
  294. data/examples/execs +0 -16
  295. data/examples/file.bl +0 -11
  296. data/examples/filedefaults +0 -10
  297. data/examples/fileparsing +0 -116
  298. data/examples/filerecursion +0 -15
  299. data/examples/functions +0 -3
  300. data/examples/groups +0 -7
  301. data/examples/head +0 -30
  302. data/examples/importing +0 -8
  303. data/examples/mac_dscl.pp +0 -28
  304. data/examples/mac_dscl_revert.pp +0 -26
  305. data/examples/mac_pkgdmg.pp +0 -7
  306. data/examples/modules/sample_module.pp +0 -10
  307. data/examples/modules/sample_module/lib/puppet/parser/functions/hostname_to_dn.rb +0 -36
  308. data/examples/modules/sample_module/manifests/init.pp +0 -12
  309. data/examples/modules/sample_module/templates/sample.erb +0 -5
  310. data/examples/nodes +0 -20
  311. data/examples/one +0 -8
  312. data/examples/relationships +0 -34
  313. data/examples/selectors +0 -28
  314. data/examples/simpletests +0 -11
  315. data/examples/svncommit +0 -13
  316. data/lib/puppet/dsl/resource_api.rb +0 -120
  317. data/lib/puppet/dsl/resource_type_api.rb +0 -34
  318. data/spec/integration/parser/ruby_manifest_spec.rb +0 -127
  319. data/spec/unit/dsl/resource_api_spec.rb +0 -180
  320. data/spec/unit/dsl/resource_type_api_spec.rb +0 -53
@@ -3,11 +3,17 @@ require 'puppet/interface/documentation'
3
3
  require 'puppet/util/methodhelper'
4
4
  require 'prettyprint'
5
5
 
6
+ # This represents an action that is attached to a face. Actions should
7
+ # be constructed by calling {Puppet::Interface::ActionManager#action},
8
+ # which is available on {Puppet::Interface}, and then calling methods of
9
+ # {Puppet::Interface::ActionBuilder} in the supplied block.
10
+ # @api private
6
11
  class Puppet::Interface::Action
7
12
  include Puppet::Util::MethodHelper
8
13
  extend Puppet::Interface::DocGen
9
14
  include Puppet::Interface::FullDocs
10
15
 
16
+ # @api private
11
17
  def initialize(face, name, attrs = {})
12
18
  raise "#{name.inspect} is an invalid action name" unless name.to_s =~ /^[a-z]\w*$/
13
19
  @face = face
@@ -32,6 +38,9 @@ class Puppet::Interface::Action
32
38
  # This is not nice, but it is the easiest way to make us behave like the
33
39
  # Ruby Method object rather than UnboundMethod. Duplication is vaguely
34
40
  # annoying, but at least we are a shallow clone. --daniel 2011-04-12
41
+
42
+ # @return [void]
43
+ # @api private
35
44
  def __dup_and_rebind_to(to)
36
45
  bound_version = self.dup
37
46
  bound_version.instance_variable_set(:@face, to)
@@ -40,8 +49,17 @@ class Puppet::Interface::Action
40
49
 
41
50
  def to_s() "#{@face}##{@name}" end
42
51
 
52
+ # The name of this action
53
+ # @return [Symbol]
43
54
  attr_reader :name
55
+
56
+ # The face this action is attached to
57
+ # @return [Puppet::Interface]
44
58
  attr_reader :face
59
+
60
+ # Whether this is the default action for the face
61
+ # @return [Boolean]
62
+ # @api private
45
63
  attr_accessor :default
46
64
  def default?
47
65
  !!@default
@@ -57,6 +75,9 @@ class Puppet::Interface::Action
57
75
 
58
76
  ########################################################################
59
77
  # Support for rendering formats and all.
78
+
79
+
80
+ # @api private
60
81
  def when_rendering(type)
61
82
  unless type.is_a? Symbol
62
83
  raise ArgumentError, "The rendering format must be a symbol, not #{type.class.name}"
@@ -71,6 +92,8 @@ class Puppet::Interface::Action
71
92
  # Guess not, nothing to run.
72
93
  return nil
73
94
  end
95
+
96
+ # @api private
74
97
  def set_rendering_method_for(type, proc)
75
98
  unless proc.is_a? Proc
76
99
  msg = "The second argument to set_rendering_method_for must be a Proc"
@@ -103,12 +126,16 @@ class Puppet::Interface::Action
103
126
  @face.__send__( :__add_method, __render_method_name_for(type), proc)
104
127
  end
105
128
 
129
+ # @return [void]
130
+ # @api private
106
131
  def __render_method_name_for(type)
107
132
  :"#{name}_when_rendering_#{type}"
108
133
  end
109
134
  private :__render_method_name_for
110
135
 
111
136
 
137
+ # @api private
138
+ # @return [Symbol]
112
139
  attr_accessor :render_as
113
140
  def render_as=(value)
114
141
  @render_as = value.to_sym
@@ -169,7 +196,14 @@ class Puppet::Interface::Action
169
196
  # this stuff work, because it would have been cleaner. Which gives you an
170
197
  # idea how motivated we were to make this cleaner. Sorry.
171
198
  # --daniel 2011-03-31
199
+
200
+
201
+ # The arity of the action
202
+ # @return [Integer]
172
203
  attr_reader :positional_arg_count
204
+
205
+ # The block that is executed when the action is invoked
206
+ # @return [block]
173
207
  attr_accessor :when_invoked
174
208
  def when_invoked=(block)
175
209
 
@@ -249,7 +283,7 @@ WRAPPER
249
283
  def options
250
284
  @face.options + @options
251
285
  end
252
-
286
+
253
287
  def add_display_global_options(*args)
254
288
  @display_global_options ||= []
255
289
  [args].flatten.each do |refopt|
@@ -259,12 +293,12 @@ WRAPPER
259
293
  @display_global_options.uniq!
260
294
  @display_global_options
261
295
  end
262
-
296
+
263
297
  def display_global_options(*args)
264
298
  args ? add_display_global_options(args) : @display_global_options + @face.display_global_options
265
299
  end
266
300
  alias :display_global_option :display_global_options
267
-
301
+
268
302
  def get_option(name, with_inherited_options = true)
269
303
  option = @options_hash[name.to_sym]
270
304
  if option.nil? and with_inherited_options
@@ -334,6 +368,8 @@ WRAPPER
334
368
  # Support code for action decoration; see puppet/interface.rb for the gory
335
369
  # details of why this is hidden away behind private. --daniel 2011-04-15
336
370
  private
371
+ # @return [void]
372
+ # @api private
337
373
  def __add_method(name, proc)
338
374
  @face.__send__ :__add_method, name, proc
339
375
  end
@@ -1,9 +1,20 @@
1
1
  require 'puppet/interface'
2
2
  require 'puppet/interface/action'
3
3
 
4
+ # This class is used to build {Puppet::Interface::Action actions}.
5
+ # When an action is defined with
6
+ # {Puppet::Interface::ActionManager#action} the block is evaluated
7
+ # within the context of a new instance of this class.
8
+ # @api public
4
9
  class Puppet::Interface::ActionBuilder
10
+ # The action under construction
11
+ # @return [Puppet::Interface::Action]
12
+ # @api private
5
13
  attr_reader :action
6
14
 
15
+ # Builds a new action.
16
+ # @return [Puppet::Interface::Action]
17
+ # @api private
7
18
  def self.build(face, name, &block)
8
19
  raise "Action #{name.inspect} must specify a block" unless block
9
20
  new(face, name, &block).action
@@ -12,10 +23,33 @@ class Puppet::Interface::ActionBuilder
12
23
  # Ideally the method we're defining here would be added to the action, and a
13
24
  # method on the face would defer to it, but we can't get scope correct, so
14
25
  # we stick with this. --daniel 2011-03-24
26
+
27
+ # Sets what the action does when it is invoked. This takes a block
28
+ # which will be called when the action is invoked. The action will
29
+ # accept arguments based on the arity of the block. It should always
30
+ # take at least one argument for options. Options will be the last
31
+ # argument.
32
+ #
33
+ # @overload when_invoked({|options| ... })
34
+ # An action with no arguments
35
+ # @overload when_invoked({|arg1, arg2, options| ... })
36
+ # An action with two arguments
37
+ # @return [void]
38
+ # @api public
39
+ # @dsl Faces
15
40
  def when_invoked(&block)
16
41
  @action.when_invoked = block
17
42
  end
18
43
 
44
+ # Sets a block to be run at the rendering stage, for a specific
45
+ # rendering type (eg JSON, YAML, console), after the block for
46
+ # when_invoked gets run. This manipulates the value returned by the
47
+ # action. It makes it possible to work around limitations in the
48
+ # underlying object returned, and should be avoided in favor of
49
+ # returning a more capable object.
50
+ # @api private
51
+ # @todo this needs more
52
+ # @dsl Faces
19
53
  def when_rendering(type = nil, &block)
20
54
  if type.nil? then # the default error message sucks --daniel 2011-04-18
21
55
  raise ArgumentError, 'You must give a rendering format to when_rendering'
@@ -26,20 +60,59 @@ class Puppet::Interface::ActionBuilder
26
60
  @action.set_rendering_method_for(type, block)
27
61
  end
28
62
 
63
+ # Declare that this action can take a specific option, and provide the
64
+ # code to do so. One or more strings are given, in the style of
65
+ # OptionParser (see example). These strings are parsed to derive a
66
+ # name for the option. Any `-` characters within the option name (ie
67
+ # excluding the intial `-` or `--` for an option) will be translated
68
+ # to `_`.The first long option will be used as the name, and the rest
69
+ # are retained as aliases. The original form of the option is used
70
+ # when invoking the face, the translated form is used internally.
71
+ #
72
+ # When the action is invoked the value of the option is available in
73
+ # a hash passed to the {Puppet::Interface::ActionBuilder#when_invoked
74
+ # when_invoked} block, using the option name in symbol form as the
75
+ # hash key.
76
+ #
77
+ # The block to this method is used to set attributes for the option
78
+ # (see {Puppet::Interface::OptionBuilder}).
79
+ #
80
+ # @param declaration [String] Option declarations, as described above
81
+ # and in the example.
82
+ #
83
+ # @example Say hi
84
+ # action :say_hi do
85
+ # option "-u USER", "--user-name USER" do
86
+ # summary "Who to say hi to"
87
+ # end
88
+ #
89
+ # when_invoked do |options|
90
+ # "Hi, #{options[:user_name]}"
91
+ # end
92
+ # end
93
+ # @api public
94
+ # @dsl Faces
29
95
  def option(*declaration, &block)
30
96
  option = Puppet::Interface::OptionBuilder.build(@action, *declaration, &block)
31
97
  @action.add_option(option)
32
98
  end
33
99
 
100
+ # Set this as the default action for the face.
101
+ # @api public
102
+ # @dsl Faces
103
+ # @return [void]
34
104
  def default(value = true)
35
105
  @action.default = !!value
36
106
  end
37
-
107
+
108
+ # @api private
38
109
  def display_global_options(*args)
39
110
  @action.add_display_global_options args
40
111
  end
41
112
  alias :display_global_option :display_global_options
42
113
 
114
+ # Sets the default rendering format
115
+ # @api private
43
116
  def render_as(value = nil)
44
117
  value.nil? and raise ArgumentError, "You must give a rendering format to render_as"
45
118
 
@@ -1,15 +1,30 @@
1
1
  require 'puppet/interface/action'
2
2
  require 'puppet/interface/action_builder'
3
3
 
4
+ # This class is not actually public API, but the method
5
+ # {Puppet::Interface::ActionManager#action action} is public when used
6
+ # as part of the Faces DSL (i.e. from within a
7
+ # {Puppet::Interface.define define} block).
8
+ # @api public
4
9
  module Puppet::Interface::ActionManager
5
10
  # Declare that this app can take a specific action, and provide
6
11
  # the code to do so.
12
+
13
+ # Defines a new action. This takes a block to build the action using
14
+ # the methods on {Puppet::Interface::ActionBuilder}.
15
+ # @param name [Symbol] The name that will be used to invoke the
16
+ # action
17
+ # @overload action(name, {|| block})
18
+ # @return [void]
19
+ # @api public
20
+ # @dsl Faces
7
21
  def action(name, &block)
8
22
  @actions ||= {}
9
23
  Puppet.warning "Redefining action #{name} for #{self}" if action?(name)
10
24
 
11
25
  action = Puppet::Interface::ActionBuilder.build(self, name, &block)
12
26
 
27
+ # REVISIT: (#18042) doesn't this mean we can't redefine the default action? -- josh
13
28
  if action.default and current = get_default_action
14
29
  raise "Actions #{current.name} and #{name} cannot both be default"
15
30
  end
@@ -17,14 +32,21 @@ module Puppet::Interface::ActionManager
17
32
  @actions[action.name] = action
18
33
  end
19
34
 
20
- # This is the short-form of an action definition; it doesn't use the
21
- # builder, just creates the action directly from the block.
35
+ # Defines an action without using ActionBuilder. The block given is
36
+ # the code that will be executed when the action is invoked.
37
+ # @api public
38
+ # @deprecated
22
39
  def script(name, &block)
23
40
  @actions ||= {}
24
- raise "Action #{name} already defined for #{self}" if action?(name)
41
+ Puppet.warning "Redefining action #{name} for #{self}" if action?(name)
42
+
43
+ # REVISIT: (#18048) it's possible to create multiple default actions
25
44
  @actions[name] = Puppet::Interface::Action.new(self, name, :when_invoked => block)
26
45
  end
27
46
 
47
+ # Returns the list of available actions for this face.
48
+ # @return [Array<Symbol>] The names of the actions for this face
49
+ # @api private
28
50
  def actions
29
51
  @actions ||= {}
30
52
  result = @actions.keys
@@ -40,6 +62,10 @@ module Puppet::Interface::ActionManager
40
62
  result.uniq.sort
41
63
  end
42
64
 
65
+ # Retrieves a named action
66
+ # @param name [Symbol] The name of the action
67
+ # @return [Puppet::Interface::Action] The action object
68
+ # @api private
43
69
  def get_action(name)
44
70
  @actions ||= {}
45
71
  result = @actions[name.to_sym]
@@ -60,6 +86,9 @@ module Puppet::Interface::ActionManager
60
86
  return result
61
87
  end
62
88
 
89
+ # Retrieves the default action for the face
90
+ # @return [Puppet::Interface::Action]
91
+ # @api private
63
92
  def get_default_action
64
93
  default = actions.map {|x| get_action(x) }.select {|x| x.default }
65
94
  if default.length > 1
@@ -68,6 +97,7 @@ module Puppet::Interface::ActionManager
68
97
  default.first
69
98
  end
70
99
 
100
+ # @api private
71
101
  def action?(name)
72
102
  actions.include?(name.to_sym)
73
103
  end
@@ -1,6 +1,7 @@
1
- # This isn't usable outside Puppet::Interface; don't load it alone.
2
1
  class Puppet::Interface
2
+ # @api private
3
3
  module DocGen
4
+ # @api private
4
5
  def self.strip_whitespace(text)
5
6
  text.gsub!(/[ \t\f]+$/, '')
6
7
 
@@ -25,6 +26,8 @@ class Puppet::Interface
25
26
  #
26
27
  # This feels a bit like overkill, but at least the common code is common
27
28
  # now. --daniel 2011-04-29
29
+
30
+ # @api private
28
31
  def attr_doc(name, &validate)
29
32
  # Now, which form of the setter do we want, validated or not?
30
33
  get_arg = "value.to_s"
@@ -51,17 +54,30 @@ class Puppet::Interface
51
54
  end
52
55
  end
53
56
 
57
+ # This module can be mixed in to provide a minimal set of
58
+ # documentation attributes.
59
+ # @api public
54
60
  module TinyDocs
55
61
  extend Puppet::Interface::DocGen
56
62
 
63
+ # @!method summary(summary)
64
+ # Sets a summary of this object.
65
+ # @api public
66
+ # @dsl Faces
57
67
  attr_doc :summary do |value|
58
68
  value =~ /\n/ and
59
69
  raise ArgumentError, "Face summary should be a single line; put the long text in 'description' instead."
60
70
  value
61
71
  end
62
72
 
73
+ # @!method description(description)
74
+ # Sets the long description of this object.
75
+ # @param description [String] The description of this object.
76
+ # @api public
77
+ # @dsl Faces
63
78
  attr_doc :description
64
79
 
80
+ # @api private
65
81
  def build_synopsis(face, action = nil, arguments = nil)
66
82
  output = PrettyPrint.format do |s|
67
83
  s.text("puppet #{face}")
@@ -85,13 +101,13 @@ class Puppet::Interface
85
101
 
86
102
  s.breakable
87
103
  end
88
-
104
+
89
105
  display_global_options.sort.each do |option|
90
106
  wrap = %w{ [ ] }
91
107
  s.group(0, *wrap) do
92
- desc = Puppet.settings.setting(option).desc
93
- type = Puppet.settings.setting(option).default
94
- type ||= Puppet.settings.setting(option).type.to_s.upcase
108
+ desc = Puppet.settings.setting(option).desc
109
+ type = Puppet.settings.setting(option).default
110
+ type ||= Puppet.settings.setting(option).type.to_s.upcase
95
111
  s.text "--#{option} #{type}"
96
112
  s.breakable
97
113
  end
@@ -106,15 +122,68 @@ class Puppet::Interface
106
122
 
107
123
  end
108
124
 
125
+ # This module can be mixed in to provide a full set of documentation
126
+ # attributes. It is intended to be used for {Puppet::Interface}.
127
+ # @api public
109
128
  module FullDocs
110
129
  extend Puppet::Interface::DocGen
111
130
  include TinyDocs
112
131
 
132
+ # @!method examples
133
+ # @overload examples(text)
134
+ # Sets examples.
135
+ # @param text [String] Example text
136
+ # @api public
137
+ # @returns [void]
138
+ # @dsl Faces
139
+ # @overload examples
140
+ # Returns documentation of examples
141
+ # @returns [String] The examples
142
+ # @api private
113
143
  attr_doc :examples
144
+
145
+ # @!method notes(text)
146
+ # @overload notes(text)
147
+ # Sets optional notes.
148
+ # @param text [String] The notes
149
+ # @api public
150
+ # @returns [void]
151
+ # @dsl Faces
152
+ # @overload notes
153
+ # Returns any optional notes
154
+ # @returns [String] The notes
155
+ # @api private
114
156
  attr_doc :notes
157
+
158
+ # @!method license(text)
159
+ # @overload license(text)
160
+ # Sets the license text
161
+ # @param text [String] the license text
162
+ # @api public
163
+ # @returns [void]
164
+ # @dsl Faces
165
+ # @overload license
166
+ # Returns the license
167
+ # @returns [String] The license
168
+ # @api private
115
169
  attr_doc :license
116
170
 
117
171
  attr_doc :short_description
172
+ # @overload short_description(value)
173
+ # Sets a short description for this object.
174
+ # @param value [String, nil] A short description (about a paragraph)
175
+ # of this component. If `value` is `nil` the short_description
176
+ # will be set to the shorter of the first paragraph or the first
177
+ # five lines of {description}.
178
+ # @return [void]
179
+ # @api public
180
+ # @dsl Faces
181
+ # @overload short_description
182
+ # Get the short description for this object
183
+ # @return [String, nil] The short description of this object. If none is
184
+ # set it will be derived from {description}. Returns `nil` if
185
+ # {description} is `nil`.
186
+ # @api private
118
187
  def short_description(value = nil)
119
188
  self.short_description = value unless value.nil?
120
189
  if @short_description.nil? then
@@ -128,6 +197,17 @@ class Puppet::Interface
128
197
  @short_description
129
198
  end
130
199
 
200
+ # @overload author(value)
201
+ # Adds an author to the documentation for this object. To set
202
+ # multiple authors, call this once for each author.
203
+ # @param value [String] the name of the author
204
+ # @api public
205
+ # @dsl Faces
206
+ # @overload author
207
+ # Returns a list of authors
208
+ # @return [String, nil] The names of all authors separated by
209
+ # newlines, or `nil` if no authors have been set.
210
+ # @api private
131
211
  def author(value = nil)
132
212
  unless value.nil? then
133
213
  unless value.is_a? String
@@ -141,10 +221,18 @@ class Puppet::Interface
141
221
  end
142
222
  @authors.empty? ? nil : @authors.join("\n")
143
223
  end
224
+
225
+ # Returns a list of authors. See {author}.
226
+ # @return [String] The list of authors, separated by newlines.
227
+ # @api private
144
228
  def authors
145
229
  @authors
146
230
  end
231
+
232
+ # @api private
147
233
  def author=(value)
234
+ # I think it's a bug that this ends up being the exposed
235
+ # version of `author` on ActionBuilder
148
236
  if Array(value).any? {|x| x =~ /\n/ } then
149
237
  raise ArgumentError, 'author should be a single line; use multiple statements'
150
238
  end
@@ -152,6 +240,18 @@ class Puppet::Interface
152
240
  end
153
241
  alias :authors= :author=
154
242
 
243
+ # Sets the copyright owner and year. This returns the copyright
244
+ # string, so it can be called with no arguments retrieve that string
245
+ # without side effects.
246
+ # @param owner [String, Array<String>] The copyright owner or an
247
+ # array of owners
248
+ # @param years [Integer, Range<Integer>, Array<Integer,Range<Integer>>]
249
+ # The copyright year or years. Years can be specified with integers,
250
+ # a range of integers, or an array of integers and ranges of
251
+ # integers.
252
+ # @return [String] A string describing the copyright on this object.
253
+ # @api public
254
+ # @dsl Faces
155
255
  def copyright(owner = nil, years = nil)
156
256
  if years.nil? and not owner.nil? then
157
257
  raise ArgumentError, 'copyright takes the owners names, then the years covered'
@@ -166,6 +266,11 @@ class Puppet::Interface
166
266
  end
167
267
  end
168
268
 
269
+ # Sets the copyright owner
270
+ # @param value [String, Array<String>] The copyright owner or
271
+ # owners.
272
+ # @return [String] Comma-separated list of copyright owners
273
+ # @api private
169
274
  attr_accessor :copyright_owner
170
275
  def copyright_owner=(value)
171
276
  case value
@@ -177,6 +282,11 @@ class Puppet::Interface
177
282
  @copyright_owner
178
283
  end
179
284
 
285
+ # Sets the copyright year
286
+ # @param value [Integer, Range<Integer>, Array<Integer, Range>] The
287
+ # copyright year or years.
288
+ # @return [String]
289
+ # @api private
180
290
  attr_accessor :copyright_years
181
291
  def copyright_years=(value)
182
292
  years = munge_copyright_year value
@@ -192,6 +302,7 @@ class Puppet::Interface
192
302
  end.join(", ")
193
303
  end
194
304
 
305
+ # @api private
195
306
  def munge_copyright_year(input)
196
307
  case input
197
308
  when Range then input