puppet 8.3.1 → 8.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (1052) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +51 -43
  3. data/README.md +4 -4
  4. data/Rakefile +0 -27
  5. data/examples/enc/regexp_nodes/regexp_nodes.rb +1 -1
  6. data/ext/windows/service/daemon.rb +4 -5
  7. data/lib/hiera/puppet_function.rb +3 -2
  8. data/lib/hiera/scope.rb +2 -2
  9. data/lib/hiera_puppet.rb +1 -3
  10. data/lib/puppet/agent/disabler.rb +2 -1
  11. data/lib/puppet/agent/locker.rb +1 -2
  12. data/lib/puppet/agent.rb +2 -1
  13. data/lib/puppet/application/agent.rb +292 -291
  14. data/lib/puppet/application/apply.rb +143 -139
  15. data/lib/puppet/application/catalog.rb +1 -0
  16. data/lib/puppet/application/config.rb +1 -0
  17. data/lib/puppet/application/describe.rb +53 -55
  18. data/lib/puppet/application/device.rb +150 -150
  19. data/lib/puppet/application/doc.rb +60 -59
  20. data/lib/puppet/application/epp.rb +1 -0
  21. data/lib/puppet/application/face_base.rb +8 -7
  22. data/lib/puppet/application/facts.rb +1 -0
  23. data/lib/puppet/application/filebucket.rb +186 -184
  24. data/lib/puppet/application/generate.rb +1 -0
  25. data/lib/puppet/application/help.rb +1 -0
  26. data/lib/puppet/application/indirection_base.rb +1 -0
  27. data/lib/puppet/application/lookup.rb +168 -171
  28. data/lib/puppet/application/module.rb +1 -0
  29. data/lib/puppet/application/node.rb +1 -0
  30. data/lib/puppet/application/parser.rb +1 -0
  31. data/lib/puppet/application/plugin.rb +1 -0
  32. data/lib/puppet/application/report.rb +1 -0
  33. data/lib/puppet/application/resource.rb +111 -108
  34. data/lib/puppet/application/script.rb +92 -93
  35. data/lib/puppet/application/ssl.rb +89 -88
  36. data/lib/puppet/application.rb +9 -8
  37. data/lib/puppet/application_support.rb +1 -1
  38. data/lib/puppet/coercion.rb +3 -2
  39. data/lib/puppet/compilable_resource_type.rb +1 -0
  40. data/lib/puppet/concurrent/lock.rb +1 -2
  41. data/lib/puppet/concurrent/synchronized.rb +1 -2
  42. data/lib/puppet/concurrent/thread_local_singleton.rb +1 -0
  43. data/lib/puppet/concurrent.rb +1 -0
  44. data/lib/puppet/configurer/downloader.rb +1 -1
  45. data/lib/puppet/configurer/fact_handler.rb +2 -1
  46. data/lib/puppet/configurer/plugin_handler.rb +1 -0
  47. data/lib/puppet/configurer.rb +17 -13
  48. data/lib/puppet/confine/any.rb +1 -0
  49. data/lib/puppet/confine/boolean.rb +1 -0
  50. data/lib/puppet/confine/exists.rb +1 -0
  51. data/lib/puppet/confine/false.rb +1 -0
  52. data/lib/puppet/confine/feature.rb +1 -0
  53. data/lib/puppet/confine/true.rb +1 -0
  54. data/lib/puppet/confine/variable.rb +1 -0
  55. data/lib/puppet/confine.rb +2 -0
  56. data/lib/puppet/confine_collection.rb +3 -1
  57. data/lib/puppet/confiner.rb +1 -0
  58. data/lib/puppet/context/trusted_information.rb +1 -0
  59. data/lib/puppet/context.rb +1 -0
  60. data/lib/puppet/daemon.rb +4 -1
  61. data/lib/puppet/data_binding.rb +2 -1
  62. data/lib/puppet/datatypes/error.rb +2 -1
  63. data/lib/puppet/datatypes/impl/error.rb +1 -0
  64. data/lib/puppet/datatypes.rb +5 -1
  65. data/lib/puppet/defaults.rb +19 -18
  66. data/lib/puppet/environments.rb +3 -2
  67. data/lib/puppet/error.rb +9 -7
  68. data/lib/puppet/etc.rb +6 -3
  69. data/lib/puppet/external/dot.rb +12 -31
  70. data/lib/puppet/face/catalog/select.rb +2 -1
  71. data/lib/puppet/face/catalog.rb +3 -2
  72. data/lib/puppet/face/config.rb +18 -20
  73. data/lib/puppet/face/epp.rb +6 -6
  74. data/lib/puppet/face/facts.rb +4 -3
  75. data/lib/puppet/face/generate.rb +2 -0
  76. data/lib/puppet/face/help.rb +8 -7
  77. data/lib/puppet/face/module/changes.rb +2 -0
  78. data/lib/puppet/face/module/install.rb +2 -1
  79. data/lib/puppet/face/module/list.rb +7 -8
  80. data/lib/puppet/face/module/uninstall.rb +1 -0
  81. data/lib/puppet/face/module.rb +1 -0
  82. data/lib/puppet/face/node/clean.rb +2 -1
  83. data/lib/puppet/face/node.rb +2 -1
  84. data/lib/puppet/face/parser.rb +2 -2
  85. data/lib/puppet/face/plugin.rb +2 -1
  86. data/lib/puppet/face/report.rb +2 -1
  87. data/lib/puppet/face/resource.rb +1 -0
  88. data/lib/puppet/face.rb +1 -0
  89. data/lib/puppet/feature/base.rb +2 -1
  90. data/lib/puppet/feature/bolt.rb +1 -0
  91. data/lib/puppet/feature/cfpropertylist.rb +1 -0
  92. data/lib/puppet/feature/eventlog.rb +1 -0
  93. data/lib/puppet/feature/hiera_eyaml.rb +1 -0
  94. data/lib/puppet/feature/hocon.rb +1 -0
  95. data/lib/puppet/feature/libuser.rb +4 -3
  96. data/lib/puppet/feature/msgpack.rb +1 -0
  97. data/lib/puppet/feature/pe_license.rb +2 -1
  98. data/lib/puppet/feature/pson.rb +1 -0
  99. data/lib/puppet/feature/selinux.rb +1 -0
  100. data/lib/puppet/feature/ssh.rb +1 -0
  101. data/lib/puppet/feature/telnet.rb +1 -0
  102. data/lib/puppet/feature/zlib.rb +1 -0
  103. data/lib/puppet/ffi/posix/constants.rb +1 -0
  104. data/lib/puppet/ffi/posix/functions.rb +1 -1
  105. data/lib/puppet/ffi/posix.rb +1 -0
  106. data/lib/puppet/ffi/windows/api_types.rb +1 -0
  107. data/lib/puppet/ffi/windows/constants.rb +78 -77
  108. data/lib/puppet/ffi/windows/functions.rb +73 -73
  109. data/lib/puppet/ffi/windows/structs.rb +3 -3
  110. data/lib/puppet/ffi/windows.rb +1 -0
  111. data/lib/puppet/file_bucket/dipper.rb +7 -1
  112. data/lib/puppet/file_bucket/file.rb +1 -0
  113. data/lib/puppet/file_bucket.rb +1 -0
  114. data/lib/puppet/file_serving/base.rb +13 -6
  115. data/lib/puppet/file_serving/configuration/parser.rb +3 -1
  116. data/lib/puppet/file_serving/configuration.rb +5 -3
  117. data/lib/puppet/file_serving/content.rb +1 -0
  118. data/lib/puppet/file_serving/fileset.rb +9 -6
  119. data/lib/puppet/file_serving/http_metadata.rb +1 -3
  120. data/lib/puppet/file_serving/metadata.rb +9 -10
  121. data/lib/puppet/file_serving/mount/file.rb +6 -3
  122. data/lib/puppet/file_serving/mount/locales.rb +2 -1
  123. data/lib/puppet/file_serving/mount/modules.rb +2 -0
  124. data/lib/puppet/file_serving/mount/pluginfacts.rb +2 -1
  125. data/lib/puppet/file_serving/mount/plugins.rb +2 -1
  126. data/lib/puppet/file_serving/mount/scripts.rb +2 -0
  127. data/lib/puppet/file_serving/mount/tasks.rb +2 -0
  128. data/lib/puppet/file_serving/mount.rb +2 -0
  129. data/lib/puppet/file_serving/terminus_helper.rb +1 -0
  130. data/lib/puppet/file_serving/terminus_selector.rb +1 -0
  131. data/lib/puppet/file_serving.rb +1 -0
  132. data/lib/puppet/file_system/file_impl.rb +2 -2
  133. data/lib/puppet/file_system/jruby.rb +1 -0
  134. data/lib/puppet/file_system/memory_file.rb +2 -0
  135. data/lib/puppet/file_system/memory_impl.rb +3 -0
  136. data/lib/puppet/file_system/path_pattern.rb +1 -0
  137. data/lib/puppet/file_system/posix.rb +5 -1
  138. data/lib/puppet/file_system/uniquefile.rb +11 -11
  139. data/lib/puppet/file_system/windows.rb +4 -2
  140. data/lib/puppet/file_system.rb +3 -2
  141. data/lib/puppet/forge/cache.rb +1 -1
  142. data/lib/puppet/forge/errors.rb +1 -3
  143. data/lib/puppet/forge/repository.rb +2 -0
  144. data/lib/puppet/forge.rb +3 -0
  145. data/lib/puppet/functions/abs.rb +2 -1
  146. data/lib/puppet/functions/alert.rb +1 -0
  147. data/lib/puppet/functions/all.rb +1 -0
  148. data/lib/puppet/functions/annotate.rb +1 -0
  149. data/lib/puppet/functions/any.rb +1 -0
  150. data/lib/puppet/functions/assert_type.rb +1 -0
  151. data/lib/puppet/functions/binary_file.rb +3 -1
  152. data/lib/puppet/functions/break.rb +2 -1
  153. data/lib/puppet/functions/call.rb +1 -1
  154. data/lib/puppet/functions/camelcase.rb +1 -1
  155. data/lib/puppet/functions/capitalize.rb +1 -1
  156. data/lib/puppet/functions/ceiling.rb +2 -2
  157. data/lib/puppet/functions/chomp.rb +1 -1
  158. data/lib/puppet/functions/chop.rb +1 -1
  159. data/lib/puppet/functions/compare.rb +1 -0
  160. data/lib/puppet/functions/contain.rb +1 -0
  161. data/lib/puppet/functions/convert_to.rb +1 -0
  162. data/lib/puppet/functions/crit.rb +1 -0
  163. data/lib/puppet/functions/debug.rb +1 -0
  164. data/lib/puppet/functions/defined.rb +7 -4
  165. data/lib/puppet/functions/dig.rb +10 -8
  166. data/lib/puppet/functions/downcase.rb +1 -0
  167. data/lib/puppet/functions/each.rb +1 -0
  168. data/lib/puppet/functions/emerg.rb +1 -0
  169. data/lib/puppet/functions/empty.rb +1 -0
  170. data/lib/puppet/functions/epp.rb +1 -1
  171. data/lib/puppet/functions/err.rb +1 -0
  172. data/lib/puppet/functions/eyaml_lookup_key.rb +6 -4
  173. data/lib/puppet/functions/filter.rb +1 -0
  174. data/lib/puppet/functions/find_file.rb +1 -0
  175. data/lib/puppet/functions/find_template.rb +1 -0
  176. data/lib/puppet/functions/flatten.rb +1 -0
  177. data/lib/puppet/functions/floor.rb +2 -2
  178. data/lib/puppet/functions/get.rb +2 -1
  179. data/lib/puppet/functions/getvar.rb +2 -1
  180. data/lib/puppet/functions/hiera.rb +1 -0
  181. data/lib/puppet/functions/hiera_array.rb +1 -0
  182. data/lib/puppet/functions/hiera_hash.rb +1 -0
  183. data/lib/puppet/functions/hiera_include.rb +2 -0
  184. data/lib/puppet/functions/hocon_data.rb +1 -0
  185. data/lib/puppet/functions/import.rb +1 -0
  186. data/lib/puppet/functions/include.rb +1 -0
  187. data/lib/puppet/functions/index.rb +2 -2
  188. data/lib/puppet/functions/info.rb +1 -0
  189. data/lib/puppet/functions/inline_epp.rb +1 -1
  190. data/lib/puppet/functions/join.rb +2 -1
  191. data/lib/puppet/functions/json_data.rb +1 -0
  192. data/lib/puppet/functions/keys.rb +1 -0
  193. data/lib/puppet/functions/length.rb +1 -1
  194. data/lib/puppet/functions/lest.rb +1 -0
  195. data/lib/puppet/functions/lookup.rb +8 -9
  196. data/lib/puppet/functions/lstrip.rb +1 -1
  197. data/lib/puppet/functions/map.rb +1 -0
  198. data/lib/puppet/functions/match.rb +3 -1
  199. data/lib/puppet/functions/max.rb +4 -4
  200. data/lib/puppet/functions/min.rb +4 -4
  201. data/lib/puppet/functions/module_directory.rb +1 -0
  202. data/lib/puppet/functions/new.rb +2 -1
  203. data/lib/puppet/functions/next.rb +1 -0
  204. data/lib/puppet/functions/notice.rb +1 -0
  205. data/lib/puppet/functions/reduce.rb +1 -1
  206. data/lib/puppet/functions/regsubst.rb +1 -0
  207. data/lib/puppet/functions/require.rb +2 -0
  208. data/lib/puppet/functions/return.rb +1 -0
  209. data/lib/puppet/functions/reverse_each.rb +1 -0
  210. data/lib/puppet/functions/round.rb +1 -0
  211. data/lib/puppet/functions/rstrip.rb +1 -1
  212. data/lib/puppet/functions/scanf.rb +1 -0
  213. data/lib/puppet/functions/size.rb +1 -2
  214. data/lib/puppet/functions/slice.rb +2 -0
  215. data/lib/puppet/functions/sort.rb +1 -0
  216. data/lib/puppet/functions/split.rb +1 -0
  217. data/lib/puppet/functions/step.rb +1 -0
  218. data/lib/puppet/functions/strftime.rb +3 -2
  219. data/lib/puppet/functions/strip.rb +1 -1
  220. data/lib/puppet/functions/then.rb +2 -0
  221. data/lib/puppet/functions/tree_each.rb +1 -1
  222. data/lib/puppet/functions/type.rb +1 -0
  223. data/lib/puppet/functions/unique.rb +2 -1
  224. data/lib/puppet/functions/unwrap.rb +1 -0
  225. data/lib/puppet/functions/upcase.rb +1 -0
  226. data/lib/puppet/functions/values.rb +1 -0
  227. data/lib/puppet/functions/versioncmp.rb +2 -2
  228. data/lib/puppet/functions/warning.rb +1 -0
  229. data/lib/puppet/functions/with.rb +1 -0
  230. data/lib/puppet/functions/yaml_data.rb +1 -0
  231. data/lib/puppet/functions.rb +9 -9
  232. data/lib/puppet/generate/models/type/property.rb +2 -0
  233. data/lib/puppet/generate/models/type/type.rb +2 -0
  234. data/lib/puppet/generate/type.rb +6 -1
  235. data/lib/puppet/gettext/config.rb +6 -0
  236. data/lib/puppet/gettext/module_translations.rb +1 -1
  237. data/lib/puppet/gettext/stubs.rb +1 -0
  238. data/lib/puppet/graph/key.rb +1 -0
  239. data/lib/puppet/graph/prioritizer.rb +1 -0
  240. data/lib/puppet/graph/rb_tree_map.rb +12 -2
  241. data/lib/puppet/graph/relationship_graph.rb +3 -2
  242. data/lib/puppet/graph/sequential_prioritizer.rb +1 -0
  243. data/lib/puppet/graph/simple_graph.rb +38 -31
  244. data/lib/puppet/graph.rb +1 -0
  245. data/lib/puppet/http/client.rb +4 -1
  246. data/lib/puppet/http/dns.rb +5 -5
  247. data/lib/puppet/http/errors.rb +1 -0
  248. data/lib/puppet/http/external_client.rb +2 -2
  249. data/lib/puppet/http/factory.rb +1 -0
  250. data/lib/puppet/http/pool.rb +2 -1
  251. data/lib/puppet/http/pool_entry.rb +1 -0
  252. data/lib/puppet/http/proxy.rb +3 -2
  253. data/lib/puppet/http/redirector.rb +1 -0
  254. data/lib/puppet/http/resolver/server_list.rb +1 -1
  255. data/lib/puppet/http/resolver/settings.rb +1 -1
  256. data/lib/puppet/http/resolver/srv.rb +1 -1
  257. data/lib/puppet/http/resolver.rb +1 -0
  258. data/lib/puppet/http/response.rb +1 -0
  259. data/lib/puppet/http/response_converter.rb +1 -0
  260. data/lib/puppet/http/response_net_http.rb +1 -1
  261. data/lib/puppet/http/retry_after_handler.rb +1 -1
  262. data/lib/puppet/http/service/ca.rb +1 -0
  263. data/lib/puppet/http/service/compiler.rb +9 -3
  264. data/lib/puppet/http/service/file_server.rb +2 -1
  265. data/lib/puppet/http/service/puppetserver.rb +1 -1
  266. data/lib/puppet/http/service/report.rb +1 -1
  267. data/lib/puppet/http/service.rb +1 -0
  268. data/lib/puppet/http/session.rb +2 -1
  269. data/lib/puppet/http/site.rb +1 -0
  270. data/lib/puppet/http.rb +1 -0
  271. data/lib/puppet/indirector/catalog/compiler.rb +50 -40
  272. data/lib/puppet/indirector/catalog/json.rb +1 -0
  273. data/lib/puppet/indirector/catalog/msgpack.rb +1 -0
  274. data/lib/puppet/indirector/catalog/rest.rb +9 -0
  275. data/lib/puppet/indirector/catalog/store_configs.rb +1 -2
  276. data/lib/puppet/indirector/catalog/yaml.rb +1 -0
  277. data/lib/puppet/indirector/code.rb +1 -0
  278. data/lib/puppet/indirector/data_binding/hiera.rb +1 -0
  279. data/lib/puppet/indirector/data_binding/none.rb +1 -0
  280. data/lib/puppet/indirector/direct_file_server.rb +3 -1
  281. data/lib/puppet/indirector/envelope.rb +1 -0
  282. data/lib/puppet/indirector/errors.rb +1 -0
  283. data/lib/puppet/indirector/exec.rb +1 -0
  284. data/lib/puppet/indirector/face.rb +7 -6
  285. data/lib/puppet/indirector/fact_search.rb +1 -0
  286. data/lib/puppet/indirector/facts/facter.rb +2 -0
  287. data/lib/puppet/indirector/facts/json.rb +1 -0
  288. data/lib/puppet/indirector/facts/memory.rb +1 -0
  289. data/lib/puppet/indirector/facts/network_device.rb +1 -0
  290. data/lib/puppet/indirector/facts/rest.rb +1 -0
  291. data/lib/puppet/indirector/facts/store_configs.rb +1 -1
  292. data/lib/puppet/indirector/facts/yaml.rb +1 -0
  293. data/lib/puppet/indirector/file_bucket_file/file.rb +10 -5
  294. data/lib/puppet/indirector/file_bucket_file/rest.rb +2 -0
  295. data/lib/puppet/indirector/file_bucket_file/selector.rb +1 -0
  296. data/lib/puppet/indirector/file_content/file.rb +1 -0
  297. data/lib/puppet/indirector/file_content/file_server.rb +1 -0
  298. data/lib/puppet/indirector/file_content/rest.rb +1 -0
  299. data/lib/puppet/indirector/file_content/selector.rb +1 -0
  300. data/lib/puppet/indirector/file_content.rb +1 -0
  301. data/lib/puppet/indirector/file_metadata/file.rb +1 -0
  302. data/lib/puppet/indirector/file_metadata/file_server.rb +1 -0
  303. data/lib/puppet/indirector/file_metadata/http.rb +1 -0
  304. data/lib/puppet/indirector/file_metadata/rest.rb +1 -0
  305. data/lib/puppet/indirector/file_metadata/selector.rb +1 -0
  306. data/lib/puppet/indirector/file_metadata.rb +1 -0
  307. data/lib/puppet/indirector/file_server.rb +2 -0
  308. data/lib/puppet/indirector/generic_http.rb +1 -0
  309. data/lib/puppet/indirector/hiera.rb +5 -4
  310. data/lib/puppet/indirector/indirection.rb +11 -1
  311. data/lib/puppet/indirector/json.rb +3 -1
  312. data/lib/puppet/indirector/memory.rb +2 -0
  313. data/lib/puppet/indirector/msgpack.rb +5 -2
  314. data/lib/puppet/indirector/node/exec.rb +3 -2
  315. data/lib/puppet/indirector/node/json.rb +1 -1
  316. data/lib/puppet/indirector/node/memory.rb +1 -0
  317. data/lib/puppet/indirector/node/msgpack.rb +1 -0
  318. data/lib/puppet/indirector/node/plain.rb +1 -0
  319. data/lib/puppet/indirector/node/rest.rb +1 -0
  320. data/lib/puppet/indirector/node/store_configs.rb +1 -2
  321. data/lib/puppet/indirector/node/yaml.rb +1 -0
  322. data/lib/puppet/indirector/none.rb +1 -0
  323. data/lib/puppet/indirector/plain.rb +1 -0
  324. data/lib/puppet/indirector/report/json.rb +1 -0
  325. data/lib/puppet/indirector/report/msgpack.rb +1 -0
  326. data/lib/puppet/indirector/report/processor.rb +2 -0
  327. data/lib/puppet/indirector/report/rest.rb +1 -0
  328. data/lib/puppet/indirector/report/yaml.rb +1 -0
  329. data/lib/puppet/indirector/request.rb +7 -5
  330. data/lib/puppet/indirector/resource/ral.rb +1 -0
  331. data/lib/puppet/indirector/resource/store_configs.rb +1 -0
  332. data/lib/puppet/indirector/resource/validator.rb +1 -0
  333. data/lib/puppet/indirector/rest.rb +1 -0
  334. data/lib/puppet/indirector/store_configs.rb +1 -0
  335. data/lib/puppet/indirector/terminus.rb +4 -1
  336. data/lib/puppet/indirector/yaml.rb +1 -0
  337. data/lib/puppet/indirector.rb +2 -0
  338. data/lib/puppet/info_service/class_information_service.rb +5 -3
  339. data/lib/puppet/info_service/plan_information_service.rb +1 -0
  340. data/lib/puppet/info_service/task_information_service.rb +1 -0
  341. data/lib/puppet/interface/action.rb +32 -27
  342. data/lib/puppet/interface/action_builder.rb +14 -14
  343. data/lib/puppet/interface/action_manager.rb +2 -0
  344. data/lib/puppet/interface/documentation.rb +21 -15
  345. data/lib/puppet/interface/face_collection.rb +5 -2
  346. data/lib/puppet/interface/option.rb +15 -4
  347. data/lib/puppet/interface/option_builder.rb +13 -9
  348. data/lib/puppet/interface/option_manager.rb +3 -2
  349. data/lib/puppet/interface.rb +3 -3
  350. data/lib/puppet/loaders.rb +1 -1
  351. data/lib/puppet/metatype/manager.rb +9 -8
  352. data/lib/puppet/module/plan.rb +10 -4
  353. data/lib/puppet/module/task.rb +8 -2
  354. data/lib/puppet/module.rb +13 -3
  355. data/lib/puppet/module_tool/applications/application.rb +6 -4
  356. data/lib/puppet/module_tool/applications/checksummer.rb +1 -2
  357. data/lib/puppet/module_tool/applications/installer.rb +32 -45
  358. data/lib/puppet/module_tool/applications/uninstaller.rb +22 -21
  359. data/lib/puppet/module_tool/applications/unpacker.rb +3 -0
  360. data/lib/puppet/module_tool/applications/upgrader.rb +28 -26
  361. data/lib/puppet/module_tool/applications.rb +1 -0
  362. data/lib/puppet/module_tool/checksums.rb +1 -1
  363. data/lib/puppet/module_tool/contents_description.rb +1 -2
  364. data/lib/puppet/module_tool/dependency.rb +1 -1
  365. data/lib/puppet/module_tool/errors/base.rb +1 -0
  366. data/lib/puppet/module_tool/errors/installer.rb +4 -4
  367. data/lib/puppet/module_tool/errors/shared.rb +12 -12
  368. data/lib/puppet/module_tool/errors/uninstaller.rb +2 -2
  369. data/lib/puppet/module_tool/errors/upgrader.rb +3 -3
  370. data/lib/puppet/module_tool/errors.rb +1 -0
  371. data/lib/puppet/module_tool/install_directory.rb +6 -4
  372. data/lib/puppet/module_tool/installed_modules.rb +2 -0
  373. data/lib/puppet/module_tool/local_tarball.rb +3 -0
  374. data/lib/puppet/module_tool/metadata.rb +21 -20
  375. data/lib/puppet/module_tool/shared_behaviors.rb +23 -21
  376. data/lib/puppet/module_tool/tar/gnu.rb +1 -0
  377. data/lib/puppet/module_tool/tar/mini.rb +1 -0
  378. data/lib/puppet/module_tool/tar.rb +2 -1
  379. data/lib/puppet/module_tool.rb +1 -1
  380. data/lib/puppet/network/authconfig.rb +1 -0
  381. data/lib/puppet/network/authorization.rb +1 -0
  382. data/lib/puppet/network/client_request.rb +1 -0
  383. data/lib/puppet/network/format.rb +5 -0
  384. data/lib/puppet/network/format_handler.rb +2 -1
  385. data/lib/puppet/network/format_support.rb +6 -5
  386. data/lib/puppet/network/formats.rb +15 -11
  387. data/lib/puppet/network/http/api/indirected_routes.rb +8 -8
  388. data/lib/puppet/network/http/api/indirection_type.rb +1 -1
  389. data/lib/puppet/network/http/api/master/v3/environments.rb +1 -0
  390. data/lib/puppet/network/http/api/master/v3.rb +1 -0
  391. data/lib/puppet/network/http/api/master.rb +1 -0
  392. data/lib/puppet/network/http/api/server/v3/environments.rb +20 -14
  393. data/lib/puppet/network/http/api/server/v3.rb +13 -13
  394. data/lib/puppet/network/http/api/server.rb +1 -0
  395. data/lib/puppet/network/http/api.rb +11 -10
  396. data/lib/puppet/network/http/connection.rb +1 -0
  397. data/lib/puppet/network/http/error.rb +2 -1
  398. data/lib/puppet/network/http/handler.rb +3 -2
  399. data/lib/puppet/network/http/issues.rb +1 -0
  400. data/lib/puppet/network/http/memory_response.rb +1 -0
  401. data/lib/puppet/network/http/request.rb +13 -6
  402. data/lib/puppet/network/http/response.rb +1 -0
  403. data/lib/puppet/network/http/route.rb +4 -2
  404. data/lib/puppet/network/http.rb +1 -0
  405. data/lib/puppet/network/http_pool.rb +2 -1
  406. data/lib/puppet/network/uri.rb +1 -0
  407. data/lib/puppet/network.rb +1 -0
  408. data/lib/puppet/node/environment.rb +12 -9
  409. data/lib/puppet/node/facts.rb +2 -1
  410. data/lib/puppet/node.rb +3 -2
  411. data/lib/puppet/pal/catalog_compiler.rb +1 -3
  412. data/lib/puppet/pal/compiler.rb +6 -2
  413. data/lib/puppet/pal/function_signature.rb +2 -1
  414. data/lib/puppet/pal/json_catalog_encoder.rb +5 -1
  415. data/lib/puppet/pal/pal_api.rb +1 -0
  416. data/lib/puppet/pal/pal_impl.rb +20 -19
  417. data/lib/puppet/pal/plan_signature.rb +2 -1
  418. data/lib/puppet/pal/script_compiler.rb +3 -2
  419. data/lib/puppet/pal/task_signature.rb +14 -9
  420. data/lib/puppet/parameter/boolean.rb +1 -0
  421. data/lib/puppet/parameter/package_options.rb +1 -0
  422. data/lib/puppet/parameter/path.rb +3 -0
  423. data/lib/puppet/parameter/value.rb +1 -0
  424. data/lib/puppet/parameter/value_collection.rb +5 -5
  425. data/lib/puppet/parameter.rb +4 -3
  426. data/lib/puppet/parser/abstract_compiler.rb +0 -2
  427. data/lib/puppet/parser/ast/block_expression.rb +1 -0
  428. data/lib/puppet/parser/ast/branch.rb +1 -0
  429. data/lib/puppet/parser/ast/hostclass.rb +1 -0
  430. data/lib/puppet/parser/ast/leaf.rb +2 -0
  431. data/lib/puppet/parser/ast/node.rb +1 -0
  432. data/lib/puppet/parser/ast/pops_bridge.rb +6 -6
  433. data/lib/puppet/parser/ast/resource.rb +2 -3
  434. data/lib/puppet/parser/ast/resource_instance.rb +2 -0
  435. data/lib/puppet/parser/ast/resourceparam.rb +6 -5
  436. data/lib/puppet/parser/ast/top_level_construct.rb +1 -0
  437. data/lib/puppet/parser/ast.rb +4 -3
  438. data/lib/puppet/parser/catalog_compiler.rb +1 -2
  439. data/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +3 -0
  440. data/lib/puppet/parser/compiler/catalog_validator.rb +1 -0
  441. data/lib/puppet/parser/compiler.rb +10 -8
  442. data/lib/puppet/parser/e4_parser_adapter.rb +15 -15
  443. data/lib/puppet/parser/files.rb +1 -1
  444. data/lib/puppet/parser/functions/assert_type.rb +55 -54
  445. data/lib/puppet/parser/functions/binary_file.rb +19 -18
  446. data/lib/puppet/parser/functions/break.rb +35 -34
  447. data/lib/puppet/parser/functions/contain.rb +1 -0
  448. data/lib/puppet/parser/functions/create_resources.rb +8 -6
  449. data/lib/puppet/parser/functions/defined.rb +102 -101
  450. data/lib/puppet/parser/functions/dig.rb +33 -32
  451. data/lib/puppet/parser/functions/digest.rb +1 -0
  452. data/lib/puppet/parser/functions/each.rb +99 -98
  453. data/lib/puppet/parser/functions/epp.rb +2 -2
  454. data/lib/puppet/parser/functions/fail.rb +9 -8
  455. data/lib/puppet/parser/functions/file.rb +14 -13
  456. data/lib/puppet/parser/functions/filter.rb +74 -73
  457. data/lib/puppet/parser/functions/find_file.rb +22 -21
  458. data/lib/puppet/parser/functions/fqdn_rand.rb +23 -22
  459. data/lib/puppet/parser/functions/generate.rb +20 -20
  460. data/lib/puppet/parser/functions/hiera.rb +94 -93
  461. data/lib/puppet/parser/functions/hiera_array.rb +82 -81
  462. data/lib/puppet/parser/functions/hiera_hash.rb +92 -91
  463. data/lib/puppet/parser/functions/hiera_include.rb +92 -91
  464. data/lib/puppet/parser/functions/include.rb +2 -1
  465. data/lib/puppet/parser/functions/inline_epp.rb +2 -2
  466. data/lib/puppet/parser/functions/inline_template.rb +11 -11
  467. data/lib/puppet/parser/functions/lest.rb +44 -43
  468. data/lib/puppet/parser/functions/lookup.rb +131 -130
  469. data/lib/puppet/parser/functions/map.rb +71 -70
  470. data/lib/puppet/parser/functions/match.rb +39 -38
  471. data/lib/puppet/parser/functions/md5.rb +2 -1
  472. data/lib/puppet/parser/functions/new.rb +985 -984
  473. data/lib/puppet/parser/functions/next.rb +34 -33
  474. data/lib/puppet/parser/functions/realize.rb +9 -9
  475. data/lib/puppet/parser/functions/reduce.rb +132 -131
  476. data/lib/puppet/parser/functions/regsubst.rb +6 -5
  477. data/lib/puppet/parser/functions/require.rb +5 -4
  478. data/lib/puppet/parser/functions/return.rb +88 -87
  479. data/lib/puppet/parser/functions/reverse_each.rb +78 -77
  480. data/lib/puppet/parser/functions/scanf.rb +28 -27
  481. data/lib/puppet/parser/functions/sha1.rb +2 -1
  482. data/lib/puppet/parser/functions/sha256.rb +1 -0
  483. data/lib/puppet/parser/functions/shellquote.rb +1 -0
  484. data/lib/puppet/parser/functions/slice.rb +34 -33
  485. data/lib/puppet/parser/functions/split.rb +5 -6
  486. data/lib/puppet/parser/functions/sprintf.rb +3 -3
  487. data/lib/puppet/parser/functions/step.rb +79 -78
  488. data/lib/puppet/parser/functions/strftime.rb +180 -179
  489. data/lib/puppet/parser/functions/tag.rb +7 -6
  490. data/lib/puppet/parser/functions/tagged.rb +13 -12
  491. data/lib/puppet/parser/functions/template.rb +24 -23
  492. data/lib/puppet/parser/functions/then.rb +68 -67
  493. data/lib/puppet/parser/functions/type.rb +48 -47
  494. data/lib/puppet/parser/functions/versioncmp.rb +1 -1
  495. data/lib/puppet/parser/functions/with.rb +23 -22
  496. data/lib/puppet/parser/functions.rb +2 -0
  497. data/lib/puppet/parser/parser_factory.rb +1 -0
  498. data/lib/puppet/parser/relationship.rb +3 -0
  499. data/lib/puppet/parser/resource/param.rb +1 -0
  500. data/lib/puppet/parser/resource.rb +10 -4
  501. data/lib/puppet/parser/scope.rb +40 -32
  502. data/lib/puppet/parser/script_compiler.rb +5 -6
  503. data/lib/puppet/parser/templatewrapper.rb +1 -0
  504. data/lib/puppet/parser/type_loader.rb +19 -17
  505. data/lib/puppet/parser.rb +1 -0
  506. data/lib/puppet/plugins/configuration.rb +1 -0
  507. data/lib/puppet/plugins/syntax_checkers.rb +1 -1
  508. data/lib/puppet/plugins.rb +1 -0
  509. data/lib/puppet/pops/adaptable.rb +3 -1
  510. data/lib/puppet/pops/adapters.rb +3 -1
  511. data/lib/puppet/pops/evaluator/access_operator.rb +79 -65
  512. data/lib/puppet/pops/evaluator/callable_signature.rb +1 -1
  513. data/lib/puppet/pops/evaluator/closure.rb +273 -277
  514. data/lib/puppet/pops/evaluator/collector_transformer.rb +11 -9
  515. data/lib/puppet/pops/evaluator/collectors/abstract_collector.rb +1 -0
  516. data/lib/puppet/pops/evaluator/collectors/catalog_collector.rb +2 -2
  517. data/lib/puppet/pops/evaluator/collectors/exported_collector.rb +4 -4
  518. data/lib/puppet/pops/evaluator/collectors/fixed_set_collector.rb +1 -1
  519. data/lib/puppet/pops/evaluator/compare_operator.rb +15 -3
  520. data/lib/puppet/pops/evaluator/deferred_resolver.rb +2 -2
  521. data/lib/puppet/pops/evaluator/epp_evaluator.rb +10 -10
  522. data/lib/puppet/pops/evaluator/evaluator_impl.rb +140 -138
  523. data/lib/puppet/pops/evaluator/external_syntax_support.rb +1 -1
  524. data/lib/puppet/pops/evaluator/json_strict_literal_evaluator.rb +2 -1
  525. data/lib/puppet/pops/evaluator/literal_evaluator.rb +1 -1
  526. data/lib/puppet/pops/evaluator/puppet_proc.rb +2 -0
  527. data/lib/puppet/pops/evaluator/relationship_operator.rb +5 -3
  528. data/lib/puppet/pops/evaluator/runtime3_converter.rb +21 -19
  529. data/lib/puppet/pops/evaluator/runtime3_resource_support.rb +31 -33
  530. data/lib/puppet/pops/evaluator/runtime3_support.rb +16 -19
  531. data/lib/puppet/pops/functions/dispatch.rb +1 -0
  532. data/lib/puppet/pops/functions/dispatcher.rb +1 -1
  533. data/lib/puppet/pops/functions/function.rb +1 -2
  534. data/lib/puppet/pops/issue_reporter.rb +19 -17
  535. data/lib/puppet/pops/issues.rb +8 -4
  536. data/lib/puppet/pops/label_provider.rb +1 -0
  537. data/lib/puppet/pops/loader/base_loader.rb +2 -2
  538. data/lib/puppet/pops/loader/dependency_loader.rb +3 -0
  539. data/lib/puppet/pops/loader/gem_support.rb +3 -1
  540. data/lib/puppet/pops/loader/generic_plan_instantiator.rb +1 -0
  541. data/lib/puppet/pops/loader/loader.rb +1 -2
  542. data/lib/puppet/pops/loader/loader_paths.rb +20 -19
  543. data/lib/puppet/pops/loader/module_loaders.rb +28 -28
  544. data/lib/puppet/pops/loader/predefined_loader.rb +1 -2
  545. data/lib/puppet/pops/loader/puppet_function_instantiator.rb +4 -2
  546. data/lib/puppet/pops/loader/puppet_plan_instantiator.rb +4 -2
  547. data/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb +1 -1
  548. data/lib/puppet/pops/loader/ruby_data_type_instantiator.rb +4 -1
  549. data/lib/puppet/pops/loader/ruby_function_instantiator.rb +4 -1
  550. data/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +6 -2
  551. data/lib/puppet/pops/loader/runtime3_type_loader.rb +2 -2
  552. data/lib/puppet/pops/loader/simple_environment_loader.rb +1 -2
  553. data/lib/puppet/pops/loader/static_loader.rb +22 -21
  554. data/lib/puppet/pops/loader/task_instantiator.rb +1 -0
  555. data/lib/puppet/pops/loader/type_definition_instantiator.rb +6 -4
  556. data/lib/puppet/pops/loader/typed_name.rb +1 -0
  557. data/lib/puppet/pops/loader/uri_helper.rb +1 -0
  558. data/lib/puppet/pops/loaders.rb +21 -18
  559. data/lib/puppet/pops/lookup/configured_data_provider.rb +1 -0
  560. data/lib/puppet/pops/lookup/context.rb +24 -23
  561. data/lib/puppet/pops/lookup/data_adapter.rb +1 -0
  562. data/lib/puppet/pops/lookup/data_dig_function_provider.rb +2 -2
  563. data/lib/puppet/pops/lookup/data_hash_function_provider.rb +1 -0
  564. data/lib/puppet/pops/lookup/data_provider.rb +1 -0
  565. data/lib/puppet/pops/lookup/environment_data_provider.rb +1 -0
  566. data/lib/puppet/pops/lookup/explainer.rb +34 -33
  567. data/lib/puppet/pops/lookup/function_provider.rb +7 -6
  568. data/lib/puppet/pops/lookup/global_data_provider.rb +1 -1
  569. data/lib/puppet/pops/lookup/hiera_config.rb +136 -100
  570. data/lib/puppet/pops/lookup/interpolation.rb +5 -1
  571. data/lib/puppet/pops/lookup/invocation.rb +3 -0
  572. data/lib/puppet/pops/lookup/key_recorder.rb +3 -1
  573. data/lib/puppet/pops/lookup/location_resolver.rb +2 -1
  574. data/lib/puppet/pops/lookup/lookup_adapter.rb +22 -20
  575. data/lib/puppet/pops/lookup/lookup_key.rb +1 -0
  576. data/lib/puppet/pops/lookup/lookup_key_function_provider.rb +1 -0
  577. data/lib/puppet/pops/lookup/module_data_provider.rb +3 -1
  578. data/lib/puppet/pops/lookup/sub_lookup.rb +5 -2
  579. data/lib/puppet/pops/lookup.rb +13 -8
  580. data/lib/puppet/pops/merge_strategy.rb +5 -2
  581. data/lib/puppet/pops/migration/migration_checker.rb +3 -1
  582. data/lib/puppet/pops/model/ast.rb +786 -685
  583. data/lib/puppet/pops/model/ast_transformer.rb +4 -3
  584. data/lib/puppet/pops/model/factory.rb +17 -13
  585. data/lib/puppet/pops/model/model_label_provider.rb +1 -1
  586. data/lib/puppet/pops/model/model_tree_dumper.rb +10 -9
  587. data/lib/puppet/pops/model/pn_transformer.rb +4 -6
  588. data/lib/puppet/pops/model/tree_dumper.rb +2 -0
  589. data/lib/puppet/pops/parser/code_merger.rb +0 -1
  590. data/lib/puppet/pops/parser/epp_parser.rb +1 -1
  591. data/lib/puppet/pops/parser/epp_support.rb +2 -2
  592. data/lib/puppet/pops/parser/evaluating_parser.rb +5 -2
  593. data/lib/puppet/pops/parser/heredoc_support.rb +6 -7
  594. data/lib/puppet/pops/parser/interpolation_support.rb +2 -3
  595. data/lib/puppet/pops/parser/lexer2.rb +32 -29
  596. data/lib/puppet/pops/parser/lexer_support.rb +38 -41
  597. data/lib/puppet/pops/parser/locatable.rb +1 -2
  598. data/lib/puppet/pops/parser/locator.rb +31 -28
  599. data/lib/puppet/pops/parser/parser_support.rb +2 -0
  600. data/lib/puppet/pops/parser/pn_parser.rb +1 -1
  601. data/lib/puppet/pops/parser/slurp_support.rb +33 -32
  602. data/lib/puppet/pops/patterns.rb +2 -3
  603. data/lib/puppet/pops/pcore.rb +2 -2
  604. data/lib/puppet/pops/pn.rb +3 -0
  605. data/lib/puppet/pops/puppet_stack.rb +1 -0
  606. data/lib/puppet/pops/resource/param.rb +11 -10
  607. data/lib/puppet/pops/resource/resource_type_impl.rb +37 -36
  608. data/lib/puppet/pops/semantic_error.rb +1 -0
  609. data/lib/puppet/pops/serialization/abstract_reader.rb +3 -2
  610. data/lib/puppet/pops/serialization/abstract_writer.rb +5 -4
  611. data/lib/puppet/pops/serialization/deserializer.rb +2 -0
  612. data/lib/puppet/pops/serialization/extension.rb +7 -0
  613. data/lib/puppet/pops/serialization/from_data_converter.rb +3 -0
  614. data/lib/puppet/pops/serialization/instance_reader.rb +1 -0
  615. data/lib/puppet/pops/serialization/instance_writer.rb +1 -0
  616. data/lib/puppet/pops/serialization/json.rb +6 -3
  617. data/lib/puppet/pops/serialization/json_path.rb +1 -0
  618. data/lib/puppet/pops/serialization/object.rb +4 -1
  619. data/lib/puppet/pops/serialization/serializer.rb +6 -2
  620. data/lib/puppet/pops/serialization/time_factory.rb +1 -1
  621. data/lib/puppet/pops/serialization/to_data_converter.rb +4 -2
  622. data/lib/puppet/pops/serialization/to_stringified_converter.rb +2 -2
  623. data/lib/puppet/pops/serialization.rb +1 -0
  624. data/lib/puppet/pops/time/timespan.rb +12 -2
  625. data/lib/puppet/pops/time/timestamp.rb +4 -0
  626. data/lib/puppet/pops/types/annotatable.rb +1 -1
  627. data/lib/puppet/pops/types/annotation.rb +1 -0
  628. data/lib/puppet/pops/types/class_loader.rb +8 -6
  629. data/lib/puppet/pops/types/implementation_registry.rb +1 -0
  630. data/lib/puppet/pops/types/iterable.rb +18 -9
  631. data/lib/puppet/pops/types/p_binary_type.rb +2 -3
  632. data/lib/puppet/pops/types/p_init_type.rb +12 -9
  633. data/lib/puppet/pops/types/p_meta_type.rb +1 -1
  634. data/lib/puppet/pops/types/p_object_type.rb +65 -42
  635. data/lib/puppet/pops/types/p_object_type_extension.rb +10 -7
  636. data/lib/puppet/pops/types/p_runtime_type.rb +11 -9
  637. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +1 -1
  638. data/lib/puppet/pops/types/p_sem_ver_type.rb +5 -5
  639. data/lib/puppet/pops/types/p_sensitive_type.rb +1 -4
  640. data/lib/puppet/pops/types/p_timespan_type.rb +4 -2
  641. data/lib/puppet/pops/types/p_timestamp_type.rb +3 -2
  642. data/lib/puppet/pops/types/p_type_set_type.rb +36 -28
  643. data/lib/puppet/pops/types/p_uri_type.rb +25 -18
  644. data/lib/puppet/pops/types/puppet_object.rb +1 -1
  645. data/lib/puppet/pops/types/recursion_guard.rb +7 -2
  646. data/lib/puppet/pops/types/ruby_generator.rb +7 -4
  647. data/lib/puppet/pops/types/ruby_method.rb +6 -5
  648. data/lib/puppet/pops/types/string_converter.rb +65 -57
  649. data/lib/puppet/pops/types/tree_iterators.rb +6 -7
  650. data/lib/puppet/pops/types/type_acceptor.rb +1 -0
  651. data/lib/puppet/pops/types/type_asserter.rb +1 -0
  652. data/lib/puppet/pops/types/type_assertion_error.rb +0 -1
  653. data/lib/puppet/pops/types/type_calculator.rb +10 -4
  654. data/lib/puppet/pops/types/type_conversion_error.rb +1 -10
  655. data/lib/puppet/pops/types/type_factory.rb +7 -4
  656. data/lib/puppet/pops/types/type_formatter.rb +12 -11
  657. data/lib/puppet/pops/types/type_mismatch_describer.rb +13 -8
  658. data/lib/puppet/pops/types/type_parser.rb +111 -107
  659. data/lib/puppet/pops/types/type_set_reference.rb +2 -0
  660. data/lib/puppet/pops/types/type_with_members.rb +1 -1
  661. data/lib/puppet/pops/types/types.rb +177 -152
  662. data/lib/puppet/pops/utils.rb +1 -0
  663. data/lib/puppet/pops/validation/checker4_0.rb +17 -11
  664. data/lib/puppet/pops/validation/tasks_checker.rb +2 -1
  665. data/lib/puppet/pops/validation/validator_factory_4_0.rb +1 -2
  666. data/lib/puppet/pops/validation.rb +8 -6
  667. data/lib/puppet/pops/visitable.rb +1 -0
  668. data/lib/puppet/pops/visitor.rb +14 -1
  669. data/lib/puppet/pops.rb +2 -0
  670. data/lib/puppet/property/boolean.rb +1 -0
  671. data/lib/puppet/property/ensure.rb +4 -1
  672. data/lib/puppet/property/keyvalue.rb +5 -4
  673. data/lib/puppet/property/list.rb +5 -5
  674. data/lib/puppet/property/ordered_list.rb +4 -4
  675. data/lib/puppet/property.rb +13 -11
  676. data/lib/puppet/provider/aix_object.rb +5 -0
  677. data/lib/puppet/provider/command.rb +1 -0
  678. data/lib/puppet/provider/confine.rb +1 -0
  679. data/lib/puppet/provider/exec/posix.rb +2 -0
  680. data/lib/puppet/provider/exec/shell.rb +1 -0
  681. data/lib/puppet/provider/exec/windows.rb +2 -1
  682. data/lib/puppet/provider/exec.rb +1 -0
  683. data/lib/puppet/provider/file/posix.rb +1 -0
  684. data/lib/puppet/provider/file/windows.rb +10 -6
  685. data/lib/puppet/provider/group/aix.rb +1 -0
  686. data/lib/puppet/provider/group/directoryservice.rb +1 -1
  687. data/lib/puppet/provider/group/groupadd.rb +9 -4
  688. data/lib/puppet/provider/group/ldap.rb +2 -0
  689. data/lib/puppet/provider/group/pw.rb +1 -0
  690. data/lib/puppet/provider/group/windows_adsi.rb +2 -0
  691. data/lib/puppet/provider/ldap.rb +2 -0
  692. data/lib/puppet/provider/nameservice/directoryservice.rb +28 -19
  693. data/lib/puppet/provider/nameservice/objectadd.rb +1 -0
  694. data/lib/puppet/provider/nameservice/pw.rb +6 -5
  695. data/lib/puppet/provider/nameservice.rb +8 -4
  696. data/lib/puppet/provider/network_device.rb +1 -2
  697. data/lib/puppet/provider/package/aix.rb +5 -4
  698. data/lib/puppet/provider/package/appdmg.rb +20 -19
  699. data/lib/puppet/provider/package/apple.rb +3 -2
  700. data/lib/puppet/provider/package/apt.rb +4 -4
  701. data/lib/puppet/provider/package/aptitude.rb +1 -0
  702. data/lib/puppet/provider/package/aptrpm.rb +2 -1
  703. data/lib/puppet/provider/package/blastwave.rb +6 -6
  704. data/lib/puppet/provider/package/dnf.rb +2 -0
  705. data/lib/puppet/provider/package/dnfmodule.rb +8 -7
  706. data/lib/puppet/provider/package/dpkg.rb +4 -4
  707. data/lib/puppet/provider/package/fink.rb +2 -1
  708. data/lib/puppet/provider/package/freebsd.rb +3 -2
  709. data/lib/puppet/provider/package/gem.rb +9 -5
  710. data/lib/puppet/provider/package/hpux.rb +4 -3
  711. data/lib/puppet/provider/package/macports.rb +2 -1
  712. data/lib/puppet/provider/package/nim.rb +13 -15
  713. data/lib/puppet/provider/package/openbsd.rb +6 -4
  714. data/lib/puppet/provider/package/opkg.rb +2 -0
  715. data/lib/puppet/provider/package/pacman.rb +12 -12
  716. data/lib/puppet/provider/package/pip.rb +3 -1
  717. data/lib/puppet/provider/package/pip2.rb +2 -2
  718. data/lib/puppet/provider/package/pip3.rb +2 -2
  719. data/lib/puppet/provider/package/pkg.rb +17 -13
  720. data/lib/puppet/provider/package/pkgdmg.rb +7 -2
  721. data/lib/puppet/provider/package/pkgin.rb +5 -5
  722. data/lib/puppet/provider/package/pkgng.rb +11 -7
  723. data/lib/puppet/provider/package/pkgutil.rb +7 -6
  724. data/lib/puppet/provider/package/portage.rb +11 -6
  725. data/lib/puppet/provider/package/ports.rb +6 -5
  726. data/lib/puppet/provider/package/portupgrade.rb +6 -12
  727. data/lib/puppet/provider/package/puppet_gem.rb +1 -0
  728. data/lib/puppet/provider/package/puppetserver_gem.rb +1 -0
  729. data/lib/puppet/provider/package/rpm.rb +10 -6
  730. data/lib/puppet/provider/package/rug.rb +2 -1
  731. data/lib/puppet/provider/package/sun.rb +20 -17
  732. data/lib/puppet/provider/package/sunfreeware.rb +1 -0
  733. data/lib/puppet/provider/package/tdnf.rb +1 -0
  734. data/lib/puppet/provider/package/up2date.rb +2 -1
  735. data/lib/puppet/provider/package/urpmi.rb +1 -0
  736. data/lib/puppet/provider/package/windows/exe_package.rb +1 -0
  737. data/lib/puppet/provider/package/windows/msi_package.rb +1 -0
  738. data/lib/puppet/provider/package/windows/package.rb +5 -3
  739. data/lib/puppet/provider/package/windows.rb +4 -2
  740. data/lib/puppet/provider/package/yum.rb +16 -13
  741. data/lib/puppet/provider/package/zypper.rb +15 -14
  742. data/lib/puppet/provider/package.rb +7 -6
  743. data/lib/puppet/provider/package_targetable.rb +1 -0
  744. data/lib/puppet/provider/parsedfile.rb +7 -2
  745. data/lib/puppet/provider/service/base.rb +2 -1
  746. data/lib/puppet/provider/service/bsd.rb +1 -0
  747. data/lib/puppet/provider/service/daemontools.rb +9 -7
  748. data/lib/puppet/provider/service/debian.rb +4 -3
  749. data/lib/puppet/provider/service/freebsd.rb +5 -6
  750. data/lib/puppet/provider/service/gentoo.rb +5 -4
  751. data/lib/puppet/provider/service/init.rb +10 -11
  752. data/lib/puppet/provider/service/launchd.rb +10 -4
  753. data/lib/puppet/provider/service/openbsd.rb +4 -4
  754. data/lib/puppet/provider/service/openrc.rb +1 -1
  755. data/lib/puppet/provider/service/openwrt.rb +1 -1
  756. data/lib/puppet/provider/service/rcng.rb +1 -0
  757. data/lib/puppet/provider/service/redhat.rb +3 -2
  758. data/lib/puppet/provider/service/runit.rb +8 -7
  759. data/lib/puppet/provider/service/service.rb +1 -0
  760. data/lib/puppet/provider/service/smf.rb +5 -2
  761. data/lib/puppet/provider/service/src.rb +16 -16
  762. data/lib/puppet/provider/service/systemd.rb +8 -4
  763. data/lib/puppet/provider/service/upstart.rb +8 -7
  764. data/lib/puppet/provider/service/windows.rb +22 -26
  765. data/lib/puppet/provider/user/aix.rb +3 -2
  766. data/lib/puppet/provider/user/directoryservice.rb +52 -44
  767. data/lib/puppet/provider/user/hpux.rb +15 -14
  768. data/lib/puppet/provider/user/ldap.rb +8 -6
  769. data/lib/puppet/provider/user/openbsd.rb +21 -20
  770. data/lib/puppet/provider/user/pw.rb +3 -2
  771. data/lib/puppet/provider/user/user_role_add.rb +19 -14
  772. data/lib/puppet/provider/user/useradd.rb +51 -41
  773. data/lib/puppet/provider/user/windows_adsi.rb +4 -1
  774. data/lib/puppet/provider.rb +9 -9
  775. data/lib/puppet/reference/configuration.rb +43 -42
  776. data/lib/puppet/reference/function.rb +1 -0
  777. data/lib/puppet/reference/indirection.rb +42 -41
  778. data/lib/puppet/reference/metaparameter.rb +1 -0
  779. data/lib/puppet/reference/providers.rb +2 -0
  780. data/lib/puppet/reference/report.rb +1 -0
  781. data/lib/puppet/reference/type.rb +4 -3
  782. data/lib/puppet/relationship.rb +3 -2
  783. data/lib/puppet/reports/http.rb +1 -1
  784. data/lib/puppet/reports/log.rb +1 -0
  785. data/lib/puppet/reports/store.rb +3 -1
  786. data/lib/puppet/reports.rb +4 -3
  787. data/lib/puppet/resource/catalog.rb +14 -10
  788. data/lib/puppet/resource/status.rb +1 -1
  789. data/lib/puppet/resource/type.rb +28 -18
  790. data/lib/puppet/resource/type_collection.rb +4 -0
  791. data/lib/puppet/resource.rb +24 -16
  792. data/lib/puppet/runtime.rb +1 -0
  793. data/lib/puppet/scheduler/job.rb +1 -0
  794. data/lib/puppet/scheduler/scheduler.rb +1 -0
  795. data/lib/puppet/scheduler/splay_job.rb +1 -0
  796. data/lib/puppet/scheduler/timer.rb +1 -0
  797. data/lib/puppet/scheduler.rb +1 -0
  798. data/lib/puppet/settings/alias_setting.rb +1 -0
  799. data/lib/puppet/settings/array_setting.rb +1 -1
  800. data/lib/puppet/settings/autosign_setting.rb +1 -1
  801. data/lib/puppet/settings/base_setting.rb +9 -5
  802. data/lib/puppet/settings/boolean_setting.rb +1 -0
  803. data/lib/puppet/settings/certificate_revocation_setting.rb +1 -1
  804. data/lib/puppet/settings/config_file.rb +3 -3
  805. data/lib/puppet/settings/directory_setting.rb +1 -0
  806. data/lib/puppet/settings/duration_setting.rb +1 -0
  807. data/lib/puppet/settings/enum_setting.rb +2 -1
  808. data/lib/puppet/settings/environment_conf.rb +9 -8
  809. data/lib/puppet/settings/errors.rb +2 -0
  810. data/lib/puppet/settings/file_or_directory_setting.rb +1 -5
  811. data/lib/puppet/settings/file_setting.rb +3 -13
  812. data/lib/puppet/settings/http_extra_headers_setting.rb +1 -1
  813. data/lib/puppet/settings/ini_file.rb +1 -0
  814. data/lib/puppet/settings/integer_setting.rb +1 -0
  815. data/lib/puppet/settings/path_setting.rb +1 -0
  816. data/lib/puppet/settings/port_setting.rb +2 -1
  817. data/lib/puppet/settings/priority_setting.rb +9 -8
  818. data/lib/puppet/settings/server_list_setting.rb +2 -2
  819. data/lib/puppet/settings/string_setting.rb +1 -0
  820. data/lib/puppet/settings/symbolic_enum_setting.rb +2 -1
  821. data/lib/puppet/settings/terminus_setting.rb +1 -0
  822. data/lib/puppet/settings/ttl_setting.rb +2 -0
  823. data/lib/puppet/settings/value_translator.rb +8 -7
  824. data/lib/puppet/settings.rb +89 -66
  825. data/lib/puppet/ssl/base.rb +4 -0
  826. data/lib/puppet/ssl/certificate.rb +3 -2
  827. data/lib/puppet/ssl/certificate_request.rb +9 -7
  828. data/lib/puppet/ssl/certificate_request_attributes.rb +3 -1
  829. data/lib/puppet/ssl/certificate_signer.rb +2 -3
  830. data/lib/puppet/ssl/digest.rb +1 -0
  831. data/lib/puppet/ssl/error.rb +2 -0
  832. data/lib/puppet/ssl/oids.rb +3 -3
  833. data/lib/puppet/ssl/openssl_loader.rb +1 -0
  834. data/lib/puppet/ssl/ssl_context.rb +11 -15
  835. data/lib/puppet/ssl/ssl_provider.rb +2 -1
  836. data/lib/puppet/ssl/state_machine.rb +1 -0
  837. data/lib/puppet/ssl/verifier.rb +2 -2
  838. data/lib/puppet/ssl.rb +1 -0
  839. data/lib/puppet/syntax_checkers/base64.rb +2 -1
  840. data/lib/puppet/syntax_checkers/epp.rb +1 -1
  841. data/lib/puppet/syntax_checkers/json.rb +1 -2
  842. data/lib/puppet/syntax_checkers/pp.rb +1 -1
  843. data/lib/puppet/syntax_checkers.rb +1 -0
  844. data/lib/puppet/test/test_helper.rb +16 -14
  845. data/lib/puppet/thread_local.rb +1 -0
  846. data/lib/puppet/transaction/additional_resource_generator.rb +5 -1
  847. data/lib/puppet/transaction/event.rb +5 -3
  848. data/lib/puppet/transaction/event_manager.rb +4 -3
  849. data/lib/puppet/transaction/persistence.rb +2 -1
  850. data/lib/puppet/transaction/report.rb +23 -15
  851. data/lib/puppet/transaction/resource_harness.rb +6 -3
  852. data/lib/puppet/transaction.rb +11 -6
  853. data/lib/puppet/trusted_external.rb +8 -4
  854. data/lib/puppet/type/component.rb +11 -5
  855. data/lib/puppet/type/exec.rb +26 -10
  856. data/lib/puppet/type/file/checksum.rb +1 -0
  857. data/lib/puppet/type/file/checksum_value.rb +3 -2
  858. data/lib/puppet/type/file/content.rb +16 -13
  859. data/lib/puppet/type/file/ctime.rb +2 -1
  860. data/lib/puppet/type/file/data_sync.rb +4 -2
  861. data/lib/puppet/type/file/ensure.rb +5 -5
  862. data/lib/puppet/type/file/group.rb +2 -1
  863. data/lib/puppet/type/file/mode.rb +4 -2
  864. data/lib/puppet/type/file/mtime.rb +2 -1
  865. data/lib/puppet/type/file/owner.rb +2 -1
  866. data/lib/puppet/type/file/selcontext.rb +2 -2
  867. data/lib/puppet/type/file/source.rb +12 -10
  868. data/lib/puppet/type/file/target.rb +2 -2
  869. data/lib/puppet/type/file/type.rb +2 -1
  870. data/lib/puppet/type/file.rb +22 -13
  871. data/lib/puppet/type/filebucket.rb +1 -0
  872. data/lib/puppet/type/group.rb +8 -8
  873. data/lib/puppet/type/notify.rb +1 -1
  874. data/lib/puppet/type/package.rb +21 -21
  875. data/lib/puppet/type/resources.rb +30 -25
  876. data/lib/puppet/type/schedule.rb +9 -10
  877. data/lib/puppet/type/service.rb +9 -7
  878. data/lib/puppet/type/stage.rb +1 -0
  879. data/lib/puppet/type/tidy.rb +9 -4
  880. data/lib/puppet/type/user.rb +28 -24
  881. data/lib/puppet/type/whit.rb +1 -1
  882. data/lib/puppet/type.rb +71 -61
  883. data/lib/puppet/util/at_fork/noop.rb +1 -0
  884. data/lib/puppet/util/at_fork/solaris.rb +2 -1
  885. data/lib/puppet/util/at_fork.rb +2 -1
  886. data/lib/puppet/util/autoload.rb +5 -0
  887. data/lib/puppet/util/backups.rb +3 -2
  888. data/lib/puppet/util/character_encoding.rb +1 -0
  889. data/lib/puppet/util/checksums.rb +11 -9
  890. data/lib/puppet/util/classgen.rb +8 -13
  891. data/lib/puppet/util/colors.rb +32 -31
  892. data/lib/puppet/util/command_line/puppet_option_parser.rb +12 -12
  893. data/lib/puppet/util/command_line/trollop.rb +693 -690
  894. data/lib/puppet/util/command_line.rb +1 -0
  895. data/lib/puppet/util/constant_inflector.rb +3 -3
  896. data/lib/puppet/util/diff.rb +13 -13
  897. data/lib/puppet/util/docs.rb +3 -0
  898. data/lib/puppet/util/errors.rb +1 -0
  899. data/lib/puppet/util/execution.rb +16 -18
  900. data/lib/puppet/util/execution_stub.rb +1 -0
  901. data/lib/puppet/util/feature.rb +1 -0
  902. data/lib/puppet/util/file_watcher.rb +2 -0
  903. data/lib/puppet/util/fileparsing.rb +2 -0
  904. data/lib/puppet/util/filetype.rb +3 -0
  905. data/lib/puppet/util/http_proxy.rb +1 -0
  906. data/lib/puppet/util/inifile.rb +3 -3
  907. data/lib/puppet/util/instance_loader.rb +2 -0
  908. data/lib/puppet/util/json.rb +1 -0
  909. data/lib/puppet/util/json_lockfile.rb +3 -1
  910. data/lib/puppet/util/ldap/connection.rb +19 -18
  911. data/lib/puppet/util/ldap/generator.rb +1 -0
  912. data/lib/puppet/util/ldap/manager.rb +3 -2
  913. data/lib/puppet/util/ldap.rb +1 -0
  914. data/lib/puppet/util/libuser.rb +1 -1
  915. data/lib/puppet/util/limits.rb +1 -0
  916. data/lib/puppet/util/lockfile.rb +1 -0
  917. data/lib/puppet/util/log/destination.rb +1 -0
  918. data/lib/puppet/util/log/destinations.rb +14 -13
  919. data/lib/puppet/util/log.rb +21 -17
  920. data/lib/puppet/util/logging.rb +18 -14
  921. data/lib/puppet/util/metaid.rb +1 -0
  922. data/lib/puppet/util/metric.rb +2 -0
  923. data/lib/puppet/util/monkey_patches.rb +1 -0
  924. data/lib/puppet/util/multi_match.rb +4 -1
  925. data/lib/puppet/util/network_device/base.rb +1 -1
  926. data/lib/puppet/util/network_device/config.rb +3 -4
  927. data/lib/puppet/util/network_device/transport/base.rb +0 -1
  928. data/lib/puppet/util/network_device/transport.rb +1 -0
  929. data/lib/puppet/util/network_device.rb +1 -0
  930. data/lib/puppet/util/package/version/debian.rb +5 -3
  931. data/lib/puppet/util/package/version/gem.rb +2 -0
  932. data/lib/puppet/util/package/version/pip.rb +7 -2
  933. data/lib/puppet/util/package/version/range/eq.rb +2 -0
  934. data/lib/puppet/util/package/version/range/gt.rb +2 -0
  935. data/lib/puppet/util/package/version/range/gt_eq.rb +2 -0
  936. data/lib/puppet/util/package/version/range/lt.rb +2 -0
  937. data/lib/puppet/util/package/version/range/lt_eq.rb +2 -0
  938. data/lib/puppet/util/package/version/range/min_max.rb +4 -0
  939. data/lib/puppet/util/package/version/range/simple.rb +1 -0
  940. data/lib/puppet/util/package/version/range.rb +3 -0
  941. data/lib/puppet/util/package/version/rpm.rb +6 -4
  942. data/lib/puppet/util/package.rb +3 -0
  943. data/lib/puppet/util/pidlock.rb +7 -7
  944. data/lib/puppet/util/platform.rb +1 -0
  945. data/lib/puppet/util/plist.rb +1 -1
  946. data/lib/puppet/util/posix.rb +8 -5
  947. data/lib/puppet/util/profiler/aggregate.rb +2 -5
  948. data/lib/puppet/util/profiler/around_profiler.rb +1 -1
  949. data/lib/puppet/util/profiler/logging.rb +1 -0
  950. data/lib/puppet/util/profiler/object_counts.rb +1 -0
  951. data/lib/puppet/util/profiler/wall_clock.rb +1 -0
  952. data/lib/puppet/util/profiler.rb +1 -0
  953. data/lib/puppet/util/provider_features.rb +4 -0
  954. data/lib/puppet/util/psych_support.rb +1 -0
  955. data/lib/puppet/util/rdoc/code_objects.rb +3 -7
  956. data/lib/puppet/util/rdoc/generators/puppet_generator.rb +37 -50
  957. data/lib/puppet/util/rdoc/generators/template/puppet/puppet.rb +50 -68
  958. data/lib/puppet/util/rdoc/parser/puppet_parser_core.rb +5 -5
  959. data/lib/puppet/util/rdoc/parser/puppet_parser_rdoc2.rb +1 -0
  960. data/lib/puppet/util/rdoc/parser.rb +1 -0
  961. data/lib/puppet/util/rdoc.rb +1 -1
  962. data/lib/puppet/util/reference.rb +1 -1
  963. data/lib/puppet/util/resource_template.rb +2 -0
  964. data/lib/puppet/util/retry_action.rb +3 -3
  965. data/lib/puppet/util/rpm_compare.rb +6 -3
  966. data/lib/puppet/util/rubygems.rb +1 -1
  967. data/lib/puppet/util/run_mode.rb +2 -1
  968. data/lib/puppet/util/selinux.rb +22 -11
  969. data/lib/puppet/util/skip_tags.rb +1 -0
  970. data/lib/puppet/util/splayer.rb +1 -0
  971. data/lib/puppet/util/storage.rb +2 -1
  972. data/lib/puppet/util/suidmanager.rb +8 -5
  973. data/lib/puppet/util/symbolic_file_mode.rb +3 -1
  974. data/lib/puppet/util/tag_set.rb +1 -0
  975. data/lib/puppet/util/tagging.rb +2 -1
  976. data/lib/puppet/util/terminal.rb +1 -0
  977. data/lib/puppet/util/user_attr.rb +1 -0
  978. data/lib/puppet/util/warnings.rb +3 -0
  979. data/lib/puppet/util/watched_file.rb +1 -0
  980. data/lib/puppet/util/watcher/change_watcher.rb +1 -0
  981. data/lib/puppet/util/watcher/periodic_watcher.rb +1 -0
  982. data/lib/puppet/util/watcher/timer.rb +1 -0
  983. data/lib/puppet/util/watcher.rb +1 -0
  984. data/lib/puppet/util/windows/access_control_entry.rb +1 -0
  985. data/lib/puppet/util/windows/access_control_list.rb +3 -2
  986. data/lib/puppet/util/windows/adsi.rb +32 -25
  987. data/lib/puppet/util/windows/com.rb +5 -3
  988. data/lib/puppet/util/windows/daemon.rb +33 -33
  989. data/lib/puppet/util/windows/error.rb +3 -2
  990. data/lib/puppet/util/windows/eventlog.rb +8 -5
  991. data/lib/puppet/util/windows/file.rb +30 -24
  992. data/lib/puppet/util/windows/monkey_patches/process.rb +0 -1
  993. data/lib/puppet/util/windows/principal.rb +27 -27
  994. data/lib/puppet/util/windows/process.rb +7 -6
  995. data/lib/puppet/util/windows/registry.rb +43 -41
  996. data/lib/puppet/util/windows/root_certs.rb +1 -0
  997. data/lib/puppet/util/windows/security.rb +43 -44
  998. data/lib/puppet/util/windows/security_descriptor.rb +1 -0
  999. data/lib/puppet/util/windows/service.rb +12 -1
  1000. data/lib/puppet/util/windows/sid.rb +6 -6
  1001. data/lib/puppet/util/windows/string.rb +1 -0
  1002. data/lib/puppet/util/windows/user.rb +33 -33
  1003. data/lib/puppet/util/windows.rb +6 -0
  1004. data/lib/puppet/util/yaml.rb +1 -0
  1005. data/lib/puppet/util.rb +18 -20
  1006. data/lib/puppet/vendor.rb +2 -1
  1007. data/lib/puppet/version.rb +3 -1
  1008. data/lib/puppet/x509/cert_provider.rb +7 -1
  1009. data/lib/puppet/x509/pem_store.rb +1 -0
  1010. data/lib/puppet/x509.rb +1 -0
  1011. data/lib/puppet.rb +1 -0
  1012. data/lib/puppet_pal.rb +1 -0
  1013. data/lib/puppet_x.rb +1 -0
  1014. data/locales/puppet.pot +195 -199
  1015. data/man/man5/puppet.conf.5 +2 -2
  1016. data/man/man8/puppet-agent.8 +1 -1
  1017. data/man/man8/puppet-apply.8 +1 -1
  1018. data/man/man8/puppet-catalog.8 +1 -1
  1019. data/man/man8/puppet-config.8 +1 -1
  1020. data/man/man8/puppet-describe.8 +1 -1
  1021. data/man/man8/puppet-device.8 +1 -1
  1022. data/man/man8/puppet-doc.8 +1 -1
  1023. data/man/man8/puppet-epp.8 +1 -1
  1024. data/man/man8/puppet-facts.8 +1 -1
  1025. data/man/man8/puppet-filebucket.8 +1 -1
  1026. data/man/man8/puppet-generate.8 +1 -1
  1027. data/man/man8/puppet-help.8 +1 -1
  1028. data/man/man8/puppet-lookup.8 +1 -1
  1029. data/man/man8/puppet-module.8 +1 -1
  1030. data/man/man8/puppet-node.8 +1 -1
  1031. data/man/man8/puppet-parser.8 +1 -1
  1032. data/man/man8/puppet-plugin.8 +1 -1
  1033. data/man/man8/puppet-report.8 +1 -1
  1034. data/man/man8/puppet-resource.8 +1 -1
  1035. data/man/man8/puppet-script.8 +1 -1
  1036. data/man/man8/puppet-ssl.8 +1 -1
  1037. data/man/man8/puppet.8 +2 -2
  1038. data/spec/integration/application/agent_spec.rb +13 -0
  1039. data/spec/lib/puppet_spec/puppetserver.rb +1 -0
  1040. data/spec/lib/puppet_spec/verbose.rb +5 -3
  1041. data/spec/unit/agent_spec.rb +2 -7
  1042. data/spec/unit/daemon_spec.rb +3 -20
  1043. data/spec/unit/indirector/catalog/compiler_spec.rb +17 -0
  1044. data/spec/unit/indirector/catalog/rest_spec.rb +17 -0
  1045. data/spec/unit/provider/package/appdmg_spec.rb +1 -1
  1046. data/spec/unit/provider/package/dnf_spec.rb +7 -0
  1047. data/spec/unit/provider/package/dnfmodule_spec.rb +22 -2
  1048. data/spec/unit/provider/service/systemd_spec.rb +8 -6
  1049. data/spec/unit/type/exec_spec.rb +14 -9
  1050. data/spec/unit/util/rpm_compare_spec.rb +8 -8
  1051. metadata +2 -3
  1052. data/CONTRIBUTING.md +0 -161
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  ## lib/trollop.rb -- trollop command-line processing library
3
4
  ## Author:: William Morgan (mailto: wmorgan-trollop@masanjin.net)
