boxcar 0.10005.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (453) hide show
  1. data/.gitignore +48 -0
  2. data/.gitsetup.yml +6 -0
  3. data/.yardopts +1 -0
  4. data/CHANGELOG.md +696 -0
  5. data/Gemfile +5 -0
  6. data/Gemfile.lock +40 -0
  7. data/LICENSE +21 -0
  8. data/README.md +91 -0
  9. data/Rakefile +18 -0
  10. data/VERSION +1 -0
  11. data/bin/_bump +126 -0
  12. data/bin/_jason +172 -0
  13. data/bin/_log4sh +3840 -0
  14. data/bin/_meat +172 -0
  15. data/bin/_prime +8 -0
  16. data/bin/_shflags +1012 -0
  17. data/bin/_shunit +1048 -0
  18. data/bin/_sub +37 -0
  19. data/bin/_treadstone +8 -0
  20. data/bin/_versions +174 -0
  21. data/bin/build +15 -0
  22. data/bin/bump +15 -0
  23. data/bin/edit +15 -0
  24. data/bin/publish +15 -0
  25. data/bin/stub +15 -0
  26. data/bin/vagrant +60 -0
  27. data/boxcar.gemspec +32 -0
  28. data/config/default.rb +30 -0
  29. data/contrib/README.md +12 -0
  30. data/contrib/emacs/vagrant.el +8 -0
  31. data/contrib/vim/vagrantfile.vim +9 -0
  32. data/keys/README.md +17 -0
  33. data/keys/vagrant +27 -0
  34. data/keys/vagrant.pub +1 -0
  35. data/lib/development.rb +25 -0
  36. data/lib/vagrant.rb +197 -0
  37. data/lib/vagrant/action.rb +63 -0
  38. data/lib/vagrant/action/box/destroy.rb +25 -0
  39. data/lib/vagrant/action/box/download.rb +84 -0
  40. data/lib/vagrant/action/box/package.rb +19 -0
  41. data/lib/vagrant/action/box/unpackage.rb +61 -0
  42. data/lib/vagrant/action/box/verify.rb +23 -0
  43. data/lib/vagrant/action/builder.rb +128 -0
  44. data/lib/vagrant/action/builtin.rb +171 -0
  45. data/lib/vagrant/action/env/set.rb +21 -0
  46. data/lib/vagrant/action/environment.rb +12 -0
  47. data/lib/vagrant/action/general/check_virtualbox.rb +28 -0
  48. data/lib/vagrant/action/general/package.rb +101 -0
  49. data/lib/vagrant/action/general/validate.rb +18 -0
  50. data/lib/vagrant/action/runner.rb +53 -0
  51. data/lib/vagrant/action/vm/boot.rb +53 -0
  52. data/lib/vagrant/action/vm/check_accessible.rb +23 -0
  53. data/lib/vagrant/action/vm/check_box.rb +33 -0
  54. data/lib/vagrant/action/vm/check_guest_additions.rb +38 -0
  55. data/lib/vagrant/action/vm/check_port_collisions.rb +89 -0
  56. data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
  57. data/lib/vagrant/action/vm/clear_forwarded_ports.rb +18 -0
  58. data/lib/vagrant/action/vm/clear_network_interfaces.rb +31 -0
  59. data/lib/vagrant/action/vm/clear_shared_folders.rb +18 -0
  60. data/lib/vagrant/action/vm/customize.rb +36 -0
  61. data/lib/vagrant/action/vm/default_name.rb +22 -0
  62. data/lib/vagrant/action/vm/destroy.rb +19 -0
  63. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +20 -0
  64. data/lib/vagrant/action/vm/discard_state.rb +22 -0
  65. data/lib/vagrant/action/vm/export.rb +57 -0
  66. data/lib/vagrant/action/vm/forward_ports.rb +92 -0
  67. data/lib/vagrant/action/vm/halt.rb +32 -0
  68. data/lib/vagrant/action/vm/host_name.rb +21 -0
  69. data/lib/vagrant/action/vm/import.rb +48 -0
  70. data/lib/vagrant/action/vm/match_mac_address.rb +21 -0
  71. data/lib/vagrant/action/vm/network.rb +403 -0
  72. data/lib/vagrant/action/vm/nfs.rb +196 -0
  73. data/lib/vagrant/action/vm/package.rb +23 -0
  74. data/lib/vagrant/action/vm/package_vagrantfile.rb +36 -0
  75. data/lib/vagrant/action/vm/provision.rb +61 -0
  76. data/lib/vagrant/action/vm/provisioner_cleanup.rb +26 -0
  77. data/lib/vagrant/action/vm/prune_nfs_exports.rb +20 -0
  78. data/lib/vagrant/action/vm/resume.rb +20 -0
  79. data/lib/vagrant/action/vm/sane_defaults.rb +78 -0
  80. data/lib/vagrant/action/vm/setup_package_files.rb +54 -0
  81. data/lib/vagrant/action/vm/share_folders.rb +114 -0
  82. data/lib/vagrant/action/vm/suspend.rb +20 -0
  83. data/lib/vagrant/action/warden.rb +92 -0
  84. data/lib/vagrant/box.rb +44 -0
  85. data/lib/vagrant/box_collection.rb +58 -0
  86. data/lib/vagrant/cli.rb +76 -0
  87. data/lib/vagrant/command.rb +24 -0
  88. data/lib/vagrant/command/base.rb +167 -0
  89. data/lib/vagrant/command/box.rb +58 -0
  90. data/lib/vagrant/command/box_add.rb +37 -0
  91. data/lib/vagrant/command/box_list.rb +28 -0
  92. data/lib/vagrant/command/box_remove.rb +27 -0
  93. data/lib/vagrant/command/box_repackage.rb +27 -0
  94. data/lib/vagrant/command/destroy.rb +64 -0
  95. data/lib/vagrant/command/gem.rb +39 -0
  96. data/lib/vagrant/command/halt.rb +39 -0
  97. data/lib/vagrant/command/init.rb +40 -0
  98. data/lib/vagrant/command/package.rb +75 -0
  99. data/lib/vagrant/command/provision.rb +40 -0
  100. data/lib/vagrant/command/reload.rb +39 -0
  101. data/lib/vagrant/command/resume.rb +33 -0
  102. data/lib/vagrant/command/ssh.rb +90 -0
  103. data/lib/vagrant/command/ssh_config.rb +51 -0
  104. data/lib/vagrant/command/start_mixins.rb +26 -0
  105. data/lib/vagrant/command/status.rb +36 -0
  106. data/lib/vagrant/command/suspend.rb +33 -0
  107. data/lib/vagrant/command/up.rb +40 -0
  108. data/lib/vagrant/communication.rb +7 -0
  109. data/lib/vagrant/communication/base.rb +56 -0
  110. data/lib/vagrant/communication/ssh.rb +229 -0
  111. data/lib/vagrant/config.rb +49 -0
  112. data/lib/vagrant/config/base.rb +82 -0
  113. data/lib/vagrant/config/container.rb +37 -0
  114. data/lib/vagrant/config/error_recorder.rb +19 -0
  115. data/lib/vagrant/config/loader.rb +127 -0
  116. data/lib/vagrant/config/nfs.rb +8 -0
  117. data/lib/vagrant/config/package.rb +7 -0
  118. data/lib/vagrant/config/ssh.rb +27 -0
  119. data/lib/vagrant/config/top.rb +72 -0
  120. data/lib/vagrant/config/vagrant.rb +14 -0
  121. data/lib/vagrant/config/vm.rb +168 -0
  122. data/lib/vagrant/config/vm/provisioner.rb +52 -0
  123. data/lib/vagrant/config/vm/sub_vm.rb +17 -0
  124. data/lib/vagrant/data_store.rb +92 -0
  125. data/lib/vagrant/downloaders.rb +7 -0
  126. data/lib/vagrant/downloaders/base.rb +25 -0
  127. data/lib/vagrant/downloaders/file.rb +22 -0
  128. data/lib/vagrant/downloaders/http.rb +97 -0
  129. data/lib/vagrant/driver.rb +8 -0
  130. data/lib/vagrant/driver/virtualbox.rb +134 -0
  131. data/lib/vagrant/driver/virtualbox_4_0.rb +459 -0
  132. data/lib/vagrant/driver/virtualbox_4_1.rb +459 -0
  133. data/lib/vagrant/driver/virtualbox_4_2.rb +606 -0
  134. data/lib/vagrant/driver/virtualbox_base.rb +309 -0
  135. data/lib/vagrant/environment.rb +517 -0
  136. data/lib/vagrant/errors.rb +441 -0
  137. data/lib/vagrant/guest.rb +18 -0
  138. data/lib/vagrant/guest/arch.rb +56 -0
  139. data/lib/vagrant/guest/base.rb +99 -0
  140. data/lib/vagrant/guest/debian.rb +64 -0
  141. data/lib/vagrant/guest/fedora.rb +66 -0
  142. data/lib/vagrant/guest/freebsd.rb +86 -0
  143. data/lib/vagrant/guest/gentoo.rb +46 -0
  144. data/lib/vagrant/guest/linux.rb +118 -0
  145. data/lib/vagrant/guest/linux/config.rb +19 -0
  146. data/lib/vagrant/guest/linux/error.rb +9 -0
  147. data/lib/vagrant/guest/openbsd.rb +20 -0
  148. data/lib/vagrant/guest/redhat.rb +67 -0
  149. data/lib/vagrant/guest/solaris.rb +118 -0
  150. data/lib/vagrant/guest/suse.rb +9 -0
  151. data/lib/vagrant/guest/ubuntu.rb +23 -0
  152. data/lib/vagrant/hosts.rb +37 -0
  153. data/lib/vagrant/hosts/arch.rb +55 -0
  154. data/lib/vagrant/hosts/base.rb +66 -0
  155. data/lib/vagrant/hosts/bsd.rb +97 -0
  156. data/lib/vagrant/hosts/fedora.rb +47 -0
  157. data/lib/vagrant/hosts/freebsd.rb +41 -0
  158. data/lib/vagrant/hosts/gentoo.rb +20 -0
  159. data/lib/vagrant/hosts/linux.rb +94 -0
  160. data/lib/vagrant/hosts/opensuse.rb +30 -0
  161. data/lib/vagrant/hosts/windows.rb +16 -0
  162. data/lib/vagrant/plugin.rb +81 -0
  163. data/lib/vagrant/provisioners.rb +12 -0
  164. data/lib/vagrant/provisioners/base.rb +44 -0
  165. data/lib/vagrant/provisioners/chef.rb +168 -0
  166. data/lib/vagrant/provisioners/chef_client.rb +132 -0
  167. data/lib/vagrant/provisioners/chef_solo.rb +234 -0
  168. data/lib/vagrant/provisioners/puppet.rb +175 -0
  169. data/lib/vagrant/provisioners/puppet_server.rb +78 -0
  170. data/lib/vagrant/provisioners/shell.rb +96 -0
  171. data/lib/vagrant/registry.rb +52 -0
  172. data/lib/vagrant/ssh.rb +126 -0
  173. data/lib/vagrant/test_helpers.rb +154 -0
  174. data/lib/vagrant/ui.rb +168 -0
  175. data/lib/vagrant/util.rb +12 -0
  176. data/lib/vagrant/util/ansi_escape_code_remover.rb +34 -0
  177. data/lib/vagrant/util/busy.rb +59 -0
  178. data/lib/vagrant/util/counter.rb +24 -0
  179. data/lib/vagrant/util/file_checksum.rb +38 -0
  180. data/lib/vagrant/util/file_mode.rb +12 -0
  181. data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
  182. data/lib/vagrant/util/is_port_open.rb +38 -0
  183. data/lib/vagrant/util/line_ending_helpers.rb +14 -0
  184. data/lib/vagrant/util/network_ip.rb +28 -0
  185. data/lib/vagrant/util/platform.rb +68 -0
  186. data/lib/vagrant/util/retryable.rb +25 -0
  187. data/lib/vagrant/util/safe_exec.rb +36 -0
  188. data/lib/vagrant/util/safe_puts.rb +31 -0
  189. data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
  190. data/lib/vagrant/util/subprocess.rb +247 -0
  191. data/lib/vagrant/util/template_renderer.rb +83 -0
  192. data/lib/vagrant/version.rb +7 -0
  193. data/lib/vagrant/vm.rb +195 -0
  194. data/libexec/build +30 -0
  195. data/libexec/build-gem +30 -0
  196. data/libexec/bump +32 -0
  197. data/libexec/edit-gem +81 -0
  198. data/libexec/publish +58 -0
  199. data/libexec/publish-gem +58 -0
  200. data/libexec/stub-prepare +37 -0
  201. data/tasks/acceptance.rake +113 -0
  202. data/tasks/bundler.rake +3 -0
  203. data/tasks/test.rake +20 -0
  204. data/templates/commands/init/Vagrantfile.erb +99 -0
  205. data/templates/commands/ssh_config/config.erb +15 -0
  206. data/templates/config/validation_failed.erb +7 -0
  207. data/templates/guests/arch/network_dhcp.erb +7 -0
  208. data/templates/guests/arch/network_static.erb +7 -0
  209. data/templates/guests/debian/network_dhcp.erb +6 -0
  210. data/templates/guests/debian/network_static.erb +7 -0
  211. data/templates/guests/fedora/network_dhcp.erb +6 -0
  212. data/templates/guests/fedora/network_static.erb +13 -0
  213. data/templates/guests/freebsd/network_dhcp.erb +3 -0
  214. data/templates/guests/freebsd/network_static.erb +3 -0
  215. data/templates/guests/gentoo/network_dhcp.erb +4 -0
  216. data/templates/guests/gentoo/network_static.erb +4 -0
  217. data/templates/guests/redhat/network_dhcp.erb +6 -0
  218. data/templates/guests/redhat/network_static.erb +7 -0
  219. data/templates/locales/en.yml +747 -0
  220. data/templates/nfs/exports.erb +5 -0
  221. data/templates/nfs/exports_freebsd.erb +5 -0
  222. data/templates/nfs/exports_linux.erb +5 -0
  223. data/templates/package_Vagrantfile.erb +11 -0
  224. data/templates/provisioners/chef_client/client.erb +32 -0
  225. data/templates/provisioners/chef_solo/solo.erb +25 -0
  226. data/test/acceptance/base.rb +48 -0
  227. data/test/acceptance/box_test.rb +99 -0
  228. data/test/acceptance/destroy_test.rb +37 -0
  229. data/test/acceptance/halt_test.rb +72 -0
  230. data/test/acceptance/init_test.rb +33 -0
  231. data/test/acceptance/networking/host_only_test.rb +37 -0
  232. data/test/acceptance/networking/port_forward_test.rb +125 -0
  233. data/test/acceptance/package_test.rb +46 -0
  234. data/test/acceptance/provisioning/basic_test.rb +61 -0
  235. data/test/acceptance/provisioning/chef_solo_test.rb +37 -0
  236. data/test/acceptance/provisioning/shell_test.rb +53 -0
  237. data/test/acceptance/resume_test.rb +17 -0
  238. data/test/acceptance/shared_folders_test.rb +84 -0
  239. data/test/acceptance/skeletons/chef_solo_basic/README.md +3 -0
  240. data/test/acceptance/skeletons/chef_solo_basic/cookbooks/basic/recipes/default.rb +5 -0
  241. data/test/acceptance/skeletons/chef_solo_json/README.md +3 -0
  242. data/test/acceptance/skeletons/chef_solo_json/cookbooks/basic/recipes/default.rb +6 -0
  243. data/test/acceptance/skeletons/provisioner_multi/README.md +3 -0
  244. data/test/acceptance/skeletons/provisioner_multi/cookbooks/basic/recipes/default.rb +5 -0
  245. data/test/acceptance/ssh_test.rb +46 -0
  246. data/test/acceptance/support/config.rb +42 -0
  247. data/test/acceptance/support/isolated_environment.rb +117 -0
  248. data/test/acceptance/support/matchers/have_color.rb +9 -0
  249. data/test/acceptance/support/matchers/match_output.rb +14 -0
  250. data/test/acceptance/support/matchers/succeed.rb +14 -0
  251. data/test/acceptance/support/network_tests.rb +29 -0
  252. data/test/acceptance/support/output.rb +95 -0
  253. data/test/acceptance/support/shared/base_context.rb +72 -0
  254. data/test/acceptance/support/shared/command_examples.rb +33 -0
  255. data/test/acceptance/support/virtualbox.rb +36 -0
  256. data/test/acceptance/suspend_test.rb +56 -0
  257. data/test/acceptance/up_basic_test.rb +33 -0
  258. data/test/acceptance/up_with_box_url.rb +40 -0
  259. data/test/acceptance/vagrant_test.rb +47 -0
  260. data/test/acceptance/version_test.rb +15 -0
  261. data/test/buildbot/README.md +72 -0
  262. data/test/buildbot/buildbot_config/__init__.py +0 -0
  263. data/test/buildbot/buildbot_config/config/__init__.py +0 -0
  264. data/test/buildbot/buildbot_config/config/loader.py +24 -0
  265. data/test/buildbot/buildbot_config/config/master.py +24 -0
  266. data/test/buildbot/buildbot_config/config/slave.py +22 -0
  267. data/test/buildbot/buildbot_config/master/__init__.py +6 -0
  268. data/test/buildbot/buildbot_config/master/builders.py +78 -0
  269. data/test/buildbot/buildbot_config/master/buildsteps.py +100 -0
  270. data/test/buildbot/buildbot_config/master/change_sources.py +8 -0
  271. data/test/buildbot/buildbot_config/master/schedulers.py +32 -0
  272. data/test/buildbot/buildbot_config/master/slaves.py +60 -0
  273. data/test/buildbot/buildbot_config/master/status.py +52 -0
  274. data/test/buildbot/master/Makefile.sample +28 -0
  275. data/test/buildbot/master/buildbot.tac +36 -0
  276. data/test/buildbot/master/master.cfg +67 -0
  277. data/test/buildbot/master/public_html/bg_gradient.jpg +0 -0
  278. data/test/buildbot/master/public_html/default.css +545 -0
  279. data/test/buildbot/master/public_html/favicon.ico +0 -0
  280. data/test/buildbot/master/public_html/robots.txt +10 -0
  281. data/test/buildbot/master/public_html/static/css/bootstrap-1.4.0.min.css +356 -0
  282. data/test/buildbot/master/public_html/static/css/prettify.css +97 -0
  283. data/test/buildbot/master/public_html/static/css/syntax.css +60 -0
  284. data/test/buildbot/master/public_html/static/css/vagrant.base.css +205 -0
  285. data/test/buildbot/master/public_html/static/images/base_box_mac.jpg +0 -0
  286. data/test/buildbot/master/public_html/static/images/getting-started/success.jpg +0 -0
  287. data/test/buildbot/master/public_html/static/images/icons/error.png +0 -0
  288. data/test/buildbot/master/public_html/static/images/vagrant_chilling.png +0 -0
  289. data/test/buildbot/master/public_html/static/images/vagrant_holding.png +0 -0
  290. data/test/buildbot/master/public_html/static/images/vagrant_looking.png +0 -0
  291. data/test/buildbot/master/public_html/static/images/windows/alter_path.jpg +0 -0
  292. data/test/buildbot/master/public_html/static/images/windows/edit_path.jpg +0 -0
  293. data/test/buildbot/master/public_html/static/images/windows/environment_variables_button.jpg +0 -0
  294. data/test/buildbot/master/public_html/static/images/windows/port_and_ppk_path.jpg +0 -0
  295. data/test/buildbot/master/public_html/static/images/windows/ppk_selection.jpg +0 -0
  296. data/test/buildbot/master/public_html/static/images/windows/putty_first_screen.jpg +0 -0
  297. data/test/buildbot/master/public_html/static/images/windows/save_result.jpg +0 -0
  298. data/test/buildbot/master/public_html/static/images/windows/vbox_manage_default_location.jpg +0 -0
  299. data/test/buildbot/master/public_html/static/js/bootstrap-tabs.js +80 -0
  300. data/test/buildbot/master/public_html/static/js/jquery-1.7.min.js +4 -0
  301. data/test/buildbot/master/templates/authfail.html +9 -0
  302. data/test/buildbot/master/templates/build.html +205 -0
  303. data/test/buildbot/master/templates/builder.html +118 -0
  304. data/test/buildbot/master/templates/builders.html +33 -0
  305. data/test/buildbot/master/templates/buildslave.html +72 -0
  306. data/test/buildbot/master/templates/buildslaves.html +70 -0
  307. data/test/buildbot/master/templates/change.html +15 -0
  308. data/test/buildbot/master/templates/layouts/base.html +58 -0
  309. data/test/buildbot/master/templates/macros/box.html +37 -0
  310. data/test/buildbot/master/templates/macros/build_line.html +50 -0
  311. data/test/buildbot/master/templates/macros/change.html +81 -0
  312. data/test/buildbot/master/templates/macros/forms.html +300 -0
  313. data/test/buildbot/master/templates/root.html +42 -0
  314. data/test/buildbot/master/templates/waterfall.html +53 -0
  315. data/test/buildbot/requirements.txt +4 -0
  316. data/test/buildbot/scripts/deploy.sh +38 -0
  317. data/test/buildbot/scripts/setup.sh +107 -0
  318. data/test/buildbot/slave/buildbot.tac +43 -0
  319. data/test/buildbot/slave/info/admin +1 -0
  320. data/test/buildbot/slave/info/host +1 -0
  321. data/test/buildbot/tests/__init__.py +0 -0
  322. data/test/buildbot/tests/master/__init__.py +0 -0
  323. data/test/buildbot/tests/master/test_slaves.py +41 -0
  324. data/test/buildbot/vendor/choices-0.4.0.tar.gz +0 -0
  325. data/test/config/acceptance_boxes.yml +7 -0
  326. data/test/support/isolated_environment.rb +46 -0
  327. data/test/support/tempdir.rb +34 -0
  328. data/test/unit/base.rb +21 -0
  329. data/test/unit/support/isolated_environment.rb +47 -0
  330. data/test/unit/support/shared/base_context.rb +30 -0
  331. data/test/unit/vagrant/action/builder_test.rb +156 -0
  332. data/test/unit/vagrant/action/environment_test.rb +16 -0
  333. data/test/unit/vagrant/action/runner_test.rb +65 -0
  334. data/test/unit/vagrant/action/warden_test.rb +92 -0
  335. data/test/unit/vagrant/box_collection_test.rb +56 -0
  336. data/test/unit/vagrant/box_test.rb +34 -0
  337. data/test/unit/vagrant/command/base_test.rb +150 -0
  338. data/test/unit/vagrant/config/base_test.rb +48 -0
  339. data/test/unit/vagrant/config/loader_test.rb +79 -0
  340. data/test/unit/vagrant/config/ssh_test.rb +17 -0
  341. data/test/unit/vagrant/config/top_test.rb +69 -0
  342. data/test/unit/vagrant/config/vm_test.rb +71 -0
  343. data/test/unit/vagrant/config_test.rb +27 -0
  344. data/test/unit/vagrant/data_store_test.rb +79 -0
  345. data/test/unit/vagrant/downloaders/base_test.rb +18 -0
  346. data/test/unit/vagrant/downloaders/file_test.rb +75 -0
  347. data/test/unit/vagrant/downloaders/http_test.rb +19 -0
  348. data/test/unit/vagrant/environment_test.rb +212 -0
  349. data/test/unit/vagrant/hosts_test.rb +36 -0
  350. data/test/unit/vagrant/registry_test.rb +74 -0
  351. data/test/unit/vagrant/util/ansi_escape_code_remover_test.rb +16 -0
  352. data/test/unit/vagrant/util/file_checksum_test.rb +23 -0
  353. data/test/unit/vagrant/util/hash_with_indifferent_access_test.rb +38 -0
  354. data/test/unit/vagrant/util/is_port_open_test.rb +53 -0
  355. data/test/unit/vagrant/util/line_endings_helper_test.rb +16 -0
  356. data/test/unit/vagrant/util/network_ip_test.rb +17 -0
  357. data/test/unit/vagrant/util/retryable_test.rb +106 -0
  358. data/test/unit/vagrant_test.rb +27 -0
  359. data/test/unit_legacy/locales/en.yml +8 -0
  360. data/test/unit_legacy/test_helper.rb +32 -0
  361. data/test/unit_legacy/vagrant/action/box/destroy_test.rb +18 -0
  362. data/test/unit_legacy/vagrant/action/box/download_test.rb +125 -0
  363. data/test/unit_legacy/vagrant/action/box/package_test.rb +25 -0
  364. data/test/unit_legacy/vagrant/action/box/unpackage_test.rb +84 -0
  365. data/test/unit_legacy/vagrant/action/box/verify_test.rb +30 -0
  366. data/test/unit_legacy/vagrant/action/env/set_test.rb +24 -0
  367. data/test/unit_legacy/vagrant/action/general/package_test.rb +268 -0
  368. data/test/unit_legacy/vagrant/action/general/validate_test.rb +31 -0
  369. data/test/unit_legacy/vagrant/action/vm/boot_test.rb +66 -0
  370. data/test/unit_legacy/vagrant/action/vm/check_accessible_test.rb +61 -0
  371. data/test/unit_legacy/vagrant/action/vm/check_box_test.rb +61 -0
  372. data/test/unit_legacy/vagrant/action/vm/check_guest_additions_test.rb +9 -0
  373. data/test/unit_legacy/vagrant/action/vm/clean_machine_folder_test.rb +84 -0
  374. data/test/unit_legacy/vagrant/action/vm/clear_forwarded_ports_test.rb +52 -0
  375. data/test/unit_legacy/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
  376. data/test/unit_legacy/vagrant/action/vm/clear_shared_folders_test.rb +40 -0
  377. data/test/unit_legacy/vagrant/action/vm/customize_test.rb +37 -0
  378. data/test/unit_legacy/vagrant/action/vm/destroy_test.rb +25 -0
  379. data/test/unit_legacy/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +49 -0
  380. data/test/unit_legacy/vagrant/action/vm/discard_state_test.rb +45 -0
  381. data/test/unit_legacy/vagrant/action/vm/export_test.rb +107 -0
  382. data/test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb +77 -0
  383. data/test/unit_legacy/vagrant/action/vm/forward_ports_test.rb +197 -0
  384. data/test/unit_legacy/vagrant/action/vm/halt_test.rb +79 -0
  385. data/test/unit_legacy/vagrant/action/vm/host_name_test.rb +36 -0
  386. data/test/unit_legacy/vagrant/action/vm/import_test.rb +66 -0
  387. data/test/unit_legacy/vagrant/action/vm/match_mac_address_test.rb +40 -0
  388. data/test/unit_legacy/vagrant/action/vm/modify_test.rb +38 -0
  389. data/test/unit_legacy/vagrant/action/vm/network_test.rb +286 -0
  390. data/test/unit_legacy/vagrant/action/vm/nfs_helpers_test.rb +26 -0
  391. data/test/unit_legacy/vagrant/action/vm/nfs_test.rb +260 -0
  392. data/test/unit_legacy/vagrant/action/vm/package_test.rb +25 -0
  393. data/test/unit_legacy/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
  394. data/test/unit_legacy/vagrant/action/vm/provision_test.rb +65 -0
  395. data/test/unit_legacy/vagrant/action/vm/provisioner_cleanup_test.rb +56 -0
  396. data/test/unit_legacy/vagrant/action/vm/resume_test.rb +35 -0
  397. data/test/unit_legacy/vagrant/action/vm/share_folders_test.rb +144 -0
  398. data/test/unit_legacy/vagrant/action/vm/suspend_test.rb +35 -0
  399. data/test/unit_legacy/vagrant/action_test.rb +89 -0
  400. data/test/unit_legacy/vagrant/box_collection_test.rb +45 -0
  401. data/test/unit_legacy/vagrant/box_test.rb +74 -0
  402. data/test/unit_legacy/vagrant/cli_test.rb +35 -0
  403. data/test/unit_legacy/vagrant/command/base_test.rb +23 -0
  404. data/test/unit_legacy/vagrant/command/group_base_test.rb +15 -0
  405. data/test/unit_legacy/vagrant/command/helpers_test.rb +88 -0
  406. data/test/unit_legacy/vagrant/command/init_test.rb +10 -0
  407. data/test/unit_legacy/vagrant/command/package_test.rb +27 -0
  408. data/test/unit_legacy/vagrant/config/base_test.rb +52 -0
  409. data/test/unit_legacy/vagrant/config/error_recorder_test.rb +18 -0
  410. data/test/unit_legacy/vagrant/config/ssh_test.rb +12 -0
  411. data/test/unit_legacy/vagrant/config/vagrant_test.rb +35 -0
  412. data/test/unit_legacy/vagrant/config/vm/provisioner_test.rb +92 -0
  413. data/test/unit_legacy/vagrant/config/vm_test.rb +47 -0
  414. data/test/unit_legacy/vagrant/config_test.rb +148 -0
  415. data/test/unit_legacy/vagrant/downloaders/http_test.rb +93 -0
  416. data/test/unit_legacy/vagrant/environment_test.rb +539 -0
  417. data/test/unit_legacy/vagrant/errors_test.rb +42 -0
  418. data/test/unit_legacy/vagrant/hosts/base_test.rb +46 -0
  419. data/test/unit_legacy/vagrant/hosts/bsd_test.rb +53 -0
  420. data/test/unit_legacy/vagrant/hosts/linux_test.rb +54 -0
  421. data/test/unit_legacy/vagrant/plugin_test.rb +9 -0
  422. data/test/unit_legacy/vagrant/provisioners/base_test.rb +63 -0
  423. data/test/unit_legacy/vagrant/provisioners/chef_client_test.rb +190 -0
  424. data/test/unit_legacy/vagrant/provisioners/chef_solo_test.rb +115 -0
  425. data/test/unit_legacy/vagrant/provisioners/chef_test.rb +209 -0
  426. data/test/unit_legacy/vagrant/provisioners/puppet_server_test.rb +68 -0
  427. data/test/unit_legacy/vagrant/provisioners/puppet_test.rb +182 -0
  428. data/test/unit_legacy/vagrant/provisioners/shell_test.rb +79 -0
  429. data/test/unit_legacy/vagrant/ssh/session_test.rb +40 -0
  430. data/test/unit_legacy/vagrant/ssh_test.rb +304 -0
  431. data/test/unit_legacy/vagrant/systems/base_test.rb +18 -0
  432. data/test/unit_legacy/vagrant/systems/linux_test.rb +104 -0
  433. data/test/unit_legacy/vagrant/util/busy_test.rb +106 -0
  434. data/test/unit_legacy/vagrant/util/counter_test.rb +29 -0
  435. data/test/unit_legacy/vagrant/util/platform_test.rb +18 -0
  436. data/test/unit_legacy/vagrant/util/stacked_proc_runner_test.rb +43 -0
  437. data/test/unit_legacy/vagrant/util/template_renderer_test.rb +145 -0
  438. data/test/unit_legacy/vagrant/vm_test.rb +300 -0
  439. data/vagrant.gemspec +39 -0
  440. data/vendor/cache/contest-0.1.3.gem +0 -0
  441. data/vendor/cache/diff-lcs-1.1.3.gem +0 -0
  442. data/vendor/cache/erubis-2.7.0.gem +0 -0
  443. data/vendor/cache/i18n-0.6.1.gem +0 -0
  444. data/vendor/cache/json-1.5.4.gem +0 -0
  445. data/vendor/cache/log4r-1.1.10.gem +0 -0
  446. data/vendor/cache/metaclass-0.0.1.gem +0 -0
  447. data/vendor/cache/minitest-2.5.1.gem +0 -0
  448. data/vendor/cache/mocha-0.13.1.gem +0 -0
  449. data/vendor/cache/rake-10.0.2.gem +0 -0
  450. data/vendor/cache/rspec-core-2.8.0.gem +0 -0
  451. data/vendor/cache/rspec-expectations-2.8.0.gem +0 -0
  452. data/vendor/cache/rspec-mocks-2.8.0.gem +0 -0
  453. metadata +676 -0