4
5
  ## Copyright:: Copyright 2007 William Morgan
@@ -16,811 +17,813 @@ require 'date'
16
17
  module Puppet
17
18
  module Util
18
19
  class CommandLine
19
- module Trollop
20
-
21
- VERSION = "1.16.2"
20
+ module Trollop
21
+ VERSION = "1.16.2"
22
22
 
23
- ## Thrown by Parser in the event of a commandline error. Not needed if
24
- ## you're using the Trollop::options entry.
25
- class CommandlineError < StandardError; end
23
+ ## Thrown by Parser in the event of a commandline error. Not needed if
24
+ ## you're using the Trollop::options entry.
25
+ class CommandlineError < StandardError; end
26
26
 
27
- ## Thrown by Parser if the user passes in '-h' or '--help'. Handled
28
- ## automatically by Trollop#options.
29
- class HelpNeeded < StandardError; end
27
+ ## Thrown by Parser if the user passes in '-h' or '--help'. Handled
28
+ ## automatically by Trollop#options.
29
+ class HelpNeeded < StandardError; end
30
30
 
31
- ## Thrown by Parser if the user passes in '-h' or '--version'. Handled
32
- ## automatically by Trollop#options.
33
- class VersionNeeded < StandardError; end
31
+ ## Thrown by Parser if the user passes in '-h' or '--version'. Handled
32
+ ## automatically by Trollop#options.
33
+ class VersionNeeded < StandardError; end
34
34
 