@@ -0,0 +1,172 @@
1
+ #!/bin/bash
2
+
3
+ : ${__meat__:=x}
4
+ if [[ "$__meat__" != 'x' ]]; then
5
+ return 0
6
+ fi
7
+ __meat__='y'
8
+
9
+ if [[ -z "${shome:-}" ]]; then
10
+ shome="$(cd -P -- "$(dirname -- "${BASH_SOURCE}")/.." && pwd -P)"
11
+ fi
12
+
13
+ function get_started {
14
+ # if getting-started bootstrap is detected, put this in the path
15
+ # mainly useful for getopt on os x
16
+ if [[ -d "$HOME/.getting-started/bootstrap" ]]; then
17
+ PATH="$HOME/.getting-started/bootstrap:$PATH"
18
+ hash -r
19
+ fi
20
+ }
21
+
22
+ function check_help {
23
+ # taken from shocco
24
+ if expr -- "$*" : ".*--help" >/dev/null; then
25
+ display_help
26
+ exit 0
27
+ fi
28
+ }
29
+
30
+ function display_help {
31
+ flags_help
32
+ echo
33
+
34
+ # taken from shocco
35
+ grep '^#/' <"$shome/$(basename $(dirname -- "$0"))/$(basename -- "$0")" | cut -c4-
36
+ }
37
+
38
+ # Exits the script with the last error code. Servers as a marker in $0 to
39
+ # begin ronn documentation until end of file.
40
+ function __MAN__ {
41
+ exit "$!"
42
+ }
43
+
44
+ # Extracts ronn-style Markdown after __MAN__ to stdout. If a line is "MAN", it
45
+ # is assumed that a here document is used (for syntactical reasons).
46
+ #
47
+ # A limitation of detecting "MAN" will truncate the Markdown if "MAN" is a
48
+ # legimate text.
49
+ #
50
+ # __MAN__ << "MAN"
51
+ # raw ronn-style Markdown
52
+ # MAN
53
+ function display_man {
54
+ awk '/^__MAN__/,/^MAN$/ {print}' <"$shome/bin/$(basename -- "$0")" | tail -n +2 | egrep -v '^MAN$'
55
+ }
56
+
57
+ function display_synopsis {
58
+ awk '/^#/ && !/^#!/ { print } /^[^#]/ || /^$/ { exit }' <"$shome/bin/$(basename -- "$0")" | cut -c3-
59
+ }
60
+
61
+ function which_library {
62
+ local library="$1"; shift
63
+ if [[ -r "$shome/bin/_$library" ]]; then
64
+ echo "$shome/bin/_$library"
65
+ elif [[ -r "$shome/.$library/bin/_profile" ]]; then
66
+ echo "$shome/.$library/bin/_profile"
67
+ elif [[ -r "$shome/.$library/.profile" ]]; then
68
+ echo "$shome/.$library/.profile"
69
+ else
70
+ local nm_library="${library%%/*}"
71
+ if [[ "$nm_library" != "$library" ]]; then
72
+ local nm_right="${library##*/}"
73
+ if [[ -r "$shome/.$nm_library/bin/_$nm_right" ]]; then
74
+ echo "$shome/.$nm_library/bin/_$nm_right"
75
+ fi
76
+ fi
77
+ fi
78
+ }
79
+
80
+ function require {
81
+ local nm_library="$1"; shift
82
+ local pth_lib="$(which_library "$nm_library")"
83
+ if [[ -r "$pth_lib" ]]; then
84
+ if [[ "$#" == 0 ]]; then
85
+ set --
86
+ fi
87
+ source "$pth_lib" "$@"
88
+ fi
89
+ }
90
+
91
+ function parse_command_line {
92
+ if [[ "$FLAGS_SUB" = "$FLAGS_TRUE" && "$@" > 0 ]]; then
93
+ local argv
94
+ declare -a argv
95
+
96
+ local argc="0"
97
+ local arg
98
+ local passthrough=
99
+ for arg in "$@"; do
100
+ if [[ -z "$passthrough" && ! "$arg" =~ ^- ]]; then
101
+ argv[argc]="--"
102
+ argc="$((argc + 1))"
103
+ passthrough=1
104
+ fi
105
+
106
+ argv[argc]="$arg"
107
+ argc="$((argc + 1))"
108
+ done
109
+
110
+ set -- "${argv[@]}"
111
+ fi
112
+
113
+ if ! FLAGS "$@"; then
114
+ if [[ "$flags_error" = "help requested" ]]; then
115
+ echo ""
116
+ display_help
117
+ exit 0
118
+ fi
119
+
120
+ return 4
121
+ fi
122
+ return 0
123
+ }
124
+
125
+ function configure_logging {
126
+ # load log4sh (disabling properties file warning) and clear the default
127
+ # configuration
128
+ LOG4SH_CONFIGURATION='none' require 'log4sh'
129
+ log4sh_resetConfiguration
130
+
131
+ # set the global logging level to INFO
132
+ logger_setLevel INFO
133
+
134
+ # add and configure a FileAppender that outputs to STDERR, and activate the
135
+ # configuration
136
+ logger_addAppender stderr
137
+ appender_setType stderr FileAppender
138
+ appender_file_setFile stderr STDERR
139
+ appender_activateOptions stderr
140
+ }
141
+
142
+ function ryaml {
143
+ ruby -ryaml -e 'def ps x; unless x.nil?; puts x; end; end; ps ARGV[1..-1].inject(YAML.load(File.read(ARGV[0]))) {|acc, key| acc[key] }' "$@" 2>&-
144
+ }
145
+
146
+ function random_str {
147
+ echo "$(date +%s).$$.$RANDOM"
148
+ }
149
+
150
+ function runmany {
151
+ local cpu="$1"; shift
152
+ local args="$1"; shift
153
+ if [[ "$#" = 0 ]]; then
154
+ cat
155
+ else
156
+ echo "$@"
157
+ fi | xargs -P $cpu -n $args -- bash -c "$*" ""
158
+ }
159
+
160
+ function _main {
161
+ if [[ -z "$shome" ]]; then
162
+ shome="$(cd -P -- "$(dirname -- "${BASH_SOURCE}")/.." && pwd -P)"
163
+ fi
164
+
165
+ require 'shflags'
166
+
167
+ configure_logging
168
+
169
+ PATH="$shome/bin:$PATH"
170
+ }
171
+
172
+ _main "$@"
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+
3
+ if [[ -z "${shome:-}" ]]; then
4
+ shome="$(cd -P -- "$(dirname -- "${BASH_SOURCE}")/.." && pwd -P)"
5
+ fi
6
+
7
+ source "$shome/bin/_jason"
8
+ set -fue
@@ -0,0 +1,1012 @@
1
+ # $Id$
2
+ # vim:et:ft=sh:sts=2:sw=2
3
+ #
4
+ # Copyright 2008 Kate Ward. All Rights Reserved.
5
+ # Released under the LGPL (GNU Lesser General Public License)
6
+ #
7
+ # shFlags -- Advanced command-line flag library for Unix shell scripts.
8
+ # http://code.google.com/p/shflags/
9
+ #
10
+ # Author: kate.ward@forestent.com (Kate Ward)
11
+ #
12
+ # This module implements something like the google-gflags library available
13
+ # from http://code.google.com/p/google-gflags/.
14
+ #
15
+ # FLAG TYPES: This is a list of the DEFINE_*'s that you can do. All flags take
16
+ # a name, default value, help-string, and optional 'short' name (one-letter
17
+ # name). Some flags have other arguments, which are described with the flag.
18
+ #
19
+ # DEFINE_string: takes any input, and intreprets it as a string.
20
+ #
21
+ # DEFINE_boolean: typically does not take any argument: say --myflag to set
22
+ # FLAGS_myflag to true, or --nomyflag to set FLAGS_myflag to false.
23
+ # Alternately, you can say
24
+ # --myflag=true or --myflag=t or --myflag=0 or
25
+ # --myflag=false or --myflag=f or --myflag=1
26
+ # Passing an option has the same affect as passing the option once.
27
+ #
28
+ # DEFINE_float: takes an input and intreprets it as a floating point number. As
29
+ # shell does not support floats per-se, the input is merely validated as
30
+ # being a valid floating point value.
31
+ #
32
+ # DEFINE_integer: takes an input and intreprets it as an integer.
33
+ #
34
+ # SPECIAL FLAGS: There are a few flags that have special meaning:
35
+ # --help (or -?) prints a list of all the flags in a human-readable fashion
36
+ # --flagfile=foo read flags from foo. (not implemented yet)
37
+ # -- as in getopt(), terminates flag-processing
38
+ #
39
+ # EXAMPLE USAGE:
40
+ #
41
+ # -- begin hello.sh --
42
+ # #! /bin/sh
43
+ # . ./shflags
44
+ # DEFINE_string name 'world' "somebody's name" n
45
+ # FLAGS "$@" || exit $?
46
+ # eval set -- "${FLAGS_ARGV}"
47
+ # echo "Hello, ${FLAGS_name}."
48
+ # -- end hello.sh --
49
+ #
50
+ # $ ./hello.sh -n Kate
51
+ # Hello, Kate.
52
+ #
53
+ # NOTE: Not all systems include a getopt version that supports long flags. On
54
+ # these systems, only short flags are recognized.
55
+
56
+ #==============================================================================
57
+ # shFlags
58
+ #
59
+ # Shared attributes:
60
+ # flags_error: last error message
61
+ # flags_return: last return value
62
+ #
63
+ # __flags_longNames: list of long names for all flags
64
+ # __flags_shortNames: list of short names for all flags
65
+ # __flags_boolNames: list of boolean flag names
66
+ #
67
+ # __flags_opts: options parsed by getopt
68
+ #
69
+ # Per-flag attributes:
70
+ # FLAGS_<flag_name>: contains value of flag named 'flag_name'
71
+ # __flags_<flag_name>_default: the default flag value
72
+ # __flags_<flag_name>_help: the flag help string
73
+ # __flags_<flag_name>_short: the flag short name
74
+ # __flags_<flag_name>_type: the flag type
75
+ #
76
+ # Notes:
77
+ # - lists of strings are space separated, and a null value is the '~' char.
78
+
79
+ # return if FLAGS already loaded
80
+ [ -n "${FLAGS_VERSION:-}" ] && return 0
81
+ FLAGS_VERSION='1.0.3'
82
+
83
+ # return values
84
+ FLAGS_TRUE=0
85
+ FLAGS_FALSE=1
86
+ FLAGS_ERROR=2
87
+
88
+ # reserved flag names
89
+ FLAGS_RESERVED='ARGC ARGV ERROR FALSE HELP PARENT RESERVED TRUE VERSION'
90
+
91
+ _flags_debug() { echo "flags:DEBUG $@" >&2; }
92
+ _flags_warn() { echo "flags:WARN $@" >&2; }
93
+ _flags_error() { echo "flags:ERROR $@" >&2; }
94
+ _flags_fatal() { echo "flags:FATAL $@" >&2; }
95
+
96
+ # specific shell checks
97
+ if [ -n "${ZSH_VERSION:-}" ]; then
98
+ setopt |grep "^shwordsplit$" >/dev/null
99
+ if [ $? -ne ${FLAGS_TRUE} ]; then
100
+ _flags_fatal 'zsh shwordsplit option is required for proper zsh operation'
101
+ exit ${FLAGS_ERROR}
102
+ fi
103
+ if [ -z "${FLAGS_PARENT:-}" ]; then
104
+ _flags_fatal "zsh does not pass \$0 through properly. please declare' \
105
+ \"FLAGS_PARENT=\$0\" before calling shFlags"
106
+ exit ${FLAGS_ERROR}
107
+ fi
108
+ fi
109
+
110
+ #
111
+ # constants
112
+ #
113
+
114
+ # getopt version
115
+ __FLAGS_GETOPT_VERS_STD=0
116
+ __FLAGS_GETOPT_VERS_ENH=1
117
+ __FLAGS_GETOPT_VERS_BSD=2
118
+
119
+ getopt >/dev/null 2>&1
120
+ case $? in
121
+ 0) __FLAGS_GETOPT_VERS=${__FLAGS_GETOPT_VERS_STD} ;; # bsd getopt
122
+ 2)
123
+ # TODO(kward): look into '-T' option to test the internal getopt() version
124
+ if [ "`getopt --version`" = '-- ' ]; then
125
+ __FLAGS_GETOPT_VERS=${__FLAGS_GETOPT_VERS_STD}
126
+ else
127
+ __FLAGS_GETOPT_VERS=${__FLAGS_GETOPT_VERS_ENH}
128
+ fi
129
+ ;;
130
+ *)
131
+ _flags_fatal 'unable to determine getopt version'
132
+ exit ${FLAGS_ERROR}
133
+ ;;
134
+ esac
135
+
136
+ # getopt optstring lengths
137
+ __FLAGS_OPTSTR_SHORT=0
138
+ __FLAGS_OPTSTR_LONG=1
139
+
140
+ __FLAGS_NULL='~'
141
+
142
+ # flag info strings
143
+ __FLAGS_INFO_DEFAULT='default'
144
+ __FLAGS_INFO_HELP='help'
145
+ __FLAGS_INFO_SHORT='short'
146
+ __FLAGS_INFO_TYPE='type'
147
+
148
+ # flag lengths
149
+ __FLAGS_LEN_SHORT=0
150
+ __FLAGS_LEN_LONG=1
151
+
152
+ # flag types
153
+ __FLAGS_TYPE_NONE=0
154
+ __FLAGS_TYPE_BOOLEAN=1
155
+ __FLAGS_TYPE_FLOAT=2
156
+ __FLAGS_TYPE_INTEGER=3
157
+ __FLAGS_TYPE_STRING=4
158
+
159
+ # set the constants readonly
160
+ __flags_constants=`set |awk -F= '/^FLAGS_/ || /^__FLAGS_/ {print $1}'`
161
+ for __flags_const in ${__flags_constants}; do
162
+ # skip certain flags
163
+ case ${__flags_const} in
164
+ FLAGS_HELP) continue ;;
165
+ FLAGS_PARENT) continue ;;
166
+ esac
167
+ # set flag readonly
168
+ if [ -z "${ZSH_VERSION:-}" ]; then
169
+ readonly ${__flags_const}
170
+ else # handle zsh
171
+ case ${ZSH_VERSION} in
172
+ [123].*) readonly ${__flags_const} ;;
173
+ *) readonly -g ${__flags_const} ;; # declare readonly constants globally
174
+ esac
175
+ fi
176
+ done
177
+ unset __flags_const __flags_constants
178
+
179
+ #
180
+ # internal variables
181
+ #
182
+
183
+ __flags_boolNames=' ' # space separated list of boolean flag names
184
+ __flags_longNames=' ' # space separated list of long flag names
185
+ __flags_shortNames=' ' # space separated list of short flag names
186
+
187
+ __flags_columns='' # screen width in columns
188
+ __flags_opts='' # temporary storage for parsed getopt flags
189
+
190
+ #------------------------------------------------------------------------------
191
+ # private functions
192
+ #
193
+
194
+ # Define a flag.
195
+ #
196
+ # Calling this function will define the following info variables for the
197
+ # specified flag:
198
+ # FLAGS_flagname - the name for this flag (based upon the long flag name)
199
+ # __flags_<flag_name>_default - the default value
200
+ # __flags_flagname_help - the help string
201
+ # __flags_flagname_short - the single letter alias
202
+ # __flags_flagname_type - the type of flag (one of __FLAGS_TYPE_*)
203
+ #
204
+ # Args:
205
+ # _flags__type: integer: internal type of flag (__FLAGS_TYPE_*)
206
+ # _flags__name: string: long flag name
207
+ # _flags__default: default flag value
208
+ # _flags__help: string: help string
209
+ # _flags__short: string: (optional) short flag name
210
+ # Returns:
211
+ # integer: success of operation, or error
212
+ _flags_define()
213
+ {
214
+ if [ $# -lt 4 ]; then
215
+ flags_error='DEFINE error: too few arguments'
216
+ flags_return=${FLAGS_ERROR}
217
+ _flags_error "${flags_error}"
218
+ return ${flags_return}
219
+ fi
220
+
221
+ _flags_type_=$1
222
+ _flags_name_=$2
223
+ _flags_default_=$3
224
+ _flags_help_=$4
225
+ _flags_short_=${5:-${__FLAGS_NULL}}
226
+
227
+ _flags_return_=${FLAGS_TRUE}
228
+
229
+ # TODO(kward): check for validity of the flag name (e.g. dashes)
230
+
231
+ # check whether the flag name is reserved
232
+ echo " ${FLAGS_RESERVED} " |grep " ${_flags_name_} " >/dev/null
233
+ if [ $? -eq 0 ]; then
234
+ flags_error="flag name (${_flags_name_}) is reserved"
235
+ _flags_return_=${FLAGS_ERROR}
236
+ fi
237
+
238
+ # require short option for getopt that don't support long options
239
+ if [ ${_flags_return_} -eq ${FLAGS_TRUE} \
240
+ -a ${__FLAGS_GETOPT_VERS} -ne ${__FLAGS_GETOPT_VERS_ENH} \
241
+ -a "${_flags_short_}" = "${__FLAGS_NULL}" ]
242
+ then
243
+ flags_error="short flag required for (${_flags_name_}) on this platform"
244
+ _flags_return_=${FLAGS_ERROR}
245
+ fi
246
+
247
+ # check for existing long name definition
248
+ if [ ${_flags_return_} -eq ${FLAGS_TRUE} ]; then
249
+ if _flags_itemInList "${_flags_name_}" \
250
+ ${__flags_longNames} ${__flags_boolNames}
251
+ then
252
+ flags_error="flag name ([no]${_flags_name_}) already defined"
253
+ _flags_warn "${flags_error}"
254
+ _flags_return_=${FLAGS_FALSE}
255
+ fi
256
+ fi
257
+
258
+ # check for existing short name definition
259
+ if [ ${_flags_return_} -eq ${FLAGS_TRUE} \
260
+ -a "${_flags_short_}" != "${__FLAGS_NULL}" ]
261
+ then
262
+ if _flags_itemInList "${_flags_short_}" ${__flags_shortNames}; then
263
+ flags_error="flag short name (${_flags_short_}) already defined"
264
+ _flags_warn "${flags_error}"
265
+ _flags_return_=${FLAGS_FALSE}
266
+ fi
267
+ fi
268
+
269
+ # handle default value. note, on several occasions the 'if' portion of an
270
+ # if/then/else contains just a ':' which does nothing. a binary reversal via
271
+ # '!' is not done because it does not work on all shells.
272
+ if [ ${_flags_return_} -eq ${FLAGS_TRUE} ]; then
273
+ case ${_flags_type_} in
274
+ ${__FLAGS_TYPE_BOOLEAN})
275
+ if _flags_validateBoolean "${_flags_default_}"; then
276
+ case ${_flags_default_} in
277
+ true|t|0) _flags_default_=${FLAGS_TRUE} ;;
278
+ false|f|1) _flags_default_=${FLAGS_FALSE} ;;
279
+ esac
280
+ else
281
+ flags_error="invalid default flag value '${_flags_default_}'"
282
+ _flags_return_=${FLAGS_ERROR}
283
+ fi
284
+ ;;
285
+
286
+ ${__FLAGS_TYPE_FLOAT})
287
+ if _flags_validateFloat "${_flags_default_}"; then
288
+ :
289
+ else
290
+ flags_error="invalid default flag value '${_flags_default_}'"
291
+ _flags_return_=${FLAGS_ERROR}
292
+ fi
293
+ ;;
294
+
295
+ ${__FLAGS_TYPE_INTEGER})
296
+ if _flags_validateInteger "${_flags_default_}"; then
297
+ :
298
+ else
299
+ flags_error="invalid default flag value '${_flags_default_}'"
300
+ _flags_return_=${FLAGS_ERROR}
301
+ fi
302
+ ;;
303
+
304
+ ${__FLAGS_TYPE_STRING}) ;; # everything in shell is a valid string
305
+
306
+ *)
307
+ flags_error="unrecognized flag type '${_flags_type_}'"
308
+ _flags_return_=${FLAGS_ERROR}
309
+ ;;
310
+ esac
311
+ fi
312
+
313
+ if [ ${_flags_return_} -eq ${FLAGS_TRUE} ]; then
314
+ # store flag information
315
+ eval "FLAGS_${_flags_name_}='${_flags_default_}'"
316
+ eval "__flags_${_flags_name_}_${__FLAGS_INFO_TYPE}=${_flags_type_}"
317
+ eval "__flags_${_flags_name_}_${__FLAGS_INFO_DEFAULT}=\
318
+ \"${_flags_default_}\""
319
+ eval "__flags_${_flags_name_}_${__FLAGS_INFO_HELP}=\"${_flags_help_}\""
320
+ eval "__flags_${_flags_name_}_${__FLAGS_INFO_SHORT}='${_flags_short_}'"
321
+
322
+ # append flag name(s) to list of names
323
+ __flags_longNames="${__flags_longNames}${_flags_name_} "
324
+ __flags_shortNames="${__flags_shortNames}${_flags_short_} "
325
+ [ ${_flags_type_} -eq ${__FLAGS_TYPE_BOOLEAN} ] && \
326
+ __flags_boolNames="${__flags_boolNames}no${_flags_name_} "
327
+ fi
328
+
329
+ flags_return=${_flags_return_}
330
+ unset _flags_default_ _flags_help_ _flags_name_ _flags_return_ _flags_short_ \
331
+ _flags_type_
332
+ [ ${flags_return} -eq ${FLAGS_ERROR} ] && _flags_error "${flags_error}"
333
+ return ${flags_return}
334
+ }
335
+
336
+ # Return valid getopt options using currently defined list of long options.
337
+ #
338
+ # This function builds a proper getopt option string for short (and long)
339
+ # options, using the current list of long options for reference.
340
+ #
341
+ # Args:
342
+ # _flags_optStr: integer: option string type (__FLAGS_OPTSTR_*)
343
+ # Output:
344
+ # string: generated option string for getopt
345
+ # Returns:
346
+ # boolean: success of operation (always returns True)
347
+ _flags_genOptStr()
348
+ {
349
+ _flags_optStrType_=$1
350
+
351
+ _flags_opts_=''
352
+
353
+ for _flags_flag_ in ${__flags_longNames}; do
354
+ _flags_type_=`_flags_getFlagInfo ${_flags_flag_} ${__FLAGS_INFO_TYPE}`
355
+ case ${_flags_optStrType_} in
356
+ ${__FLAGS_OPTSTR_SHORT})
357
+ _flags_shortName_=`_flags_getFlagInfo \
358
+ ${_flags_flag_} ${__FLAGS_INFO_SHORT}`
359
+ if [ "${_flags_shortName_}" != "${__FLAGS_NULL}" ]; then
360
+ _flags_opts_="${_flags_opts_}${_flags_shortName_}"
361
+ # getopt needs a trailing ':' to indicate a required argument
362
+ [ ${_flags_type_} -ne ${__FLAGS_TYPE_BOOLEAN} ] && \
363
+ _flags_opts_="${_flags_opts_}:"
364
+ fi
365
+ ;;
366
+
367
+ ${__FLAGS_OPTSTR_LONG})
368
+ _flags_opts_="${_flags_opts_:+${_flags_opts_},}${_flags_flag_}"
369
+ # getopt needs a trailing ':' to indicate a required argument
370
+ [ ${_flags_type_} -ne ${__FLAGS_TYPE_BOOLEAN} ] && \
371
+ _flags_opts_="${_flags_opts_}:"
372
+ ;;
373
+ esac
374
+ done
375
+
376
+ echo "${_flags_opts_}"
377
+ unset _flags_flag_ _flags_opts_ _flags_optStrType_ _flags_shortName_ \
378
+ _flags_type_
379
+ return ${FLAGS_TRUE}
380
+ }
381
+
382
+ # Returns flag details based on a flag name and flag info.
383
+ #
384
+ # Args:
385
+ # string: long flag name
386
+ # string: flag info (see the _flags_define function for valid info types)
387
+ # Output:
388
+ # string: value of dereferenced flag variable
389
+ # Returns:
390
+ # integer: one of FLAGS_{TRUE|FALSE|ERROR}
391
+ _flags_getFlagInfo()
392
+ {
393
+ _flags_name_=$1
394
+ _flags_info_=$2
395
+
396
+ _flags_nameVar_="__flags_${_flags_name_}_${_flags_info_}"
397
+ _flags_strToEval_="_flags_value_=\"\${${_flags_nameVar_}:-}\""
398
+ eval "${_flags_strToEval_}"
399
+ if [ -n "${_flags_value_}" ]; then
400
+ flags_return=${FLAGS_TRUE}
401
+ else
402
+ # see if the _flags_name_ variable is a string as strings can be empty...
403
+ # note: the DRY principle would say to have this function call itself for
404
+ # the next three lines, but doing so results in an infinite loop as an
405
+ # invalid _flags_name_ will also not have the associated _type variable.
406
+ # Because it doesn't (it will evaluate to an empty string) the logic will
407
+ # try to find the _type variable of the _type variable, and so on. Not so
408
+ # good ;-)
409
+ _flags_typeVar_="__flags_${_flags_name_}_${__FLAGS_INFO_TYPE}"
410
+ _flags_strToEval_="_flags_type_=\"\${${_flags_typeVar_}:-}\""
411
+ eval "${_flags_strToEval_}"
412
+ if [ "${_flags_type_}" = "${__FLAGS_TYPE_STRING}" ]; then
413
+ flags_return=${FLAGS_TRUE}
414
+ else
415
+ flags_return=${FLAGS_ERROR}
416
+ flags_error="invalid flag name (${_flags_nameVar_})"
417
+ fi
418
+ fi
419
+
420
+ echo "${_flags_value_}"
421
+ unset _flags_info_ _flags_name_ _flags_strToEval_ _flags_type_ _flags_value_ \
422
+ _flags_nameVar_ _flags_typeVar_
423
+ [ ${flags_return} -eq ${FLAGS_ERROR} ] && _flags_error "${flags_error}"
424
+ return ${flags_return}
425
+ }
426
+
427
+ # check for presense of item in a list. passed a string (e.g. 'abc'), this
428
+ # function will determine if the string is present in the list of strings (e.g.
429
+ # ' foo bar abc ').
430
+ #
431
+ # Args:
432
+ # _flags__str: string: string to search for in a list of strings
433
+ # unnamed: list: list of strings
434
+ # Returns:
435
+ # boolean: true if item is in the list
436
+ _flags_itemInList()
437
+ {
438
+ _flags_str_=$1
439
+ shift
440
+
441
+ echo " ${*:-} " |grep " ${_flags_str_} " >/dev/null
442
+ if [ $? -eq 0 ]; then
443
+ flags_return=${FLAGS_TRUE}
444
+ else
445
+ flags_return=${FLAGS_FALSE}
446
+ fi
447
+
448
+ unset _flags_str_
449
+ return ${flags_return}
450
+ }
451
+
452
+ # Returns the width of the current screen.
453
+ #
454
+ # Output:
455
+ # integer: width in columns of the current screen.
456
+ _flags_columns()
457
+ {
458
+ if [ -z "${__flags_columns}" ]; then
459
+ # determine the value and store it
460
+ if eval stty size >/dev/null 2>&1; then
461
+ # stty size worked :-)
462
+ set -- `stty size`
463
+ __flags_columns=$2
464
+ elif eval tput cols >/dev/null 2>&1; then
465
+ set -- `tput cols`
466
+ __flags_columns=$1
467
+ else
468
+ __flags_columns=80 # default terminal width
469
+ fi
470
+ fi
471
+ echo ${__flags_columns}
472
+ }
473
+
474
+ # Validate a boolean.
475
+ #
476
+ # Args:
477
+ # _flags__bool: boolean: value to validate
478
+ # Returns:
479
+ # bool: true if the value is a valid boolean
480
+ _flags_validateBoolean()
481
+ {
482
+ _flags_bool_=$1
483
+
484
+ flags_return=${FLAGS_TRUE}
485
+ case "${_flags_bool_}" in
486
+ true|t|0) ;;
487
+ false|f|1) ;;
488
+ *) flags_return=${FLAGS_FALSE} ;;
489
+ esac
490
+
491
+ unset _flags_bool_
492
+ return ${flags_return}
493
+ }
494
+
495
+ # Validate a float.
496
+ #
497
+ # Args:
498
+ # _flags__float: float: value to validate
499
+ # Returns:
500
+ # bool: true if the value is a valid float
501
+ _flags_validateFloat()
502
+ {
503
+ _flags_float_=$1
504
+
505
+ if _flags_validateInteger ${_flags_float_}; then
506
+ flags_return=${FLAGS_TRUE}
507
+ else
508
+ flags_return=${FLAGS_TRUE}
509
+ case ${_flags_float_} in
510
+ -*) # negative floats
511
+ _flags_test_=`expr "${_flags_float_}" : '\(-[0-9][0-9]*\.[0-9][0-9]*\)'`
512
+ ;;
513
+ *) # positive floats
514
+ _flags_test_=`expr "${_flags_float_}" : '\([0-9][0-9]*\.[0-9][0-9]*\)'`
515
+ ;;
516
+ esac
517
+ [ "${_flags_test_}" != "${_flags_float_}" ] && flags_return=${FLAGS_FALSE}
518
+ fi
519
+
520
+ unset _flags_float_ _flags_test_
521
+ return ${flags_return}
522
+ }
523
+
524
+ # Validate an integer.
525
+ #
526
+ # Args:
527
+ # _flags__integer: interger: value to validate
528
+ # Returns:
529
+ # bool: true if the value is a valid integer
530
+ _flags_validateInteger()
531
+ {
532
+ _flags_int_=$1
533
+
534
+ flags_return=${FLAGS_TRUE}
535
+ case ${_flags_int_} in
536
+ -*) # negative ints
537
+ _flags_test_=`expr "${_flags_int_}" : '\(-[0-9][0-9]*\)'`
538
+ ;;
539
+ *) # positive ints
540
+ _flags_test_=`expr "${_flags_int_}" : '\([0-9][0-9]*\)'`
541
+ ;;
542
+ esac
543
+ [ "${_flags_test_}" != "${_flags_int_}" ] && flags_return=${FLAGS_FALSE}
544
+
545
+ unset _flags_int_ _flags_test_
546
+ return ${flags_return}
547
+ }
548
+
549
+ # Parse command-line options using the standard getopt.
550
+ #
551
+ # Note: the flag options are passed around in the global __flags_opts so that
552
+ # the formatting is not lost due to shell parsing and such.
553
+ #
554
+ # Args:
555
+ # @: varies: command-line options to parse
556
+ # Returns:
557
+ # integer: a FLAGS success condition
558
+ _flags_getoptStandard()
559
+ {
560
+ flags_return=${FLAGS_TRUE}
561
+ _flags_shortOpts_=`_flags_genOptStr ${__FLAGS_OPTSTR_SHORT}`
562
+
563
+ # check for spaces in passed options
564
+ for _flags_opt_ in "$@"; do
565
+ # note: the silliness with the x's is purely for ksh93 on Ubuntu 6.06
566
+ _flags_match_=`echo "x${_flags_opt_}x" |sed 's/ //g'`
567
+ if [ "${_flags_match_}" != "x${_flags_opt_}x" ]; then
568
+ flags_error='the available getopt does not support spaces in options'
569
+ flags_return=${FLAGS_ERROR}
570
+ break
571
+ fi
572
+ done
573
+
574
+ if [ ${flags_return} -eq ${FLAGS_TRUE} ]; then
575
+ __flags_opts=`getopt ${_flags_shortOpts_} $@ 2>&1`
576
+ _flags_rtrn_=$?
577
+ if [ ${_flags_rtrn_} -ne ${FLAGS_TRUE} ]; then
578
+ _flags_warn "${__flags_opts}"
579
+ flags_error='unable to parse provided options with getopt.'
580
+ flags_return=${FLAGS_ERROR}
581
+ fi
582
+ fi
583
+
584
+ unset _flags_match_ _flags_opt_ _flags_rtrn_ _flags_shortOpts_
585
+ return ${flags_return}
586
+ }
587
+
588
+ # Parse command-line options using the enhanced getopt.
589
+ #
590
+ # Note: the flag options are passed around in the global __flags_opts so that
591
+ # the formatting is not lost due to shell parsing and such.
592
+ #
593
+ # Args:
594
+ # @: varies: command-line options to parse
595
+ # Returns:
596
+ # integer: a FLAGS success condition
597
+ _flags_getoptEnhanced()
598
+ {
599
+ flags_return=${FLAGS_TRUE}
600
+ _flags_shortOpts_=`_flags_genOptStr ${__FLAGS_OPTSTR_SHORT}`
601
+ _flags_boolOpts_=`echo "${__flags_boolNames}" \
602
+ |sed 's/^ *//;s/ *$//;s/ /,/g'`
603
+ _flags_longOpts_=`_flags_genOptStr ${__FLAGS_OPTSTR_LONG}`
604
+
605
+ __flags_opts=`getopt \
606
+ -o ${_flags_shortOpts_} \
607
+ -l "${_flags_longOpts_},${_flags_boolOpts_}" \
608
+ -- "$@" 2>&1`
609
+ _flags_rtrn_=$?
610
+ if [ ${_flags_rtrn_} -ne ${FLAGS_TRUE} ]; then
611
+ _flags_warn "${__flags_opts}"
612
+ flags_error='unable to parse provided options with getopt.'
613
+ flags_return=${FLAGS_ERROR}
614
+ fi
615
+
616
+ unset _flags_boolOpts_ _flags_longOpts_ _flags_rtrn_ _flags_shortOpts_
617
+ return ${flags_return}
618
+ }
619
+
620
+ # Dynamically parse a getopt result and set appropriate variables.
621
+ #
622
+ # This function does the actual conversion of getopt output and runs it through
623
+ # the standard case structure for parsing. The case structure is actually quite
624
+ # dynamic to support any number of flags.
625
+ #
626
+ # Args:
627
+ # argc: int: original command-line argument count
628
+ # @: varies: output from getopt parsing
629
+ # Returns:
630
+ # integer: a FLAGS success condition
631
+ _flags_parseGetopt()
632
+ {
633
+ _flags_argc_=$1
634
+ shift
635
+
636
+ flags_return=${FLAGS_TRUE}
637
+
638
+ if [ ${__FLAGS_GETOPT_VERS} -ne ${__FLAGS_GETOPT_VERS_ENH} ]; then
639
+ set -- $@
640
+ else
641
+ # note the quotes around the `$@' -- they are essential!
642
+ eval set -- "$@"
643
+ fi
644
+
645
+ # provide user with number of arguments to shift by later
646
+ # NOTE: the FLAGS_ARGC variable is obsolete as of 1.0.3 because it does not
647
+ # properly give user access to non-flag arguments mixed in between flag
648
+ # arguments. Its usage was replaced by FLAGS_ARGV, and it is being kept only
649
+ # for backwards compatibility reasons.
650
+ FLAGS_ARGC=`expr $# - 1 - ${_flags_argc_}`
651
+
652
+ # handle options. note options with values must do an additional shift
653
+ while true; do
654
+ _flags_opt_=$1
655
+ _flags_arg_=${2:-}
656
+ _flags_type_=${__FLAGS_TYPE_NONE}
657
+ _flags_name_=''
658
+
659
+ # determine long flag name
660
+ case "${_flags_opt_}" in
661
+ --) shift; break ;; # discontinue option parsing
662
+
663
+ --*) # long option
664
+ _flags_opt_=`expr "${_flags_opt_}" : '--\(.*\)'`
665
+ _flags_len_=${__FLAGS_LEN_LONG}
666
+ if _flags_itemInList "${_flags_opt_}" ${__flags_longNames}; then
667
+ _flags_name_=${_flags_opt_}
668
+ else
669
+ # check for negated long boolean version
670
+ if _flags_itemInList "${_flags_opt_}" ${__flags_boolNames}; then
671
+ _flags_name_=`expr "${_flags_opt_}" : 'no\(.*\)'`
672
+ _flags_type_=${__FLAGS_TYPE_BOOLEAN}
673
+ _flags_arg_=${__FLAGS_NULL}
674
+ fi
675
+ fi
676
+ ;;
677
+
678
+ -*) # short option
679
+ _flags_opt_=`expr "${_flags_opt_}" : '-\(.*\)'`
680
+ _flags_len_=${__FLAGS_LEN_SHORT}
681
+ if _flags_itemInList "${_flags_opt_}" ${__flags_shortNames}; then
682
+ # yes. match short name to long name. note purposeful off-by-one
683
+ # (too high) with awk calculations.
684
+ _flags_pos_=`echo "${__flags_shortNames}" \
685
+ |awk 'BEGIN{RS=" ";rn=0}$0==e{rn=NR}END{print rn}' \
686
+ e=${_flags_opt_}`
687
+ _flags_name_=`echo "${__flags_longNames}" \
688
+ |awk 'BEGIN{RS=" "}rn==NR{print $0}' rn="${_flags_pos_}"`
689
+ fi
690
+ ;;
691
+ esac
692
+
693
+ # die if the flag was unrecognized
694
+ if [ -z "${_flags_name_}" ]; then
695
+ flags_error="unrecognized option (${_flags_opt_})"
696
+ flags_return=${FLAGS_ERROR}
697
+ break
698
+ fi
699
+
700
+ # set new flag value
701
+ [ ${_flags_type_} -eq ${__FLAGS_TYPE_NONE} ] && \
702
+ _flags_type_=`_flags_getFlagInfo \
703
+ "${_flags_name_}" ${__FLAGS_INFO_TYPE}`
704
+ case ${_flags_type_} in
705
+ ${__FLAGS_TYPE_BOOLEAN})
706
+ if [ ${_flags_len_} -eq ${__FLAGS_LEN_LONG} ]; then
707
+ if [ "${_flags_arg_}" != "${__FLAGS_NULL}" ]; then
708
+ eval "FLAGS_${_flags_name_}=${FLAGS_TRUE}"
709
+ else
710
+ eval "FLAGS_${_flags_name_}=${FLAGS_FALSE}"
711
+ fi
712
+ else
713
+ _flags_strToEval_="_flags_val_=\
714
+ \${__flags_${_flags_name_}_${__FLAGS_INFO_DEFAULT}}"
715
+ eval "${_flags_strToEval_}"
716
+ if [ ${_flags_val_} -eq ${FLAGS_FALSE} ]; then
717
+ eval "FLAGS_${_flags_name_}=${FLAGS_TRUE}"
718
+ else
719
+ eval "FLAGS_${_flags_name_}=${FLAGS_FALSE}"
720
+ fi
721
+ fi
722
+ ;;
723
+
724
+ ${__FLAGS_TYPE_FLOAT})
725
+ if _flags_validateFloat "${_flags_arg_}"; then
726
+ eval "FLAGS_${_flags_name_}='${_flags_arg_}'"
727
+ else
728
+ flags_error="invalid float value (${_flags_arg_})"
729
+ flags_return=${FLAGS_ERROR}
730
+ break
731
+ fi
732
+ ;;
733
+
734
+ ${__FLAGS_TYPE_INTEGER})
735
+ if _flags_validateInteger "${_flags_arg_}"; then
736
+ eval "FLAGS_${_flags_name_}='${_flags_arg_}'"
737
+ else
738
+ flags_error="invalid integer value (${_flags_arg_})"
739
+ flags_return=${FLAGS_ERROR}
740
+ break
741
+ fi
742
+ ;;
743
+
744
+ ${__FLAGS_TYPE_STRING})
745
+ eval "FLAGS_${_flags_name_}='${_flags_arg_}'"
746
+ ;;
747
+ esac
748
+
749
+ # handle special case help flag
750
+ if [ "${_flags_name_}" = 'help' ]; then
751
+ if [ ${FLAGS_help} -eq ${FLAGS_TRUE} ]; then
752
+ flags_error='help requested'
753
+ flags_return=${FLAGS_FALSE}
754
+ break
755
+ fi
756
+ fi
757
+
758
+ # shift the option and non-boolean arguements out.
759
+ shift
760
+ [ ${_flags_type_} != ${__FLAGS_TYPE_BOOLEAN} ] && shift
761
+ done
762
+
763
+ # give user back non-flag arguments
764
+ FLAGS_ARGV=''
765
+ while [ $# -gt 0 ]; do
766
+ FLAGS_ARGV="${FLAGS_ARGV:+${FLAGS_ARGV} }'$1'"
767
+ shift
768
+ done
769
+
770
+ unset _flags_arg_ _flags_len_ _flags_name_ _flags_opt_ _flags_pos_ \
771
+ _flags_strToEval_ _flags_type_ _flags_val_
772
+ return ${flags_return}
773
+ }
774
+
775
+ #------------------------------------------------------------------------------
776
+ # public functions
777
+ #
778
+
779
+ # A basic boolean flag. Boolean flags do not take any arguments, and their
780
+ # value is either 1 (false) or 0 (true). For long flags, the false value is
781
+ # specified on the command line by prepending the word 'no'. With short flags,
782
+ # the presense of the flag toggles the current value between true and false.
783
+ # Specifying a short boolean flag twice on the command results in returning the
784
+ # value back to the default value.
785
+ #
786
+ # A default value is required for boolean flags.
787
+ #
788
+ # For example, lets say a Boolean flag was created whose long name was 'update'
789
+ # and whose short name was 'x', and the default value was 'false'. This flag
790
+ # could be explicitly set to 'true' with '--update' or by '-x', and it could be
791
+ # explicitly set to 'false' with '--noupdate'.
792
+ DEFINE_boolean() { _flags_define ${__FLAGS_TYPE_BOOLEAN} "$@" || return "$?"; }
793
+
794
+ # Other basic flags.
795
+ DEFINE_float() { _flags_define ${__FLAGS_TYPE_FLOAT} "$@" || return "$?"; }
796
+ DEFINE_integer() { _flags_define ${__FLAGS_TYPE_INTEGER} "$@" || return "$?"; }
797
+ DEFINE_string() { _flags_define ${__FLAGS_TYPE_STRING} "$@" || return "$?"; }
798
+
799
+ # Parse the flags.
800
+ #
801
+ # Args:
802
+ # unnamed: list: command-line flags to parse
803
+ # Returns:
804
+ # integer: success of operation, or error
805
+ FLAGS()
806
+ {
807
+ # define a standard 'help' flag if one isn't already defined
808
+ [ -z "${__flags_help_type:-}" ] && \
809
+ DEFINE_boolean 'help' false 'show this help' 'h'
810
+
811
+ # parse options
812
+ if [ $# -gt 0 ]; then
813
+ if [ ${__FLAGS_GETOPT_VERS} -ne ${__FLAGS_GETOPT_VERS_ENH} ]; then
814
+ _flags_getoptStandard "$@"
815
+ else
816
+ _flags_getoptEnhanced "$@"
817
+ fi
818
+ flags_return=$?
819
+ else
820
+ # nothing passed; won't bother running getopt
821
+ __flags_opts='--'
822
+ flags_return=${FLAGS_TRUE}
823
+ fi
824
+
825
+ if [ ${flags_return} -eq ${FLAGS_TRUE} ]; then
826
+ _flags_parseGetopt $# "${__flags_opts}"
827
+ flags_return=$?
828
+ fi
829
+
830
+ [ ${flags_return} -eq ${FLAGS_ERROR} ] && _flags_fatal "${flags_error}"
831
+ return ${flags_return}
832
+ }
833
+
834
+ # This is a helper function for determining the `getopt` version for platforms
835
+ # where the detection isn't working. It simply outputs debug information that
836
+ # can be included in a bug report.
837
+ #
838
+ # Args:
839
+ # none
840
+ # Output:
841
+ # debug info that can be included in a bug report
842
+ # Returns:
843
+ # nothing
844
+ flags_getoptInfo()
845
+ {
846
+ # platform info
847
+ _flags_debug "uname -a: `uname -a`"
848
+ _flags_debug "PATH: ${PATH}"
849
+
850
+ # shell info
851
+ if [ -n "${BASH_VERSION:-}" ]; then
852
+ _flags_debug 'shell: bash'
853
+ _flags_debug "BASH_VERSION: ${BASH_VERSION}"
854
+ elif [ -n "${ZSH_VERSION:-}" ]; then
855
+ _flags_debug 'shell: zsh'
856
+ _flags_debug "ZSH_VERSION: ${ZSH_VERSION}"
857
+ fi
858
+
859
+ # getopt info
860
+ getopt >/dev/null
861
+ _flags_getoptReturn=$?
862
+ _flags_debug "getopt return: ${_flags_getoptReturn}"
863
+ _flags_debug "getopt --version: `getopt --version 2>&1`"
864
+
865
+ unset _flags_getoptReturn
866
+ }
867
+
868
+ # Returns whether the detected getopt version is the enhanced version.
869
+ #
870
+ # Args:
871
+ # none
872
+ # Output:
873
+ # none
874
+ # Returns:
875
+ # bool: true if getopt is the enhanced version
876
+ flags_getoptIsEnh()
877
+ {
878
+ test ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_ENH}
879
+ }
880
+
881
+ # Returns whether the detected getopt version is the standard version.
882
+ #
883
+ # Args:
884
+ # none
885
+ # Returns:
886
+ # bool: true if getopt is the standard version
887
+ flags_getoptIsStd()
888
+ {
889
+ test ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_STD}
890
+ }
891
+
892
+ # This is effectively a 'usage()' function. It prints usage information and
893
+ # exits the program with ${FLAGS_FALSE} if it is ever found in the command line
894
+ # arguments. Note this function can be overridden so other apps can define
895
+ # their own --help flag, replacing this one, if they want.
896
+ #
897
+ # Args:
898
+ # none
899
+ # Returns:
900
+ # integer: success of operation (always returns true)
901
+ flags_help()
902
+ {
903
+ if [ -n "${FLAGS_HELP:-}" ]; then
904
+ echo "${FLAGS_HELP}" >&2
905
+ else
906
+ echo "USAGE: ${FLAGS_PARENT:-$0} [flags] args" >&2
907
+ fi
908
+ if [ -n "${__flags_longNames}" ]; then
909
+ echo 'flags:' >&2
910
+ for flags_name_ in ${__flags_longNames}; do
911
+ flags_flagStr_=''
912
+ flags_boolStr_=''
913
+
914
+ flags_default_=`_flags_getFlagInfo \
915
+ "${flags_name_}" ${__FLAGS_INFO_DEFAULT}`
916
+ flags_help_=`_flags_getFlagInfo \
917
+ "${flags_name_}" ${__FLAGS_INFO_HELP}`
918
+ flags_short_=`_flags_getFlagInfo \
919
+ "${flags_name_}" ${__FLAGS_INFO_SHORT}`
920
+ flags_type_=`_flags_getFlagInfo \
921
+ "${flags_name_}" ${__FLAGS_INFO_TYPE}`
922
+
923
+ [ "${flags_short_}" != "${__FLAGS_NULL}" ] \
924
+ && flags_flagStr_="-${flags_short_}"
925
+
926
+ if [ ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_ENH} ]; then
927
+ [ "${flags_short_}" != "${__FLAGS_NULL}" ] \
928
+ && flags_flagStr_="${flags_flagStr_},"
929
+ [ ${flags_type_} -eq ${__FLAGS_TYPE_BOOLEAN} ] \
930
+ && flags_boolStr_='[no]'
931
+ flags_flagStr_="${flags_flagStr_}--${flags_boolStr_}${flags_name_}:"
932
+ fi
933
+
934
+ case ${flags_type_} in
935
+ ${__FLAGS_TYPE_BOOLEAN})
936
+ if [ ${flags_default_} -eq ${FLAGS_TRUE} ]; then
937
+ flags_defaultStr_='true'
938
+ else
939
+ flags_defaultStr_='false'
940
+ fi
941
+ ;;
942
+ ${__FLAGS_TYPE_FLOAT}|${__FLAGS_TYPE_INTEGER})
943
+ flags_defaultStr_=${flags_default_} ;;
944
+ ${__FLAGS_TYPE_STRING}) flags_defaultStr_="'${flags_default_}'" ;;
945
+ esac
946
+ flags_defaultStr_="(default: ${flags_defaultStr_})"
947
+
948
+ flags_helpStr_=" ${flags_flagStr_} ${flags_help_} ${flags_defaultStr_}"
949
+ flags_helpStrLen_=`expr "${flags_helpStr_}" : '.*'`
950
+ flags_columns_=`_flags_columns`
951
+ if [ ${flags_helpStrLen_} -lt ${flags_columns_} ]; then
952
+ echo "${flags_helpStr_}" >&2
953
+ else
954
+ echo " ${flags_flagStr_} ${flags_help_}" >&2
955
+ # note: the silliness with the x's is purely for ksh93 on Ubuntu 6.06
956
+ # because it doesn't like empty strings when used in this manner.
957
+ flags_emptyStr_="`echo \"x${flags_flagStr_}x\" \
958
+ |awk '{printf "%"length($0)-2"s", ""}'`"
959
+ flags_helpStr_=" ${flags_emptyStr_} ${flags_defaultStr_}"
960
+ flags_helpStrLen_=`expr "${flags_helpStr_}" : '.*'`
961
+ if [ ${__FLAGS_GETOPT_VERS} -eq ${__FLAGS_GETOPT_VERS_STD} \
962
+ -o ${flags_helpStrLen_} -lt ${flags_columns_} ]; then
963
+ # indented to match help string
964
+ echo "${flags_helpStr_}" >&2
965
+ else
966
+ # indented four from left to allow for longer defaults as long flag
967
+ # names might be used too, making things too long
968
+ echo " ${flags_defaultStr_}" >&2
969
+ fi
970
+ fi
971
+ done
972
+ fi
973
+
974
+ unset flags_boolStr_ flags_default_ flags_defaultStr_ flags_emptyStr_ \
975
+ flags_flagStr_ flags_help_ flags_helpStr flags_helpStrLen flags_name_ \
976
+ flags_columns_ flags_short_ flags_type_
977
+ return ${FLAGS_TRUE}
978
+ }
979
+
980
+ # Reset shflags back to an uninitialized state.
981
+ #
982
+ # Args:
983
+ # none
984
+ # Returns:
985
+ # nothing
986
+ flags_reset()
987
+ {
988
+ for flags_name_ in ${__flags_longNames}; do
989
+ flags_strToEval_="unset FLAGS_${flags_name_}"
990
+ for flags_type_ in \
991
+ ${__FLAGS_INFO_DEFAULT} \
992
+ ${__FLAGS_INFO_HELP} \
993
+ ${__FLAGS_INFO_SHORT} \
994
+ ${__FLAGS_INFO_TYPE}
995
+ do
996
+ flags_strToEval_=\
997
+ "${flags_strToEval_} __flags_${flags_name_}_${flags_type_}"
998
+ done
999
+ eval ${flags_strToEval_}
1000
+ done
1001
+
1002
+ # reset internal variables
1003
+ __flags_boolNames=' '
1004
+ __flags_longNames=' '
1005
+ __flags_shortNames=' '
1006
+
1007
+ unset flags_name_ flags_type_ flags_strToEval_
1008
+ }
1009
+
1010
+ # parse stops on first non-option arg
1011
+ FLAGS_SUB="$FLAGS_FALSE"
1012
+