35
- ## Regex for floating point numbers
36
- FLOAT_RE = /^-?((\d+(\.\d+)?)|(\.\d+))([eE][-+]?[\d]+)?$/
35
+ ## Regex for floating point numbers
36
+ FLOAT_RE = /^-?((\d+(\.\d+)?)|(\.\d+))([eE][-+]?[\d]+)?$/
37
37
 
38
- ## Regex for parameters
39
- PARAM_RE = /^-(-|\.$|[^\d\.])/
38
+ ## Regex for parameters
39
+ PARAM_RE = /^-(-|\.$|[^\d\.])/
40
40
 
41
- ## The commandline parser. In typical usage, the methods in this class
42
- ## will be handled internally by Trollop::options. In this case, only the
43
- ## #opt, #banner and #version, #depends, and #conflicts methods will
44
- ## typically be called.
45
- ##
46
- ## If you want to instantiate this class yourself (for more complicated
47
- ## argument-parsing logic), call #parse to actually produce the output hash,
48
- ## and consider calling it from within
49
- ## Trollop::with_standard_exception_handling.
50
- class Parser
51
-
52
- ## The set of values that indicate a flag option when passed as the
53
- ## +:type+ parameter of #opt.
54
- FLAG_TYPES = [:flag, :bool, :boolean]
55
-
56
- ## The set of values that indicate a single-parameter (normal) option when
57
- ## passed as the +:type+ parameter of #opt.
41
+ ## The commandline parser. In typical usage, the methods in this class
42
+ ## will be handled internally by Trollop::options. In this case, only the
43
+ ## #opt, #banner and #version, #depends, and #conflicts methods will
44
+ ## typically be called.
58
45
  ##
59
- ## A value of +io+ corresponds to a readable IO resource, including
60
- ## a filename, URI, or the strings 'stdin' or '-'.
61
- SINGLE_ARG_TYPES = [:int, :integer, :string, :double, :float, :io, :date]
62
-
63
- ## The set of values that indicate a multiple-parameter option (i.e., that
64
- ## takes multiple space-separated values on the commandline) when passed as
65
- ## the +:type+ parameter of #opt.
66
- MULTI_ARG_TYPES = [:ints, :integers, :strings, :doubles, :floats, :ios, :dates]
67
-
68
- ## The complete set of legal values for the +:type+ parameter of #opt.
69
- TYPES = FLAG_TYPES + SINGLE_ARG_TYPES + MULTI_ARG_TYPES
70
-
71
- INVALID_SHORT_ARG_REGEX = /[\d-]/ #:nodoc:
72
-
73
- ## The values from the commandline that were not interpreted by #parse.
74
- attr_reader :leftovers
75
-
76
- ## The complete configuration hashes for each option. (Mainly useful
77
- ## for testing.)
78
- attr_reader :specs
79
-
80
- ## A flag that determines whether or not to attempt to automatically generate "short" options if they are not
81
- ## explicitly specified.
82
- attr_accessor :create_default_short_options
83
-
84
- ## A flag that determines whether or not to raise an error if the parser is passed one or more
85
- ## options that were not registered ahead of time. If 'true', then the parser will simply
86
- ## ignore options that it does not recognize.
87
- attr_accessor :ignore_invalid_options
88
-
89
- ## A flag indicating whether or not the parser should attempt to handle "--help" and
90
- ## "--version" specially. If 'false', it will treat them just like any other option.
91
- attr_accessor :handle_help_and_version
92
-
93
- ## Initializes the parser, and instance-evaluates any block given.
94
- def initialize *a, &b
95
- @version = nil
96
- @leftovers = []
97
- @specs = {}
98
- @long = {}
99
- @short = {}
100
- @order = []
101
- @constraints = []
102
- @stop_words = []
103
- @stop_on_unknown = false
104
-
105
- #instance_eval(&b) if b # can't take arguments
106
- cloaker(&b).bind(self).call(*a) if b
107
- end
46
+ ## If you want to instantiate this class yourself (for more complicated
47
+ ## argument-parsing logic), call #parse to actually produce the output hash,
48
+ ## and consider calling it from within
49
+ ## Trollop::with_standard_exception_handling.
50
+ class Parser
51
+ ## The set of values that indicate a flag option when passed as the
52
+ ## +:type+ parameter of #opt.
53
+ FLAG_TYPES = [:flag, :bool, :boolean]
54
+
55
+ ## The set of values that indicate a single-parameter (normal) option when
56
+ ## passed as the +:type+ parameter of #opt.
57
+ ##
58
+ ## A value of +io+ corresponds to a readable IO resource, including
59
+ ## a filename, URI, or the strings 'stdin' or '-'.
60
+ SINGLE_ARG_TYPES = [:int, :integer, :string, :double, :float, :io, :date]
61
+
62
+ ## The set of values that indicate a multiple-parameter option (i.e., that
63
+ ## takes multiple space-separated values on the commandline) when passed as
64
+ ## the +:type+ parameter of #opt.
65
+ MULTI_ARG_TYPES = [:ints, :integers, :strings, :doubles, :floats, :ios, :dates]
66
+
67
+ ## The complete set of legal values for the +:type+ parameter of #opt.
68
+ TYPES = FLAG_TYPES + SINGLE_ARG_TYPES + MULTI_ARG_TYPES
69
+
70
+ INVALID_SHORT_ARG_REGEX = /[\d-]/ # :nodoc:
71
+
72
+ ## The values from the commandline that were not interpreted by #parse.
73
+ attr_reader :leftovers
74
+
75
+ ## The complete configuration hashes for each option. (Mainly useful
76
+ ## for testing.)
77
+ attr_reader :specs
78
+
79
+ ## A flag that determines whether or not to attempt to automatically generate "short" options if they are not
80
+ ## explicitly specified.
81
+ attr_accessor :create_default_short_options
82
+
83
+ ## A flag that determines whether or not to raise an error if the parser is passed one or more
84
+ ## options that were not registered ahead of time. If 'true', then the parser will simply
85
+ ## ignore options that it does not recognize.
86
+ attr_accessor :ignore_invalid_options
87
+
88
+ ## A flag indicating whether or not the parser should attempt to handle "--help" and
89
+ ## "--version" specially. If 'false', it will treat them just like any other option.
90
+ attr_accessor :handle_help_and_version
91
+
92
+ ## Initializes the parser, and instance-evaluates any block given.
93
+ def initialize *a, &b
94
+ @version = nil
95
+ @leftovers = []
96
+ @specs = {}
97
+ @long = {}
98
+ @short = {}
99
+ @order = []
100
+ @constraints = []
101
+ @stop_words = []
102
+ @stop_on_unknown = false
103
+
104
+ # instance_eval(&b) if b # can't take arguments
105
+ cloaker(&b).bind(self).call(*a) if b
106
+ end
108
107
 
109
- ## Define an option. +name+ is the option name, a unique identifier
110
- ## for the option that you will use internally, which should be a
111
- ## symbol or a string. +desc+ is a string description which will be
112
- ## displayed in help messages.
113
- ##
114
- ## Takes the following optional arguments:
115
- ##
116
- ## [+:long+] Specify the long form of the argument, i.e. the form with two dashes. If unspecified, will be automatically derived based on the argument name by turning the +name+ option into a string, and replacing any _'s by -'s.
117
- ## [+:short+] Specify the short form of the argument, i.e. the form with one dash. If unspecified, will be automatically derived from +name+.
118
- ## [+:type+] Require that the argument take a parameter or parameters of type +type+. For a single parameter, the value can be a member of +SINGLE_ARG_TYPES+, or a corresponding Ruby class (e.g. +Integer+ for +:int+). For multiple-argument parameters, the value can be any member of +MULTI_ARG_TYPES+ constant. If unset, the default argument type is +:flag+, meaning that the argument does not take a parameter. The specification of +:type+ is not necessary if a +:default+ is given.
119
- ## [+:default+] Set the default value for an argument. Without a default value, the hash returned by #parse (and thus Trollop::options) will have a +nil+ value for this key unless the argument is given on the commandline. The argument type is derived automatically from the class of the default value given, so specifying a +:type+ is not necessary if a +:default+ is given. (But see below for an important caveat when +:multi+: is specified too.) If the argument is a flag, and the default is set to +true+, then if it is specified on the commandline the value will be +false+.
120
- ## [+:required+] If set to +true+, the argument must be provided on the commandline.
121
- ## [+:multi+] If set to +true+, allows multiple occurrences of the option on the commandline. Otherwise, only a single instance of the option is allowed. (Note that this is different from taking multiple parameters. See below.)
122
- ##
123
- ## Note that there are two types of argument multiplicity: an argument
124
- ## can take multiple values, e.g. "--arg 1 2 3". An argument can also
125
- ## be allowed to occur multiple times, e.g. "--arg 1 --arg 2".
126
- ##
127
- ## Arguments that take multiple values should have a +:type+ parameter
128
- ## drawn from +MULTI_ARG_TYPES+ (e.g. +:strings+), or a +:default:+
129
- ## value of an array of the correct type (e.g. [String]). The
130
- ## value of this argument will be an array of the parameters on the
131
- ## commandline.
132
- ##
133
- ## Arguments that can occur multiple times should be marked with
134
- ## +:multi+ => +true+. The value of this argument will also be an array.
135
- ## In contrast with regular non-multi options, if not specified on
136
- ## the commandline, the default value will be [], not nil.
137
- ##
138
- ## These two attributes can be combined (e.g. +:type+ => +:strings+,
139
- ## +:multi+ => +true+), in which case the value of the argument will be
140
- ## an array of arrays.
141
- ##
142
- ## There's one ambiguous case to be aware of: when +:multi+: is true and a
143
- ## +:default+ is set to an array (of something), it's ambiguous whether this
144
- ## is a multi-value argument as well as a multi-occurrence argument.
145
- ## In this case, Trollop assumes that it's not a multi-value argument.
146
- ## If you want a multi-value, multi-occurrence argument with a default
147
- ## value, you must specify +:type+ as well.
148
-
149
- def opt name, desc="", opts={}
150
- raise ArgumentError, _("you already have an argument named '%{name}'") % { name: name } if @specs.member? name
151
-
152
- ## fill in :type
153
- opts[:type] = # normalize
154
- case opts[:type]
155
- when :boolean, :bool; :flag
156
- when :integer; :int
157
- when :integers; :ints
158
- when :double; :float
159
- when :doubles; :floats
160
- when Class
161
- case opts[:type].name
162
- when 'TrueClass', 'FalseClass'; :flag
163
- when 'String'; :string
164
- when 'Integer'; :int
165
- when 'Float'; :float
166
- when 'IO'; :io
167
- when 'Date'; :date
108
+ ## Define an option. +name+ is the option name, a unique identifier
109
+ ## for the option that you will use internally, which should be a
110
+ ## symbol or a string. +desc+ is a string description which will be
111
+ ## displayed in help messages.
112
+ ##
113
+ ## Takes the following optional arguments:
114
+ ##
115
+ ## [+:long+] Specify the long form of the argument, i.e. the form with two dashes. If unspecified, will be automatically derived based on the argument name by turning the +name+ option into a string, and replacing any _'s by -'s.
116
+ ## [+:short+] Specify the short form of the argument, i.e. the form with one dash. If unspecified, will be automatically derived from +name+.
117
+ ## [+:type+] Require that the argument take a parameter or parameters of type +type+. For a single parameter, the value can be a member of +SINGLE_ARG_TYPES+, or a corresponding Ruby class (e.g. +Integer+ for +:int+). For multiple-argument parameters, the value can be any member of +MULTI_ARG_TYPES+ constant. If unset, the default argument type is +:flag+, meaning that the argument does not take a parameter. The specification of +:type+ is not necessary if a +:default+ is given.
118
+ ## [+:default+] Set the default value for an argument. Without a default value, the hash returned by #parse (and thus Trollop::options) will have a +nil+ value for this key unless the argument is given on the commandline. The argument type is derived automatically from the class of the default value given, so specifying a +:type+ is not necessary if a +:default+ is given. (But see below for an important caveat when +:multi+: is specified too.) If the argument is a flag, and the default is set to +true+, then if it is specified on the commandline the value will be +false+.
119
+ ## [+:required+] If set to +true+, the argument must be provided on the commandline.
120
+ ## [+:multi+] If set to +true+, allows multiple occurrences of the option on the commandline. Otherwise, only a single instance of the option is allowed. (Note that this is different from taking multiple parameters. See below.)
121
+ ##
122
+ ## Note that there are two types of argument multiplicity: an argument
123
+ ## can take multiple values, e.g. "--arg 1 2 3". An argument can also
124
+ ## be allowed to occur multiple times, e.g. "--arg 1 --arg 2".
125
+ ##
126
+ ## Arguments that take multiple values should have a +:type+ parameter
127
+ ## drawn from +MULTI_ARG_TYPES+ (e.g. +:strings+), or a +:default:+
128
+ ## value of an array of the correct type (e.g. [String]). The
129
+ ## value of this argument will be an array of the parameters on the
130
+ ## commandline.
131
+ ##
132
+ ## Arguments that can occur multiple times should be marked with
133
+ ## +:multi+ => +true+. The value of this argument will also be an array.
134
+ ## In contrast with regular non-multi options, if not specified on
135
+ ## the commandline, the default value will be [], not nil.
136
+ ##
137
+ ## These two attributes can be combined (e.g. +:type+ => +:strings+,
138
+ ## +:multi+ => +true+), in which case the value of the argument will be
139
+ ## an array of arrays.
140
+ ##
141
+ ## There's one ambiguous case to be aware of: when +:multi+: is true and a
142
+ ## +:default+ is set to an array (of something), it's ambiguous whether this
143
+ ## is a multi-value argument as well as a multi-occurrence argument.
144
+ ## In this case, Trollop assumes that it's not a multi-value argument.
145
+ ## If you want a multi-value, multi-occurrence argument with a default
146
+ ## value, you must specify +:type+ as well.
147
+
148
+ def opt name, desc="", opts={}
149
+ raise ArgumentError, _("you already have an argument named '%{name}'") % { name: name } if @specs.member? name
150
+
151
+ ## fill in :type
152
+ opts[:type] = # normalize
153
+ case opts[:type]
154
+ when :boolean, :bool; :flag
155
+ when :integer; :int
156
+ when :integers; :ints
157
+ when :double; :float
158
+ when :doubles; :floats
159
+ when Class
160
+ case opts[:type].name
161
+ when 'TrueClass', 'FalseClass'; :flag
162
+ when 'String'; :string
163
+ when 'Integer'; :int
164
+ when 'Float'; :float
165
+ when 'IO'; :io
166
+ when 'Date'; :date
167
+ else
168
+ raise ArgumentError, _("unsupported argument type '%{type}'") % { type: opts[:type].class.name }
169
+ end
170
+ when nil; nil
168
171
  else
169
- raise ArgumentError, _("unsupported argument type '%{type}'") % { type: opts[:type].class.name }
170
- end
171
- when nil; nil
172
- else
173
- raise ArgumentError, _("unsupported argument type '%{type}'") % { type: opts[:type] } unless TYPES.include?(opts[:type])
174
- opts[:type]
175
- end
176
-
177
- ## for options with :multi => true, an array default doesn't imply
178
- ## a multi-valued argument. for that you have to specify a :type
179
- ## as well. (this is how we disambiguate an ambiguous situation;
180
- ## see the docs for Parser#opt for details.)
181
- disambiguated_default =
182
- if opts[:multi] && opts[:default].is_a?(Array) && !opts[:type]
183
- opts[:default].first
184
- else
185
- opts[:default]
186
- end
172
+ raise ArgumentError, _("unsupported argument type '%{type}'") % { type: opts[:type] } unless TYPES.include?(opts[:type])
187
173
 
188
- type_from_default =
189
- case disambiguated_default
190
- when Integer; :int
191
- when Numeric; :float
192
- when TrueClass, FalseClass; :flag
193
- when String; :string
194
- when IO; :io
195
- when Date; :date
196
- when Array
197
- if opts[:default].empty?
198
- raise ArgumentError, _("multiple argument type cannot be deduced from an empty array for '%{value0}'") % { value0: opts[:default][0].class.name }
174
+ opts[:type]
199
175
  end
200
- case opts[:default][0] # the first element determines the types
201
- when Integer; :ints
202
- when Numeric; :floats
203
- when String; :strings
204
- when IO; :ios
205
- when Date; :dates
176
+
177
+ ## for options with :multi => true, an array default doesn't imply
178
+ ## a multi-valued argument. for that you have to specify a :type
179
+ ## as well. (this is how we disambiguate an ambiguous situation;
180
+ ## see the docs for Parser#opt for details.)
181
+ disambiguated_default =
182
+ if opts[:multi] && opts[:default].is_a?(Array) && !opts[:type]
183
+ opts[:default].first
206
184
  else
207
- raise ArgumentError, _("unsupported multiple argument type '%{value0}'") % { value0: opts[:default][0].class.name }
185
+ opts[:default]
208
186
  end
209
- when nil; nil
210
- else
211
- raise ArgumentError, _("unsupported argument type '%{value0}'") % { value0: opts[:default].class.name }
212
- end
213
-
214
- raise ArgumentError, _(":type specification and default type don't match (default type is %{type_from_default})") % { type_from_default: type_from_default } if opts[:type] && type_from_default && opts[:type] != type_from_default
215
187
 
216
- opts[:type] = opts[:type] || type_from_default || :flag
188
+ type_from_default =
189
+ case disambiguated_default
190
+ when Integer; :int
191
+ when Numeric; :float
192
+ when TrueClass, FalseClass; :flag
193
+ when String; :string
194
+ when IO; :io
195
+ when Date; :date
196
+ when Array
197
+ if opts[:default].empty?
198
+ raise ArgumentError, _("multiple argument type cannot be deduced from an empty array for '%{value0}'") % { value0: opts[:default][0].class.name }
199
+ end
217
200
 
218
- ## fill in :long
219
- opts[:long] = opts[:long] ? opts[:long].to_s : name.to_s.tr("_", "-")
220
- opts[:long] =
221
- case opts[:long]
222
- when /^--([^-].*)$/
223
- $1
224
- when /^[^-]/
225
- opts[:long]
226
- else
227
- raise ArgumentError, _("invalid long option name %{name}") % { name: opts[:long].inspect }
228
- end
229
- raise ArgumentError, _("long option name %{value0} is already taken; please specify a (different) :long") % { value0: opts[:long].inspect } if @long[opts[:long]]
230
-
231
- ## fill in :short
232
- opts[:short] = opts[:short].to_s if opts[:short] unless opts[:short] == :none
233
- opts[:short] = case opts[:short]
234
- when /^-(.)$/; $1
235
- when nil, :none, /^.$/; opts[:short]
236
- else raise ArgumentError, _("invalid short option name '%{name}'") % { name: opts[:short].inspect }
237
- end
201
+ case opts[:default][0] # the first element determines the types
202
+ when Integer; :ints
203
+ when Numeric; :floats
204
+ when String; :strings
205
+ when IO; :ios
206
+ when Date; :dates
207
+ else
208
+ raise ArgumentError, _("unsupported multiple argument type '%{value0}'") % { value0: opts[:default][0].class.name }
209
+ end
210
+ when nil; nil
211
+ else
212
+ raise ArgumentError, _("unsupported argument type '%{value0}'") % { value0: opts[:default].class.name }
213
+ end
238
214
 
239
- if opts[:short]
240
- raise ArgumentError, _("short option name %{value0} is already taken; please specify a (different) :short") % { value0: opts[:short].inspect } if @short[opts[:short]]
241
- raise ArgumentError, _("a short option name can't be a number or a dash") if opts[:short] =~ INVALID_SHORT_ARG_REGEX
242
- end
215
+ raise ArgumentError, _(":type specification and default type don't match (default type is %{type_from_default})") % { type_from_default: type_from_default } if opts[:type] && type_from_default && opts[:type] != type_from_default
243
216
 
244
- ## fill in :default for flags
245
- opts[:default] = false if opts[:type] == :flag && opts[:default].nil?
217
+ opts[:type] = opts[:type] || type_from_default || :flag
246
218
 
247
- ## autobox :default for :multi (multi-occurrence) arguments
248
- opts[:default] = [opts[:default]] if opts[:default] && opts[:multi] && !opts[:default].is_a?(Array)
219
+ ## fill in :long
220
+ opts[:long] = opts[:long] ? opts[:long].to_s : name.to_s.tr("_", "-")
221
+ opts[:long] =
222
+ case opts[:long]
223
+ when /^--([^-].*)$/
224
+ $1
225
+ when /^[^-]/
226
+ opts[:long]
227
+ else
228
+ raise ArgumentError, _("invalid long option name %{name}") % { name: opts[:long].inspect }
229
+ end
230
+ raise ArgumentError, _("long option name %{value0} is already taken; please specify a (different) :long") % { value0: opts[:long].inspect } if @long[opts[:long]]
231
+
232
+ ## fill in :short
233
+ opts[:short] = opts[:short].to_s if opts[:short] unless opts[:short] == :none
234
+ opts[:short] = case opts[:short]
235
+ when /^-(.)$/; $1
236
+ when nil, :none, /^.$/; opts[:short]
237
+ else raise ArgumentError, _("invalid short option name '%{name}'") % { name: opts[:short].inspect }
238
+ end
239
+
240
+ if opts[:short]
241
+ raise ArgumentError, _("short option name %{value0} is already taken; please specify a (different) :short") % { value0: opts[:short].inspect } if @short[opts[:short]]
242
+ raise ArgumentError, _("a short option name can't be a number or a dash") if opts[:short] =~ INVALID_SHORT_ARG_REGEX
243
+ end
249
244
 
250
- ## fill in :multi
251
- opts[:multi] ||= false
245
+ ## fill in :default for flags
246
+ opts[:default] = false if opts[:type] == :flag && opts[:default].nil?
252
247
 
253
- opts[:desc] ||= desc
254
- @long[opts[:long]] = name
255
- @short[opts[:short]] = name if opts[:short] && opts[:short] != :none
256
- @specs[name] = opts
257
- @order << [:opt, name]
258
- end
248
+ ## autobox :default for :multi (multi-occurrence) arguments
249
+ opts[:default] = [opts[:default]] if opts[:default] && opts[:multi] && !opts[:default].is_a?(Array)
259
250
 
260
- ## Sets the version string. If set, the user can request the version
261
- ## on the commandline. Should probably be of the form "<program name>
262
- ## <version number>".
263
- def version s=nil; @version = s if s; @version end
264
-
265
- ## Adds text to the help display. Can be interspersed with calls to
266
- ## #opt to build a multi-section help page.
267
- def banner s; @order << [:text, s] end
268
- alias :text :banner
269
-
270
- ## Marks two (or more!) options as requiring each other. Only handles
271
- ## undirected (i.e., mutual) dependencies. Directed dependencies are
272
- ## better modeled with Trollop::die.
273
- def depends *syms
274
- syms.each { |sym| raise ArgumentError, _("unknown option '%{sym}'") % { sym: sym } unless @specs[sym] }
275
- @constraints << [:depends, syms]
276
- end
251
+ ## fill in :multi
252
+ opts[:multi] ||= false
277
253
 
278
- ## Marks two (or more!) options as conflicting.
279
- def conflicts *syms
280
- syms.each { |sym| raise ArgumentError, _("unknown option '%{sym}'") % { sym: sym } unless @specs[sym] }
281
- @constraints << [:conflicts, syms]
282
- end
254
+ opts[:desc] ||= desc
255
+ @long[opts[:long]] = name
256
+ @short[opts[:short]] = name if opts[:short] && opts[:short] != :none
257
+ @specs[name] = opts
258
+ @order << [:opt, name]
259
+ end
283
260
 
284
- ## Defines a set of words which cause parsing to terminate when
285
- ## encountered, such that any options to the left of the word are
286
- ## parsed as usual, and options to the right of the word are left
287
- ## intact.
288
- ##
289
- ## A typical use case would be for subcommand support, where these
290
- ## would be set to the list of subcommands. A subsequent Trollop
291
- ## invocation would then be used to parse subcommand options, after
292
- ## shifting the subcommand off of ARGV.
293
- def stop_on *words
294
- @stop_words = [*words].flatten
295
- end
261
+ ## Sets the version string. If set, the user can request the version
262
+ ## on the commandline. Should probably be of the form "<program name>
263
+ ## <version number>".
264
+ def version s=nil; @version = s if s; @version end
265
+
266
+ ## Adds text to the help display. Can be interspersed with calls to
267
+ ## #opt to build a multi-section help page.
268
+ def banner s; @order << [:text, s] end
269
+ alias :text :banner
270
+
271
+ ## Marks two (or more!) options as requiring each other. Only handles
272
+ ## undirected (i.e., mutual) dependencies. Directed dependencies are
273
+ ## better modeled with Trollop::die.
274
+ def depends *syms
275
+ syms.each { |sym| raise ArgumentError, _("unknown option '%{sym}'") % { sym: sym } unless @specs[sym] }
276
+ @constraints << [:depends, syms]
277
+ end
296
278
 
297
- ## Similar to #stop_on, but stops on any unknown word when encountered
298
- ## (unless it is a parameter for an argument). This is useful for
299
- ## cases where you don't know the set of subcommands ahead of time,
300
- ## i.e., without first parsing the global options.
301
- def stop_on_unknown
302
- @stop_on_unknown = true
303
- end
279
+ ## Marks two (or more!) options as conflicting.
280
+ def conflicts *syms
281
+ syms.each { |sym| raise ArgumentError, _("unknown option '%{sym}'") % { sym: sym } unless @specs[sym] }
282
+ @constraints << [:conflicts, syms]
283
+ end
304
284
 
305
- ## Parses the commandline. Typically called by Trollop::options,
306
- ## but you can call it directly if you need more control.
307
- ##
308
- ## throws CommandlineError, HelpNeeded, and VersionNeeded exceptions.
309
- def parse cmdline=ARGV
310
- vals = {}
311
- required = {}
312
-
313
- if handle_help_and_version
314
- opt :version, _("Print version and exit") if @version unless @specs[:version] || @long["version"]
315
- opt :help, _("Show this message") unless @specs[:help] || @long["help"]
285
+ ## Defines a set of words which cause parsing to terminate when
286
+ ## encountered, such that any options to the left of the word are
287
+ ## parsed as usual, and options to the right of the word are left
288
+ ## intact.
289
+ ##
290
+ ## A typical use case would be for subcommand support, where these
291
+ ## would be set to the list of subcommands. A subsequent Trollop
292
+ ## invocation would then be used to parse subcommand options, after
293
+ ## shifting the subcommand off of ARGV.
294
+ def stop_on *words
295
+ @stop_words = [*words].flatten
316
296
  end
317
297
 
318
- @specs.each do |sym, opts|
319
- required[sym] = true if opts[:required]
320
- vals[sym] = opts[:default]
321
- vals[sym] = [] if opts[:multi] && !opts[:default] # multi arguments default to [], not nil
298
+ ## Similar to #stop_on, but stops on any unknown word when encountered
299
+ ## (unless it is a parameter for an argument). This is useful for
300
+ ## cases where you don't know the set of subcommands ahead of time,
301
+ ## i.e., without first parsing the global options.
302
+ def stop_on_unknown
303
+ @stop_on_unknown = true
322
304
  end
323
305
 
324
- resolve_default_short_options if create_default_short_options
325
-
326
- ## resolve symbols
327
- given_args = {}
328
- @leftovers = each_arg cmdline do |arg, params|
329
- sym = case arg
330
- when /^-([^-])$/
331
- @short[$1]
332
- when /^--no-([^-]\S*)$/
333
- @long["[no-]#{$1}"]
334
- when /^--([^-]\S*)$/
335
- @long[$1] ? @long[$1] : @long["[no-]#{$1}"]
336
- else
337
- raise CommandlineError, _("invalid argument syntax: '%{arg}'") % { arg: arg }
306
+ ## Parses the commandline. Typically called by Trollop::options,
307
+ ## but you can call it directly if you need more control.
308
+ ##
309
+ ## throws CommandlineError, HelpNeeded, and VersionNeeded exceptions.
310
+ def parse cmdline=ARGV
311
+ vals = {}
312
+ required = {}
313
+
314
+ if handle_help_and_version
315
+ opt :version, _("Print version and exit") if @version unless @specs[:version] || @long["version"]
316
+ opt :help, _("Show this message") unless @specs[:help] || @long["help"]
338
317
  end
339
318
 
340
- unless sym
341
- next 0 if ignore_invalid_options
342
- raise CommandlineError, _("unknown argument '%{arg}'") % { arg: arg } unless sym
319
+ @specs.each do |sym, opts|
320
+ required[sym] = true if opts[:required]
321
+ vals[sym] = opts[:default]
322
+ vals[sym] = [] if opts[:multi] && !opts[:default] # multi arguments default to [], not nil
343
323
  end
344
324
 
345
- if given_args.include?(sym) && !@specs[sym][:multi]
346
- raise CommandlineError, _("option '%{arg}' specified multiple times") % { arg: arg }
347
- end
325
+ resolve_default_short_options if create_default_short_options
326
+
327
+ ## resolve symbols
328
+ given_args = {}
329
+ @leftovers = each_arg cmdline do |arg, params|
330
+ sym = case arg
331
+ when /^-([^-])$/
332
+ @short[$1]
333
+ when /^--no-([^-]\S*)$/
334
+ @long["[no-]#{$1}"]
335
+ when /^--([^-]\S*)$/
336
+ @long[$1] ? @long[$1] : @long["[no-]#{$1}"]
337
+ else
338
+ raise CommandlineError, _("invalid argument syntax: '%{arg}'") % { arg: arg }
339
+ end
340
+
341
+ unless sym
342
+ next 0 if ignore_invalid_options
343
+ raise CommandlineError, _("unknown argument '%{arg}'") % { arg: arg } unless sym
344
+ end
345
+
346
+ if given_args.include?(sym) && !@specs[sym][:multi]
347
+ raise CommandlineError, _("option '%{arg}' specified multiple times") % { arg: arg }
348
+ end
348
349
 
349
- given_args[sym] ||= {}
350
+ given_args[sym] ||= {}
350
351
 
351
- given_args[sym][:arg] = arg
352
- given_args[sym][:params] ||= []
352
+ given_args[sym][:arg] = arg
353
+ given_args[sym][:params] ||= []
353
354
 
354
- # The block returns the number of parameters taken.
355
- num_params_taken = 0
355
+ # The block returns the number of parameters taken.
356
+ num_params_taken = 0
356
357
 
357
- unless params.nil?
358
- if SINGLE_ARG_TYPES.include?(@specs[sym][:type])
359
- given_args[sym][:params] << params[0, 1] # take the first parameter
360
- num_params_taken = 1
361
- elsif MULTI_ARG_TYPES.include?(@specs[sym][:type])
362
- given_args[sym][:params] << params # take all the parameters
363
- num_params_taken = params.size
358
+ unless params.nil?
359
+ if SINGLE_ARG_TYPES.include?(@specs[sym][:type])
360
+ given_args[sym][:params] << params[0, 1] # take the first parameter
361
+ num_params_taken = 1
362
+ elsif MULTI_ARG_TYPES.include?(@specs[sym][:type])
363
+ given_args[sym][:params] << params # take all the parameters
364
+ num_params_taken = params.size
365
+ end
364
366
  end
365
- end
366
367
 
367
- num_params_taken
368
- end
368
+ num_params_taken
369
+ end
369
370
 
370
- if handle_help_and_version
371
- ## check for version and help args
372
- raise VersionNeeded if given_args.include? :version
373
- raise HelpNeeded if given_args.include? :help
374
- end
371
+ if handle_help_and_version
372
+ ## check for version and help args
373
+ raise VersionNeeded if given_args.include? :version
374
+ raise HelpNeeded if given_args.include? :help
375
+ end
375
376
 
376
- ## check constraint satisfaction
377
- @constraints.each do |type, syms|
378
- constraint_sym = syms.find { |sym| given_args[sym] }
379
- next unless constraint_sym
377
+ ## check constraint satisfaction
378
+ @constraints.each do |type, syms|
379
+ constraint_sym = syms.find { |sym| given_args[sym] }
380
+ next unless constraint_sym
380
381
 
381
- case type
382
- when :depends
383
- syms.each { |sym| raise CommandlineError, _("--%{value0} requires --%{value1}") % { value0: @specs[constraint_sym][:long], value1: @specs[sym][:long] } unless given_args.include? sym }
384
- when :conflicts
385
- syms.each { |sym| raise CommandlineError, _("--%{value0} conflicts with --%{value1}") % { value0: @specs[constraint_sym][:long], value1: @specs[sym][:long] } if given_args.include?(sym) && (sym != constraint_sym) }
382
+ case type
383
+ when :depends
384
+ syms.each { |sym| raise CommandlineError, _("--%{value0} requires --%{value1}") % { value0: @specs[constraint_sym][:long], value1: @specs[sym][:long] } unless given_args.include? sym }
385
+ when :conflicts
386
+ syms.each { |sym| raise CommandlineError, _("--%{value0} conflicts with --%{value1}") % { value0: @specs[constraint_sym][:long], value1: @specs[sym][:long] } if given_args.include?(sym) && (sym != constraint_sym) }
387
+ end
386
388
  end
387
- end
388
389
 
389
- required.each do |sym, val|
390
- raise CommandlineError, _("option --%{opt} must be specified") % { opt: @specs[sym][:long] } unless given_args.include? sym
391
- end
390
+ required.each do |sym, _val|
391
+ raise CommandlineError, _("option --%{opt} must be specified") % { opt: @specs[sym][:long] } unless given_args.include? sym
392
+ end
392
393
 
393
- ## parse parameters
394
- given_args.each do |sym, given_data|
395
- arg = given_data[:arg]
396
- params = given_data[:params]
394
+ ## parse parameters
395
+ given_args.each do |sym, given_data|
396
+ arg = given_data[:arg]
397
+ params = given_data[:params]
397
398
 
398
- opts = @specs[sym]
399
- raise CommandlineError, _("option '%{arg}' needs a parameter") % { arg: arg } if params.empty? && opts[:type] != :flag
399
+ opts = @specs[sym]
400
+ raise CommandlineError, _("option '%{arg}' needs a parameter") % { arg: arg } if params.empty? && opts[:type] != :flag
400
401
 
401
- vals["#{sym}_given".intern] = true # mark argument as specified on the commandline
402
+ vals["#{sym}_given".intern] = true # mark argument as specified on the commandline
402
403
 
403
- case opts[:type]
404
- when :flag
405
- if arg =~ /^--no-/ and sym.to_s =~ /^--\[no-\]/
406
- vals[sym] = opts[:default]
407
- else
408
- vals[sym] = !opts[:default]
404
+ case opts[:type]
405
+ when :flag
406
+ if arg =~ /^--no-/ and sym.to_s =~ /^--\[no-\]/
407
+ vals[sym] = opts[:default]
408
+ else
409
+ vals[sym] = !opts[:default]
410
+ end
411
+ when :int, :ints
412
+ vals[sym] = params.map { |pg| pg.map { |p| parse_integer_parameter p, arg } }
413
+ when :float, :floats
414
+ vals[sym] = params.map { |pg| pg.map { |p| parse_float_parameter p, arg } }
415
+ when :string, :strings
416
+ vals[sym] = params.map { |pg| pg.map { |p| p.to_s } }
417
+ when :io, :ios
418
+ vals[sym] = params.map { |pg| pg.map { |p| parse_io_parameter p, arg } }
419
+ when :date, :dates
420
+ vals[sym] = params.map { |pg| pg.map { |p| parse_date_parameter p, arg } }
409
421
  end
410
- when :int, :ints
411
- vals[sym] = params.map { |pg| pg.map { |p| parse_integer_parameter p, arg } }
412
- when :float, :floats
413
- vals[sym] = params.map { |pg| pg.map { |p| parse_float_parameter p, arg } }
414
- when :string, :strings
415
- vals[sym] = params.map { |pg| pg.map { |p| p.to_s } }
416
- when :io, :ios
417
- vals[sym] = params.map { |pg| pg.map { |p| parse_io_parameter p, arg } }
418
- when :date, :dates
419
- vals[sym] = params.map { |pg| pg.map { |p| parse_date_parameter p, arg } }
420
- end
421
422
 
422
- if SINGLE_ARG_TYPES.include?(opts[:type])
423
- unless opts[:multi] # single parameter
424
- vals[sym] = vals[sym][0][0]
425
- else # multiple options, each with a single parameter
426
- vals[sym] = vals[sym].map { |p| p[0] }
423
+ if SINGLE_ARG_TYPES.include?(opts[:type])
424
+ unless opts[:multi] # single parameter
425
+ vals[sym] = vals[sym][0][0]
426
+ else # multiple options, each with a single parameter
427
+ vals[sym] = vals[sym].map { |p| p[0] }
428
+ end
429
+ elsif MULTI_ARG_TYPES.include?(opts[:type]) && !opts[:multi]
430
+ vals[sym] = vals[sym][0] # single option, with multiple parameters
427
431
  end
428
- elsif MULTI_ARG_TYPES.include?(opts[:type]) && !opts[:multi]
429
- vals[sym] = vals[sym][0] # single option, with multiple parameters
430
- end
431
- # else: multiple options, with multiple parameters
432
+ # else: multiple options, with multiple parameters
432
433
 
433
- opts[:callback].call(vals[sym]) if opts.has_key?(:callback)
434
- end
434
+ opts[:callback].call(vals[sym]) if opts.has_key?(:callback)
435
+ end
435
436
 
436
- ## modify input in place with only those
437
- ## arguments we didn't process
438
- cmdline.clear
439
- @leftovers.each { |l| cmdline << l }
437
+ ## modify input in place with only those
438
+ ## arguments we didn't process
439
+ cmdline.clear
440
+ @leftovers.each { |l| cmdline << l }
440
441
 
441
- ## allow openstruct-style accessors
442
- class << vals
443
- def method_missing(m, *args)
444
- self[m] || self[m.to_s]
442
+ ## allow openstruct-style accessors
443
+ class << vals
444
+ def method_missing(m, *args)
445
+ self[m] || self[m.to_s]
446
+ end
445
447
  end
448
+ vals
446
449
  end
447
- vals
448
- end
449
450
 
450
- def parse_date_parameter param, arg #:nodoc:
451
- begin
451
+ def parse_date_parameter param, arg # :nodoc:
452
452
  begin
453
- time = Chronic.parse(param)
454
- rescue NameError
455
- # chronic is not available
456
- end
457
- time ? Date.new(time.year, time.month, time.day) : Date.parse(param)
458
- rescue ArgumentError
459
- raise CommandlineError, _("option '%{arg}' needs a date") % { arg: arg }, $!.backtrace
460
- end
461
- end
462
-
463
- ## Print the help message to +stream+.
464
- def educate stream=$stdout
465
- width # just calculate it now; otherwise we have to be careful not to
466
- # call this unless the cursor's at the beginning of a line.
467
-
468
- left = {}
469
- @specs.each do |name, spec|
470
- left[name] = "--#{spec[:long]}" +
471
- (spec[:short] && spec[:short] != :none ? ", -#{spec[:short]}" : "") +
472
- case spec[:type]
473
- when :flag; ""
474
- when :int; " <i>"
475
- when :ints; " <i+>"
476
- when :string; " <s>"
477
- when :strings; " <s+>"
478
- when :float; " <f>"
479
- when :floats; " <f+>"
480
- when :io; " <filename/uri>"
481
- when :ios; " <filename/uri+>"
482
- when :date; " <date>"
483
- when :dates; " <date+>"
453
+ begin
454
+ time = Chronic.parse(param)
455
+ rescue NameError
456
+ # chronic is not available
484
457
  end
458
+ time ? Date.new(time.year, time.month, time.day) : Date.parse(param)
459
+ rescue ArgumentError
460
+ raise CommandlineError, _("option '%{arg}' needs a date") % { arg: arg }, $!.backtrace
461
+ end
485
462
  end
486
463
 
487
- leftcol_width = left.values.map { |s| s.length }.max || 0
488
- rightcol_start = leftcol_width + 6 # spaces
464
+ ## Print the help message to +stream+.
465
+ def educate stream=$stdout
466
+ width # just calculate it now; otherwise we have to be careful not to
467
+ # call this unless the cursor's at the beginning of a line.
468
+
469
+ left = {}
470
+ @specs.each do |name, spec|
471
+ left[name] = "--#{spec[:long]}" +
472
+ (spec[:short] && spec[:short] != :none ? ", -#{spec[:short]}" : "") +
473
+ case spec[:type]
474
+ when :flag; ""
475
+ when :int; " <i>"
476
+ when :ints; " <i+>"
477
+ when :string; " <s>"
478
+ when :strings; " <s+>"
479
+ when :float; " <f>"
480
+ when :floats; " <f+>"
481
+ when :io; " <filename/uri>"
482
+ when :ios; " <filename/uri+>"
483
+ when :date; " <date>"
484
+ when :dates; " <date+>"
485
+ end
486
+ end
489
487
 
490
- unless @order.size > 0 && @order.first.first == :text
491
- stream.puts "#@version\n" if @version
492
- stream.puts _("Options:")
493
- end
488
+ leftcol_width = left.values.map { |s| s.length }.max || 0
489
+ rightcol_start = leftcol_width + 6 # spaces
494
490
 
495
- @order.each do |what, opt|
496
- if what == :text
497
- stream.puts wrap(opt)
498
- next
491
+ unless @order.size > 0 && @order.first.first == :text
492
+ stream.puts "#@version\n" if @version
493
+ stream.puts _("Options:")
499
494
  end
500
495
 
501
- spec = @specs[opt]
502
- stream.printf " %#{leftcol_width}s: ", left[opt]
503
- desc = spec[:desc] + begin
504
- default_s = case spec[:default]
505
- when $stdout; "<stdout>"
506
- when $stdin; "<stdin>"
507
- when $stderr; "<stderr>"
508
- when Array
509
- spec[:default].join(", ")
510
- else
511
- spec[:default].to_s
496
+ @order.each do |what, opt|
497
+ if what == :text
498
+ stream.puts wrap(opt)
499
+ next
512
500
  end
513
501
 
514
- if spec[:default]
515
- if spec[:desc] =~ /\.$/
516
- _(" (Default: %{default_s})") % { default_s: default_s }
502
+ spec = @specs[opt]
503
+ stream.printf " %#{leftcol_width}s: ", left[opt]
504
+ desc = spec[:desc] + begin
505
+ default_s = case spec[:default]
506
+ when $stdout; "<stdout>"
507
+ when $stdin; "<stdin>"
508
+ when $stderr; "<stderr>"
509
+ when Array
510
+ spec[:default].join(", ")
511
+ else
512
+ spec[:default].to_s
513
+ end
514
+
515
+ if spec[:default]
516
+ if spec[:desc] =~ /\.$/
517
+ _(" (Default: %{default_s})") % { default_s: default_s }
518
+ else
519
+ _(" (default: %{default_s})") % { default_s: default_s }
520
+ end
517
521
  else
518
- _(" (default: %{default_s})") % { default_s: default_s }
522
+ ""
519
523
  end
520
- else
521
- ""
522
524
  end
525
+ stream.puts wrap(desc, :width => width - rightcol_start - 1, :prefix => rightcol_start)
523
526
  end
524
- stream.puts wrap(desc, :width => width - rightcol_start - 1, :prefix => rightcol_start)
525
527
  end
526
- end
527
528
 
528
- def width #:nodoc:
529
- @width ||= if $stdout.tty?
530
- begin
531
- require 'curses'
532
- Curses::init_screen
533
- x = Curses::cols
534
- Curses::close_screen
535
- x
536
- rescue Exception
537
- 80
538
- end
539
- else
540
- 80
529
+ def width # :nodoc:
530
+ @width ||= if $stdout.tty?
531
+ begin
532
+ require 'curses'
533
+ Curses::init_screen
534
+ x = Curses::cols
535
+ Curses::close_screen
536
+ x
537
+ rescue Exception
538
+ 80
539
+ end
540
+ else
541
+ 80
542
+ end
541
543
  end
542
- end
543
544
 
544
- def wrap str, opts={} # :nodoc:
545
- if str == ""
546
- [""]
547
- else
548
- str.split("\n").map { |s| wrap_line s, opts }.flatten
545
+ def wrap str, opts={} # :nodoc:
546
+ if str == ""
547
+ [""]
548
+ else
549
+ str.split("\n").map { |s| wrap_line s, opts }.flatten
550
+ end
549
551
  end
550
- end
551
552
 
552
- ## The per-parser version of Trollop::die (see that for documentation).
553
- def die arg, msg
554
- if msg
555
- $stderr.puts _("Error: argument --%{value0} %{msg}.") % { value0: @specs[arg][:long], msg: msg }
556
- else
557
- $stderr.puts _("Error: %{arg}.") % { arg: arg }
553
+ ## The per-parser version of Trollop::die (see that for documentation).
554
+ def die arg, msg
555
+ if msg
556
+ $stderr.puts _("Error: argument --%{value0} %{msg}.") % { value0: @specs[arg][:long], msg: msg }
557
+ else
558
+ $stderr.puts _("Error: %{arg}.") % { arg: arg }
559
+ end
560
+ $stderr.puts _("Try --help for help.")
561
+ exit(-1)
558
562
  end
559
- $stderr.puts _("Try --help for help.")
560
- exit(-1)
561
- end
562
563
 
563
- private
564
+ private
564
565
 
565
- ## yield successive arg, parameter pairs
566
- def each_arg args
567
- remains = []
568
- i = 0
566
+ ## yield successive arg, parameter pairs
567
+ def each_arg args
568
+ remains = []
569
+ i = 0
569
570
 
570
- until i >= args.length
571
- if @stop_words.member? args[i]
572
- remains += args[i .. -1]
573
- return remains
574
- end
575
- case args[i]
576
- when /^--$/ # arg terminator
577
- remains += args[(i + 1) .. -1]
578
- return remains
579
- when /^--(\S+?)=(.*)$/ # long argument with equals
580
- yield "--#{$1}", [$2]
581
- i += 1
582
- when /^--(\S+)$/ # long argument
583
- params = collect_argument_parameters(args, i + 1)
584
- unless params.empty?
585
- num_params_taken = yield args[i], params
586
- unless num_params_taken
587
- if @stop_on_unknown
588
- remains += args[i + 1 .. -1]
589
- return remains
590
- else
591
- remains += params
571
+ until i >= args.length
572
+ if @stop_words.member? args[i]
573
+ remains += args[i .. -1]
574
+ return remains
575
+ end
576
+ case args[i]
577
+ when /^--$/ # arg terminator
578
+ remains += args[(i + 1) .. -1]
579
+ return remains
580
+ when /^--(\S+?)=(.*)$/ # long argument with equals
581
+ yield "--#{$1}", [$2]
582
+ i += 1
583
+ when /^--(\S+)$/ # long argument
584
+ params = collect_argument_parameters(args, i + 1)
585
+ unless params.empty?
586
+ num_params_taken = yield args[i], params
587
+ unless num_params_taken
588
+ if @stop_on_unknown
589
+ remains += args[i + 1 .. -1]
590
+ return remains
591
+ else
592
+ remains += params
593
+ end
592
594
  end
595
+ i += 1 + num_params_taken
596
+ else # long argument no parameter
597
+ yield args[i], nil
598
+ i += 1
593
599
  end
594
- i += 1 + num_params_taken
595
- else # long argument no parameter
596
- yield args[i], nil
597
- i += 1
598
- end
599
- when /^-(\S+)$/ # one or more short arguments
600
- shortargs = $1.split(//)
601
- shortargs.each_with_index do |a, j|
602
- if j == (shortargs.length - 1)
603
- params = collect_argument_parameters(args, i + 1)
604
- unless params.empty?
605
- num_params_taken = yield "-#{a}", params
606
- unless num_params_taken
607
- if @stop_on_unknown
608
- remains += args[i + 1 .. -1]
609
- return remains
610
- else
611
- remains += params
600
+ when /^-(\S+)$/ # one or more short arguments
601
+ shortargs = $1.split(//)
602
+ shortargs.each_with_index do |a, j|
603
+ if j == (shortargs.length - 1)
604
+ params = collect_argument_parameters(args, i + 1)
605
+ unless params.empty?
606
+ num_params_taken = yield "-#{a}", params
607
+ unless num_params_taken
608
+ if @stop_on_unknown
609
+ remains += args[i + 1 .. -1]
610
+ return remains
611
+ else
612
+ remains += params
613
+ end
612
614
  end
615
+ i += 1 + num_params_taken
616
+ else # argument no parameter
617
+ yield "-#{a}", nil
618
+ i += 1
613
619
  end
614
- i += 1 + num_params_taken
615
- else # argument no parameter
620
+ else
616
621
  yield "-#{a}", nil
617
- i += 1
618
622
  end
619
- else
620
- yield "-#{a}", nil
621
623
  end
622
- end
623
- else
624
- if @stop_on_unknown
625
- remains += args[i .. -1]
626
- return remains
627
624
  else
628
- remains << args[i]
629
- i += 1
625
+ if @stop_on_unknown
626
+ remains += args[i .. -1]
627
+ return remains
628
+ else
629
+ remains << args[i]
630
+ i += 1
631
+ end
630
632
  end
631
633
  end
634
+
635
+ remains
632
636
  end
633
637
 
634
- remains
635
- end
638
+ def parse_integer_parameter param, arg
639
+ raise CommandlineError, _("option '%{arg}' needs an integer") % { arg: arg } unless param =~ /^\d+$/
636
640
 
637
- def parse_integer_parameter param, arg
638
- raise CommandlineError, _("option '%{arg}' needs an integer") % { arg: arg } unless param =~ /^\d+$/
639
- param.to_i
640
- end
641
+ param.to_i
642
+ end
641
643
 
642
- def parse_float_parameter param, arg
643
- raise CommandlineError, _("option '%{arg}' needs a floating-point number") % { arg: arg } unless param =~ FLOAT_RE
644
- param.to_f
645
- end
644
+ def parse_float_parameter param, arg
645
+ raise CommandlineError, _("option '%{arg}' needs a floating-point number") % { arg: arg } unless param =~ FLOAT_RE
646
646
 
647
- def parse_io_parameter param, arg
648
- case param
649
- when /^(stdin|-)$/i; $stdin
650
- else
651
- require 'open-uri'
652
- begin
653
- open param
654
- rescue SystemCallError => e
655
- raise CommandlineError, _("file or url for option '%{arg}' cannot be opened: %{value0}") % { arg: arg, value0: e.message }, e.backtrace
647
+ param.to_f
648
+ end
649
+
650
+ def parse_io_parameter param, arg
651
+ case param
652
+ when /^(stdin|-)$/i; $stdin
653
+ else
654
+ require 'open-uri'
655
+ begin
656
+ URI.parse(param).open
657
+ rescue SystemCallError => e
658
+ raise CommandlineError, _("file or url for option '%{arg}' cannot be opened: %{value0}") % { arg: arg, value0: e.message }, e.backtrace
659
+ end
656
660
  end
657
661
  end
658
- end
659
662
 
660
- def collect_argument_parameters args, start_at
661
- params = []
662
- pos = start_at
663
- while args[pos] && args[pos] !~ PARAM_RE && !@stop_words.member?(args[pos]) do
664
- params << args[pos]
665
- pos += 1
663
+ def collect_argument_parameters args, start_at
664
+ params = []
665
+ pos = start_at
666
+ while args[pos] && args[pos] !~ PARAM_RE && !@stop_words.member?(args[pos]) do
667
+ params << args[pos]
668
+ pos += 1
669
+ end
670
+ params
666
671
  end
667
- params
668
- end
669
672
 
670
- def resolve_default_short_options
671
- @order.each do |type, name|
672
- next unless type == :opt
673
- opts = @specs[name]
674
- next if opts[:short]
673
+ def resolve_default_short_options
674
+ @order.each do |type, name|
675
+ next unless type == :opt
675
676
 
676
- c = opts[:long].split(//).find { |d| d !~ INVALID_SHORT_ARG_REGEX && !@short.member?(d) }
677
- if c # found a character to use
678
- opts[:short] = c
679
- @short[c] = name
677
+ opts = @specs[name]
678
+ next if opts[:short]
679
+
680
+ c = opts[:long].split(//).find { |d| d !~ INVALID_SHORT_ARG_REGEX && !@short.member?(d) }
681
+ if c # found a character to use
682
+ opts[:short] = c
683
+ @short[c] = name
684
+ end
680
685
  end
681
686
  end
682
- end
683
687
 
684
- def wrap_line str, opts={}
685
- prefix = opts[:prefix] || 0
686
- width = opts[:width] || (self.width - 1)
687
- start = 0
688
- ret = []
689
- until start > str.length
690
- nextt =
691
- if start + width >= str.length
692
- str.length
693
- else
694
- x = str.rindex(/\s/, start + width)
695
- x = str.index(/\s/, start) if x && x < start
696
- x || str.length
697
- end
698
- ret << (ret.empty? ? "" : " " * prefix) + str[start ... nextt]
699
- start = nextt + 1
688
+ def wrap_line str, opts={}
689
+ prefix = opts[:prefix] || 0
690
+ width = opts[:width] || (self.width - 1)
691
+ start = 0
692
+ ret = []
693
+ until start > str.length
694
+ nextt =
695
+ if start + width >= str.length
696
+ str.length
697
+ else
698
+ x = str.rindex(/\s/, start + width)
699
+ x = str.index(/\s/, start) if x && x < start
700
+ x || str.length
701
+ end
702
+ ret << (ret.empty? ? "" : " " * prefix) + str[start ... nextt]
703
+ start = nextt + 1
704
+ end
705
+ ret
700
706
  end
701
- ret
702
- end
703
707
 
704
- ## instance_eval but with ability to handle block arguments
705
- ## thanks to why: http://redhanded.hobix.com/inspect/aBlockCostume.html
706
- def cloaker &b
707
- (class << self; self; end).class_eval do
708
- define_method :cloaker_, &b
709
- meth = instance_method :cloaker_
710
- remove_method :cloaker_
711
- meth
708
+ ## instance_eval but with ability to handle block arguments
709
+ ## thanks to why: http://redhanded.hobix.com/inspect/aBlockCostume.html
710
+ def cloaker &b
711
+ (class << self; self; end).class_eval do
712
+ define_method :cloaker_, &b
713
+ meth = instance_method :cloaker_
714
+ remove_method :cloaker_
715
+ meth
716
+ end
712
717
  end
713
718
  end
714
- end
715
-
716
- ## The easy, syntactic-sugary entry method into Trollop. Creates a Parser,
717
- ## passes the block to it, then parses +args+ with it, handling any errors or
718
- ## requests for help or version information appropriately (and then exiting).
719
- ## Modifies +args+ in place. Returns a hash of option values.
720
- ##
721
- ## The block passed in should contain zero or more calls to +opt+
722
- ## (Parser#opt), zero or more calls to +text+ (Parser#text), and
723
- ## probably a call to +version+ (Parser#version).
724
- ##
725
- ## The returned block contains a value for every option specified with
726
- ## +opt+. The value will be the value given on the commandline, or the
727
- ## default value if the option was not specified on the commandline. For
728
- ## every option specified on the commandline, a key "<option
729
- ## name>_given" will also be set in the hash.
730
- ##
731
- ## Example:
732
- ##
733
- ## require 'trollop'
734
- ## opts = Trollop::options do
735
- ## opt :monkey, "Use monkey mode" # a flag --monkey, defaulting to false
736
- ## opt :goat, "Use goat mode", :default => true # a flag --goat, defaulting to true
737
- ## opt :num_limbs, "Number of limbs", :default => 4 # an integer --num-limbs <i>, defaulting to 4
738
- ## opt :num_thumbs, "Number of thumbs", :type => :int # an integer --num-thumbs <i>, defaulting to nil
739
- ## end
740
- ##
741
- ## ## if called with no arguments
742
- ## p opts # => { :monkey => false, :goat => true, :num_limbs => 4, :num_thumbs => nil }
743
- ##
744
- ## ## if called with --monkey
745
- ## p opts # => {:monkey_given=>true, :monkey=>true, :goat=>true, :num_limbs=>4, :help=>false, :num_thumbs=>nil}
746
- ##
747
- ## See more examples at http://trollop.rubyforge.org.
748
- def options args=ARGV, *a, &b
749
- @last_parser = Parser.new(*a, &b)
750
- with_standard_exception_handling(@last_parser) { @last_parser.parse args }
751
- end
752
719
 
753
- ## If Trollop::options doesn't do quite what you want, you can create a Parser
754
- ## object and call Parser#parse on it. That method will throw CommandlineError,
755
- ## HelpNeeded and VersionNeeded exceptions when necessary; if you want to
756
- ## have these handled for you in the standard manner (e.g. show the help
757
- ## and then exit upon an HelpNeeded exception), call your code from within
758
- ## a block passed to this method.
759
- ##
760
- ## Note that this method will call System#exit after handling an exception!
761
- ##
762
- ## Usage example:
763
- ##
764
- ## require 'trollop'
765
- ## p = Trollop::Parser.new do
766
- ## opt :monkey, "Use monkey mode" # a flag --monkey, defaulting to false
767
- ## opt :goat, "Use goat mode", :default => true # a flag --goat, defaulting to true
768
- ## end
769
- ##
770
- ## opts = Trollop::with_standard_exception_handling p do
771
- ## o = p.parse ARGV
772
- ## raise Trollop::HelpNeeded if ARGV.empty? # show help screen
773
- ## o
774
- ## end
775
- ##
776
- ## Requires passing in the parser object.
777
-
778
- def with_standard_exception_handling parser
779
- begin
780
- yield
781
- rescue CommandlineError => e
782
- $stderr.puts _("Error: %{value0}.") % { value0: e.message }
783
- $stderr.puts _("Try --help for help.")
784
- exit(-1)
785
- rescue HelpNeeded
786
- parser.educate
787
- exit
788
- rescue VersionNeeded
789
- puts parser.version
790
- exit
720
+ ## The easy, syntactic-sugary entry method into Trollop. Creates a Parser,
721
+ ## passes the block to it, then parses +args+ with it, handling any errors or
722
+ ## requests for help or version information appropriately (and then exiting).
723
+ ## Modifies +args+ in place. Returns a hash of option values.
724
+ ##
725
+ ## The block passed in should contain zero or more calls to +opt+
726
+ ## (Parser#opt), zero or more calls to +text+ (Parser#text), and
727
+ ## probably a call to +version+ (Parser#version).
728
+ ##
729
+ ## The returned block contains a value for every option specified with
730
+ ## +opt+. The value will be the value given on the commandline, or the
731
+ ## default value if the option was not specified on the commandline. For
732
+ ## every option specified on the commandline, a key "<option
733
+ ## name>_given" will also be set in the hash.
734
+ ##
735
+ ## Example:
736
+ ##
737
+ ## require 'trollop'
738
+ ## opts = Trollop::options do
739
+ ## opt :monkey, "Use monkey mode" # a flag --monkey, defaulting to false
740
+ ## opt :goat, "Use goat mode", :default => true # a flag --goat, defaulting to true
741
+ ## opt :num_limbs, "Number of limbs", :default => 4 # an integer --num-limbs <i>, defaulting to 4
742
+ ## opt :num_thumbs, "Number of thumbs", :type => :int # an integer --num-thumbs <i>, defaulting to nil
743
+ ## end
744
+ ##
745
+ ## ## if called with no arguments
746
+ ## p opts # => { :monkey => false, :goat => true, :num_limbs => 4, :num_thumbs => nil }
747
+ ##
748
+ ## ## if called with --monkey
749
+ ## p opts # => {:monkey_given=>true, :monkey=>true, :goat=>true, :num_limbs=>4, :help=>false, :num_thumbs=>nil}
750
+ ##
751
+ ## See more examples at http://trollop.rubyforge.org.
752
+ def options args=ARGV, *a, &b
753
+ @last_parser = Parser.new(*a, &b)
754
+ with_standard_exception_handling(@last_parser) { @last_parser.parse args }
791
755
  end
792
- end
793
756
 
794
- ## Informs the user that their usage of 'arg' was wrong, as detailed by
795
- ## 'msg', and dies. Example:
796
- ##
797
- ## options do
798
- ## opt :volume, :default => 0.0
799
- ## end
800
- ##
801
- ## die :volume, "too loud" if opts[:volume] > 10.0
802
- ## die :volume, "too soft" if opts[:volume] < 0.1
803
- ##
804
- ## In the one-argument case, simply print that message, a notice
805
- ## about -h, and die. Example:
806
- ##
807
- ## options do
808
- ## opt :whatever # ...
809
- ## end
810
- ##
811
- ## Trollop::die "need at least one filename" if ARGV.empty?
812
- def die arg, msg=nil
813
- if @last_parser
814
- @last_parser.die arg, msg
815
- else
816
- #TRANSLATORS 'Trollop' is the name of a module and 'die' and 'options' are methods in it and should not be translated.
817
- raise ArgumentError, _("Trollop::die can only be called after Trollop::options")
757
+ ## If Trollop::options doesn't do quite what you want, you can create a Parser
758
+ ## object and call Parser#parse on it. That method will throw CommandlineError,
759
+ ## HelpNeeded and VersionNeeded exceptions when necessary; if you want to
760
+ ## have these handled for you in the standard manner (e.g. show the help
761
+ ## and then exit upon an HelpNeeded exception), call your code from within
762
+ ## a block passed to this method.
763
+ ##
764
+ ## Note that this method will call System#exit after handling an exception!
765
+ ##
766
+ ## Usage example:
767
+ ##
768
+ ## require 'trollop'
769
+ ## p = Trollop::Parser.new do
770
+ ## opt :monkey, "Use monkey mode" # a flag --monkey, defaulting to false
771
+ ## opt :goat, "Use goat mode", :default => true # a flag --goat, defaulting to true
772
+ ## end
773
+ ##
774
+ ## opts = Trollop::with_standard_exception_handling p do
775
+ ## o = p.parse ARGV
776
+ ## raise Trollop::HelpNeeded if ARGV.empty? # show help screen
777
+ ## o
778
+ ## end
779
+ ##
780
+ ## Requires passing in the parser object.
781
+
782
+ def with_standard_exception_handling parser
783
+ begin
784
+ yield
785
+ rescue CommandlineError => e
786
+ $stderr.puts _("Error: %{value0}.") % { value0: e.message }
787
+ $stderr.puts _("Try --help for help.")
788
+ exit(-1)
789
+ rescue HelpNeeded
790
+ parser.educate
791
+ exit
792
+ rescue VersionNeeded
793
+ puts parser.version
794
+ exit
795
+ end
818
796
  end
819
- end
820
797
 
821
- module_function :options, :die, :with_standard_exception_handling
798
+ ## Informs the user that their usage of 'arg' was wrong, as detailed by
799
+ ## 'msg', and dies. Example:
800
+ ##
801
+ ## options do
802
+ ## opt :volume, :default => 0.0
803
+ ## end
804
+ ##
805
+ ## die :volume, "too loud" if opts[:volume] > 10.0
806
+ ## die :volume, "too soft" if opts[:volume] < 0.1
807
+ ##
808
+ ## In the one-argument case, simply print that message, a notice
809
+ ## about -h, and die. Example:
810
+ ##
811
+ ## options do
812
+ ## opt :whatever # ...
813
+ ## end
814
+ ##
815
+ ## Trollop::die "need at least one filename" if ARGV.empty?
816
+ def die arg, msg=nil
817
+ if @last_parser
818
+ @last_parser.die arg, msg
819
+ else
820
+ # TRANSLATORS 'Trollop' is the name of a module and 'die' and 'options' are methods in it and should not be translated.
821
+ raise ArgumentError, _("Trollop::die can only be called after Trollop::options")
822
+ end
823
+ end
822
824
 
823
- end # module
825
+ module_function :options, :die, :with_standard_exception_handling
826
+ end # module
824
827
  end
825
828
  end
826
829
  end