boxcar 0.10005.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +48 -0
- data/.gitsetup.yml +6 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +696 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +40 -0
- data/LICENSE +21 -0
- data/README.md +91 -0
- data/Rakefile +18 -0
- data/VERSION +1 -0
- data/bin/_bump +126 -0
- data/bin/_jason +172 -0
- data/bin/_log4sh +3840 -0
- data/bin/_meat +172 -0
- data/bin/_prime +8 -0
- data/bin/_shflags +1012 -0
- data/bin/_shunit +1048 -0
- data/bin/_sub +37 -0
- data/bin/_treadstone +8 -0
- data/bin/_versions +174 -0
- data/bin/build +15 -0
- data/bin/bump +15 -0
- data/bin/edit +15 -0
- data/bin/publish +15 -0
- data/bin/stub +15 -0
- data/bin/vagrant +60 -0
- data/boxcar.gemspec +32 -0
- data/config/default.rb +30 -0
- data/contrib/README.md +12 -0
- data/contrib/emacs/vagrant.el +8 -0
- data/contrib/vim/vagrantfile.vim +9 -0
- data/keys/README.md +17 -0
- data/keys/vagrant +27 -0
- data/keys/vagrant.pub +1 -0
- data/lib/development.rb +25 -0
- data/lib/vagrant.rb +197 -0
- data/lib/vagrant/action.rb +63 -0
- data/lib/vagrant/action/box/destroy.rb +25 -0
- data/lib/vagrant/action/box/download.rb +84 -0
- data/lib/vagrant/action/box/package.rb +19 -0
- data/lib/vagrant/action/box/unpackage.rb +61 -0
- data/lib/vagrant/action/box/verify.rb +23 -0
- data/lib/vagrant/action/builder.rb +128 -0
- data/lib/vagrant/action/builtin.rb +171 -0
- data/lib/vagrant/action/env/set.rb +21 -0
- data/lib/vagrant/action/environment.rb +12 -0
- data/lib/vagrant/action/general/check_virtualbox.rb +28 -0
- data/lib/vagrant/action/general/package.rb +101 -0
- data/lib/vagrant/action/general/validate.rb +18 -0
- data/lib/vagrant/action/runner.rb +53 -0
- data/lib/vagrant/action/vm/boot.rb +53 -0
- data/lib/vagrant/action/vm/check_accessible.rb +23 -0
- data/lib/vagrant/action/vm/check_box.rb +33 -0
- data/lib/vagrant/action/vm/check_guest_additions.rb +38 -0
- data/lib/vagrant/action/vm/check_port_collisions.rb +89 -0
- data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
- data/lib/vagrant/action/vm/clear_forwarded_ports.rb +18 -0
- data/lib/vagrant/action/vm/clear_network_interfaces.rb +31 -0
- data/lib/vagrant/action/vm/clear_shared_folders.rb +18 -0
- data/lib/vagrant/action/vm/customize.rb +36 -0
- data/lib/vagrant/action/vm/default_name.rb +22 -0
- data/lib/vagrant/action/vm/destroy.rb +19 -0
- data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +20 -0
- data/lib/vagrant/action/vm/discard_state.rb +22 -0
- data/lib/vagrant/action/vm/export.rb +57 -0
- data/lib/vagrant/action/vm/forward_ports.rb +92 -0
- data/lib/vagrant/action/vm/halt.rb +32 -0
- data/lib/vagrant/action/vm/host_name.rb +21 -0
- data/lib/vagrant/action/vm/import.rb +48 -0
- data/lib/vagrant/action/vm/match_mac_address.rb +21 -0
- data/lib/vagrant/action/vm/network.rb +403 -0
- data/lib/vagrant/action/vm/nfs.rb +196 -0
- data/lib/vagrant/action/vm/package.rb +23 -0
- data/lib/vagrant/action/vm/package_vagrantfile.rb +36 -0
- data/lib/vagrant/action/vm/provision.rb +61 -0
- data/lib/vagrant/action/vm/provisioner_cleanup.rb +26 -0
- data/lib/vagrant/action/vm/prune_nfs_exports.rb +20 -0
- data/lib/vagrant/action/vm/resume.rb +20 -0
- data/lib/vagrant/action/vm/sane_defaults.rb +78 -0
- data/lib/vagrant/action/vm/setup_package_files.rb +54 -0
- data/lib/vagrant/action/vm/share_folders.rb +114 -0
- data/lib/vagrant/action/vm/suspend.rb +20 -0
- data/lib/vagrant/action/warden.rb +92 -0
- data/lib/vagrant/box.rb +44 -0
- data/lib/vagrant/box_collection.rb +58 -0
- data/lib/vagrant/cli.rb +76 -0
- data/lib/vagrant/command.rb +24 -0
- data/lib/vagrant/command/base.rb +167 -0
- data/lib/vagrant/command/box.rb +58 -0
- data/lib/vagrant/command/box_add.rb +37 -0
- data/lib/vagrant/command/box_list.rb +28 -0
- data/lib/vagrant/command/box_remove.rb +27 -0
- data/lib/vagrant/command/box_repackage.rb +27 -0
- data/lib/vagrant/command/destroy.rb +64 -0
- data/lib/vagrant/command/gem.rb +39 -0
- data/lib/vagrant/command/halt.rb +39 -0
- data/lib/vagrant/command/init.rb +40 -0
- data/lib/vagrant/command/package.rb +75 -0
- data/lib/vagrant/command/provision.rb +40 -0
- data/lib/vagrant/command/reload.rb +39 -0
- data/lib/vagrant/command/resume.rb +33 -0
- data/lib/vagrant/command/ssh.rb +90 -0
- data/lib/vagrant/command/ssh_config.rb +51 -0
- data/lib/vagrant/command/start_mixins.rb +26 -0
- data/lib/vagrant/command/status.rb +36 -0
- data/lib/vagrant/command/suspend.rb +33 -0
- data/lib/vagrant/command/up.rb +40 -0
- data/lib/vagrant/communication.rb +7 -0
- data/lib/vagrant/communication/base.rb +56 -0
- data/lib/vagrant/communication/ssh.rb +229 -0
- data/lib/vagrant/config.rb +49 -0
- data/lib/vagrant/config/base.rb +82 -0
- data/lib/vagrant/config/container.rb +37 -0
- data/lib/vagrant/config/error_recorder.rb +19 -0
- data/lib/vagrant/config/loader.rb +127 -0
- data/lib/vagrant/config/nfs.rb +8 -0
- data/lib/vagrant/config/package.rb +7 -0
- data/lib/vagrant/config/ssh.rb +27 -0
- data/lib/vagrant/config/top.rb +72 -0
- data/lib/vagrant/config/vagrant.rb +14 -0
- data/lib/vagrant/config/vm.rb +168 -0
- data/lib/vagrant/config/vm/provisioner.rb +52 -0
- data/lib/vagrant/config/vm/sub_vm.rb +17 -0
- data/lib/vagrant/data_store.rb +92 -0
- data/lib/vagrant/downloaders.rb +7 -0
- data/lib/vagrant/downloaders/base.rb +25 -0
- data/lib/vagrant/downloaders/file.rb +22 -0
- data/lib/vagrant/downloaders/http.rb +97 -0
- data/lib/vagrant/driver.rb +8 -0
- data/lib/vagrant/driver/virtualbox.rb +134 -0
- data/lib/vagrant/driver/virtualbox_4_0.rb +459 -0
- data/lib/vagrant/driver/virtualbox_4_1.rb +459 -0
- data/lib/vagrant/driver/virtualbox_4_2.rb +606 -0
- data/lib/vagrant/driver/virtualbox_base.rb +309 -0
- data/lib/vagrant/environment.rb +517 -0
- data/lib/vagrant/errors.rb +441 -0
- data/lib/vagrant/guest.rb +18 -0
- data/lib/vagrant/guest/arch.rb +56 -0
- data/lib/vagrant/guest/base.rb +99 -0
- data/lib/vagrant/guest/debian.rb +64 -0
- data/lib/vagrant/guest/fedora.rb +66 -0
- data/lib/vagrant/guest/freebsd.rb +86 -0
- data/lib/vagrant/guest/gentoo.rb +46 -0
- data/lib/vagrant/guest/linux.rb +118 -0
- data/lib/vagrant/guest/linux/config.rb +19 -0
- data/lib/vagrant/guest/linux/error.rb +9 -0
- data/lib/vagrant/guest/openbsd.rb +20 -0
- data/lib/vagrant/guest/redhat.rb +67 -0
- data/lib/vagrant/guest/solaris.rb +118 -0
- data/lib/vagrant/guest/suse.rb +9 -0
- data/lib/vagrant/guest/ubuntu.rb +23 -0
- data/lib/vagrant/hosts.rb +37 -0
- data/lib/vagrant/hosts/arch.rb +55 -0
- data/lib/vagrant/hosts/base.rb +66 -0
- data/lib/vagrant/hosts/bsd.rb +97 -0
- data/lib/vagrant/hosts/fedora.rb +47 -0
- data/lib/vagrant/hosts/freebsd.rb +41 -0
- data/lib/vagrant/hosts/gentoo.rb +20 -0
- data/lib/vagrant/hosts/linux.rb +94 -0
- data/lib/vagrant/hosts/opensuse.rb +30 -0
- data/lib/vagrant/hosts/windows.rb +16 -0
- data/lib/vagrant/plugin.rb +81 -0
- data/lib/vagrant/provisioners.rb +12 -0
- data/lib/vagrant/provisioners/base.rb +44 -0
- data/lib/vagrant/provisioners/chef.rb +168 -0
- data/lib/vagrant/provisioners/chef_client.rb +132 -0
- data/lib/vagrant/provisioners/chef_solo.rb +234 -0
- data/lib/vagrant/provisioners/puppet.rb +175 -0
- data/lib/vagrant/provisioners/puppet_server.rb +78 -0
- data/lib/vagrant/provisioners/shell.rb +96 -0
- data/lib/vagrant/registry.rb +52 -0
- data/lib/vagrant/ssh.rb +126 -0
- data/lib/vagrant/test_helpers.rb +154 -0
- data/lib/vagrant/ui.rb +168 -0
- data/lib/vagrant/util.rb +12 -0
- data/lib/vagrant/util/ansi_escape_code_remover.rb +34 -0
- data/lib/vagrant/util/busy.rb +59 -0
- data/lib/vagrant/util/counter.rb +24 -0
- data/lib/vagrant/util/file_checksum.rb +38 -0
- data/lib/vagrant/util/file_mode.rb +12 -0
- data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
- data/lib/vagrant/util/is_port_open.rb +38 -0
- data/lib/vagrant/util/line_ending_helpers.rb +14 -0
- data/lib/vagrant/util/network_ip.rb +28 -0
- data/lib/vagrant/util/platform.rb +68 -0
- data/lib/vagrant/util/retryable.rb +25 -0
- data/lib/vagrant/util/safe_exec.rb +36 -0
- data/lib/vagrant/util/safe_puts.rb +31 -0
- data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
- data/lib/vagrant/util/subprocess.rb +247 -0
- data/lib/vagrant/util/template_renderer.rb +83 -0
- data/lib/vagrant/version.rb +7 -0
- data/lib/vagrant/vm.rb +195 -0
- data/libexec/build +30 -0
- data/libexec/build-gem +30 -0
- data/libexec/bump +32 -0
- data/libexec/edit-gem +81 -0
- data/libexec/publish +58 -0
- data/libexec/publish-gem +58 -0
- data/libexec/stub-prepare +37 -0
- data/tasks/acceptance.rake +113 -0
- data/tasks/bundler.rake +3 -0
- data/tasks/test.rake +20 -0
- data/templates/commands/init/Vagrantfile.erb +99 -0
- data/templates/commands/ssh_config/config.erb +15 -0
- data/templates/config/validation_failed.erb +7 -0
- data/templates/guests/arch/network_dhcp.erb +7 -0
- data/templates/guests/arch/network_static.erb +7 -0
- data/templates/guests/debian/network_dhcp.erb +6 -0
- data/templates/guests/debian/network_static.erb +7 -0
- data/templates/guests/fedora/network_dhcp.erb +6 -0
- data/templates/guests/fedora/network_static.erb +13 -0
- data/templates/guests/freebsd/network_dhcp.erb +3 -0
- data/templates/guests/freebsd/network_static.erb +3 -0
- data/templates/guests/gentoo/network_dhcp.erb +4 -0
- data/templates/guests/gentoo/network_static.erb +4 -0
- data/templates/guests/redhat/network_dhcp.erb +6 -0
- data/templates/guests/redhat/network_static.erb +7 -0
- data/templates/locales/en.yml +747 -0
- data/templates/nfs/exports.erb +5 -0
- data/templates/nfs/exports_freebsd.erb +5 -0
- data/templates/nfs/exports_linux.erb +5 -0
- data/templates/package_Vagrantfile.erb +11 -0
- data/templates/provisioners/chef_client/client.erb +32 -0
- data/templates/provisioners/chef_solo/solo.erb +25 -0
- data/test/acceptance/base.rb +48 -0
- data/test/acceptance/box_test.rb +99 -0
- data/test/acceptance/destroy_test.rb +37 -0
- data/test/acceptance/halt_test.rb +72 -0
- data/test/acceptance/init_test.rb +33 -0
- data/test/acceptance/networking/host_only_test.rb +37 -0
- data/test/acceptance/networking/port_forward_test.rb +125 -0
- data/test/acceptance/package_test.rb +46 -0
- data/test/acceptance/provisioning/basic_test.rb +61 -0
- data/test/acceptance/provisioning/chef_solo_test.rb +37 -0
- data/test/acceptance/provisioning/shell_test.rb +53 -0
- data/test/acceptance/resume_test.rb +17 -0
- data/test/acceptance/shared_folders_test.rb +84 -0
- data/test/acceptance/skeletons/chef_solo_basic/README.md +3 -0
- data/test/acceptance/skeletons/chef_solo_basic/cookbooks/basic/recipes/default.rb +5 -0
- data/test/acceptance/skeletons/chef_solo_json/README.md +3 -0
- data/test/acceptance/skeletons/chef_solo_json/cookbooks/basic/recipes/default.rb +6 -0
- data/test/acceptance/skeletons/provisioner_multi/README.md +3 -0
- data/test/acceptance/skeletons/provisioner_multi/cookbooks/basic/recipes/default.rb +5 -0
- data/test/acceptance/ssh_test.rb +46 -0
- data/test/acceptance/support/config.rb +42 -0
- data/test/acceptance/support/isolated_environment.rb +117 -0
- data/test/acceptance/support/matchers/have_color.rb +9 -0
- data/test/acceptance/support/matchers/match_output.rb +14 -0
- data/test/acceptance/support/matchers/succeed.rb +14 -0
- data/test/acceptance/support/network_tests.rb +29 -0
- data/test/acceptance/support/output.rb +95 -0
- data/test/acceptance/support/shared/base_context.rb +72 -0
- data/test/acceptance/support/shared/command_examples.rb +33 -0
- data/test/acceptance/support/virtualbox.rb +36 -0
- data/test/acceptance/suspend_test.rb +56 -0
- data/test/acceptance/up_basic_test.rb +33 -0
- data/test/acceptance/up_with_box_url.rb +40 -0
- data/test/acceptance/vagrant_test.rb +47 -0
- data/test/acceptance/version_test.rb +15 -0
- data/test/buildbot/README.md +72 -0
- data/test/buildbot/buildbot_config/__init__.py +0 -0
- data/test/buildbot/buildbot_config/config/__init__.py +0 -0
- data/test/buildbot/buildbot_config/config/loader.py +24 -0
- data/test/buildbot/buildbot_config/config/master.py +24 -0
- data/test/buildbot/buildbot_config/config/slave.py +22 -0
- data/test/buildbot/buildbot_config/master/__init__.py +6 -0
- data/test/buildbot/buildbot_config/master/builders.py +78 -0
- data/test/buildbot/buildbot_config/master/buildsteps.py +100 -0
- data/test/buildbot/buildbot_config/master/change_sources.py +8 -0
- data/test/buildbot/buildbot_config/master/schedulers.py +32 -0
- data/test/buildbot/buildbot_config/master/slaves.py +60 -0
- data/test/buildbot/buildbot_config/master/status.py +52 -0
- data/test/buildbot/master/Makefile.sample +28 -0
- data/test/buildbot/master/buildbot.tac +36 -0
- data/test/buildbot/master/master.cfg +67 -0
- data/test/buildbot/master/public_html/bg_gradient.jpg +0 -0
- data/test/buildbot/master/public_html/default.css +545 -0
- data/test/buildbot/master/public_html/favicon.ico +0 -0
- data/test/buildbot/master/public_html/robots.txt +10 -0
- data/test/buildbot/master/public_html/static/css/bootstrap-1.4.0.min.css +356 -0
- data/test/buildbot/master/public_html/static/css/prettify.css +97 -0
- data/test/buildbot/master/public_html/static/css/syntax.css +60 -0
- data/test/buildbot/master/public_html/static/css/vagrant.base.css +205 -0
- data/test/buildbot/master/public_html/static/images/base_box_mac.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/getting-started/success.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/icons/error.png +0 -0
- data/test/buildbot/master/public_html/static/images/vagrant_chilling.png +0 -0
- data/test/buildbot/master/public_html/static/images/vagrant_holding.png +0 -0
- data/test/buildbot/master/public_html/static/images/vagrant_looking.png +0 -0
- data/test/buildbot/master/public_html/static/images/windows/alter_path.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/windows/edit_path.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/windows/environment_variables_button.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/windows/port_and_ppk_path.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/windows/ppk_selection.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/windows/putty_first_screen.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/windows/save_result.jpg +0 -0
- data/test/buildbot/master/public_html/static/images/windows/vbox_manage_default_location.jpg +0 -0
- data/test/buildbot/master/public_html/static/js/bootstrap-tabs.js +80 -0
- data/test/buildbot/master/public_html/static/js/jquery-1.7.min.js +4 -0
- data/test/buildbot/master/templates/authfail.html +9 -0
- data/test/buildbot/master/templates/build.html +205 -0
- data/test/buildbot/master/templates/builder.html +118 -0
- data/test/buildbot/master/templates/builders.html +33 -0
- data/test/buildbot/master/templates/buildslave.html +72 -0
- data/test/buildbot/master/templates/buildslaves.html +70 -0
- data/test/buildbot/master/templates/change.html +15 -0
- data/test/buildbot/master/templates/layouts/base.html +58 -0
- data/test/buildbot/master/templates/macros/box.html +37 -0
- data/test/buildbot/master/templates/macros/build_line.html +50 -0
- data/test/buildbot/master/templates/macros/change.html +81 -0
- data/test/buildbot/master/templates/macros/forms.html +300 -0
- data/test/buildbot/master/templates/root.html +42 -0
- data/test/buildbot/master/templates/waterfall.html +53 -0
- data/test/buildbot/requirements.txt +4 -0
- data/test/buildbot/scripts/deploy.sh +38 -0
- data/test/buildbot/scripts/setup.sh +107 -0
- data/test/buildbot/slave/buildbot.tac +43 -0
- data/test/buildbot/slave/info/admin +1 -0
- data/test/buildbot/slave/info/host +1 -0
- data/test/buildbot/tests/__init__.py +0 -0
- data/test/buildbot/tests/master/__init__.py +0 -0
- data/test/buildbot/tests/master/test_slaves.py +41 -0
- data/test/buildbot/vendor/choices-0.4.0.tar.gz +0 -0
- data/test/config/acceptance_boxes.yml +7 -0
- data/test/support/isolated_environment.rb +46 -0
- data/test/support/tempdir.rb +34 -0
- data/test/unit/base.rb +21 -0
- data/test/unit/support/isolated_environment.rb +47 -0
- data/test/unit/support/shared/base_context.rb +30 -0
- data/test/unit/vagrant/action/builder_test.rb +156 -0
- data/test/unit/vagrant/action/environment_test.rb +16 -0
- data/test/unit/vagrant/action/runner_test.rb +65 -0
- data/test/unit/vagrant/action/warden_test.rb +92 -0
- data/test/unit/vagrant/box_collection_test.rb +56 -0
- data/test/unit/vagrant/box_test.rb +34 -0
- data/test/unit/vagrant/command/base_test.rb +150 -0
- data/test/unit/vagrant/config/base_test.rb +48 -0
- data/test/unit/vagrant/config/loader_test.rb +79 -0
- data/test/unit/vagrant/config/ssh_test.rb +17 -0
- data/test/unit/vagrant/config/top_test.rb +69 -0
- data/test/unit/vagrant/config/vm_test.rb +71 -0
- data/test/unit/vagrant/config_test.rb +27 -0
- data/test/unit/vagrant/data_store_test.rb +79 -0
- data/test/unit/vagrant/downloaders/base_test.rb +18 -0
- data/test/unit/vagrant/downloaders/file_test.rb +75 -0
- data/test/unit/vagrant/downloaders/http_test.rb +19 -0
- data/test/unit/vagrant/environment_test.rb +212 -0
- data/test/unit/vagrant/hosts_test.rb +36 -0
- data/test/unit/vagrant/registry_test.rb +74 -0
- data/test/unit/vagrant/util/ansi_escape_code_remover_test.rb +16 -0
- data/test/unit/vagrant/util/file_checksum_test.rb +23 -0
- data/test/unit/vagrant/util/hash_with_indifferent_access_test.rb +38 -0
- data/test/unit/vagrant/util/is_port_open_test.rb +53 -0
- data/test/unit/vagrant/util/line_endings_helper_test.rb +16 -0
- data/test/unit/vagrant/util/network_ip_test.rb +17 -0
- data/test/unit/vagrant/util/retryable_test.rb +106 -0
- data/test/unit/vagrant_test.rb +27 -0
- data/test/unit_legacy/locales/en.yml +8 -0
- data/test/unit_legacy/test_helper.rb +32 -0
- data/test/unit_legacy/vagrant/action/box/destroy_test.rb +18 -0
- data/test/unit_legacy/vagrant/action/box/download_test.rb +125 -0
- data/test/unit_legacy/vagrant/action/box/package_test.rb +25 -0
- data/test/unit_legacy/vagrant/action/box/unpackage_test.rb +84 -0
- data/test/unit_legacy/vagrant/action/box/verify_test.rb +30 -0
- data/test/unit_legacy/vagrant/action/env/set_test.rb +24 -0
- data/test/unit_legacy/vagrant/action/general/package_test.rb +268 -0
- data/test/unit_legacy/vagrant/action/general/validate_test.rb +31 -0
- data/test/unit_legacy/vagrant/action/vm/boot_test.rb +66 -0
- data/test/unit_legacy/vagrant/action/vm/check_accessible_test.rb +61 -0
- data/test/unit_legacy/vagrant/action/vm/check_box_test.rb +61 -0
- data/test/unit_legacy/vagrant/action/vm/check_guest_additions_test.rb +9 -0
- data/test/unit_legacy/vagrant/action/vm/clean_machine_folder_test.rb +84 -0
- data/test/unit_legacy/vagrant/action/vm/clear_forwarded_ports_test.rb +52 -0
- data/test/unit_legacy/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
- data/test/unit_legacy/vagrant/action/vm/clear_shared_folders_test.rb +40 -0
- data/test/unit_legacy/vagrant/action/vm/customize_test.rb +37 -0
- data/test/unit_legacy/vagrant/action/vm/destroy_test.rb +25 -0
- data/test/unit_legacy/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +49 -0
- data/test/unit_legacy/vagrant/action/vm/discard_state_test.rb +45 -0
- data/test/unit_legacy/vagrant/action/vm/export_test.rb +107 -0
- data/test/unit_legacy/vagrant/action/vm/forward_ports_helpers_test.rb +77 -0
- data/test/unit_legacy/vagrant/action/vm/forward_ports_test.rb +197 -0
- data/test/unit_legacy/vagrant/action/vm/halt_test.rb +79 -0
- data/test/unit_legacy/vagrant/action/vm/host_name_test.rb +36 -0
- data/test/unit_legacy/vagrant/action/vm/import_test.rb +66 -0
- data/test/unit_legacy/vagrant/action/vm/match_mac_address_test.rb +40 -0
- data/test/unit_legacy/vagrant/action/vm/modify_test.rb +38 -0
- data/test/unit_legacy/vagrant/action/vm/network_test.rb +286 -0
- data/test/unit_legacy/vagrant/action/vm/nfs_helpers_test.rb +26 -0
- data/test/unit_legacy/vagrant/action/vm/nfs_test.rb +260 -0
- data/test/unit_legacy/vagrant/action/vm/package_test.rb +25 -0
- data/test/unit_legacy/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
- data/test/unit_legacy/vagrant/action/vm/provision_test.rb +65 -0
- data/test/unit_legacy/vagrant/action/vm/provisioner_cleanup_test.rb +56 -0
- data/test/unit_legacy/vagrant/action/vm/resume_test.rb +35 -0
- data/test/unit_legacy/vagrant/action/vm/share_folders_test.rb +144 -0
- data/test/unit_legacy/vagrant/action/vm/suspend_test.rb +35 -0
- data/test/unit_legacy/vagrant/action_test.rb +89 -0
- data/test/unit_legacy/vagrant/box_collection_test.rb +45 -0
- data/test/unit_legacy/vagrant/box_test.rb +74 -0
- data/test/unit_legacy/vagrant/cli_test.rb +35 -0
- data/test/unit_legacy/vagrant/command/base_test.rb +23 -0
- data/test/unit_legacy/vagrant/command/group_base_test.rb +15 -0
- data/test/unit_legacy/vagrant/command/helpers_test.rb +88 -0
- data/test/unit_legacy/vagrant/command/init_test.rb +10 -0
- data/test/unit_legacy/vagrant/command/package_test.rb +27 -0
- data/test/unit_legacy/vagrant/config/base_test.rb +52 -0
- data/test/unit_legacy/vagrant/config/error_recorder_test.rb +18 -0
- data/test/unit_legacy/vagrant/config/ssh_test.rb +12 -0
- data/test/unit_legacy/vagrant/config/vagrant_test.rb +35 -0
- data/test/unit_legacy/vagrant/config/vm/provisioner_test.rb +92 -0
- data/test/unit_legacy/vagrant/config/vm_test.rb +47 -0
- data/test/unit_legacy/vagrant/config_test.rb +148 -0
- data/test/unit_legacy/vagrant/downloaders/http_test.rb +93 -0
- data/test/unit_legacy/vagrant/environment_test.rb +539 -0
- data/test/unit_legacy/vagrant/errors_test.rb +42 -0
- data/test/unit_legacy/vagrant/hosts/base_test.rb +46 -0
- data/test/unit_legacy/vagrant/hosts/bsd_test.rb +53 -0
- data/test/unit_legacy/vagrant/hosts/linux_test.rb +54 -0
- data/test/unit_legacy/vagrant/plugin_test.rb +9 -0
- data/test/unit_legacy/vagrant/provisioners/base_test.rb +63 -0
- data/test/unit_legacy/vagrant/provisioners/chef_client_test.rb +190 -0
- data/test/unit_legacy/vagrant/provisioners/chef_solo_test.rb +115 -0
- data/test/unit_legacy/vagrant/provisioners/chef_test.rb +209 -0
- data/test/unit_legacy/vagrant/provisioners/puppet_server_test.rb +68 -0
- data/test/unit_legacy/vagrant/provisioners/puppet_test.rb +182 -0
- data/test/unit_legacy/vagrant/provisioners/shell_test.rb +79 -0
- data/test/unit_legacy/vagrant/ssh/session_test.rb +40 -0
- data/test/unit_legacy/vagrant/ssh_test.rb +304 -0
- data/test/unit_legacy/vagrant/systems/base_test.rb +18 -0
- data/test/unit_legacy/vagrant/systems/linux_test.rb +104 -0
- data/test/unit_legacy/vagrant/util/busy_test.rb +106 -0
- data/test/unit_legacy/vagrant/util/counter_test.rb +29 -0
- data/test/unit_legacy/vagrant/util/platform_test.rb +18 -0
- data/test/unit_legacy/vagrant/util/stacked_proc_runner_test.rb +43 -0
- data/test/unit_legacy/vagrant/util/template_renderer_test.rb +145 -0
- data/test/unit_legacy/vagrant/vm_test.rb +300 -0
- data/vagrant.gemspec +39 -0
- data/vendor/cache/contest-0.1.3.gem +0 -0
- data/vendor/cache/diff-lcs-1.1.3.gem +0 -0
- data/vendor/cache/erubis-2.7.0.gem +0 -0
- data/vendor/cache/i18n-0.6.1.gem +0 -0
- data/vendor/cache/json-1.5.4.gem +0 -0
- data/vendor/cache/log4r-1.1.10.gem +0 -0
- data/vendor/cache/metaclass-0.0.1.gem +0 -0
- data/vendor/cache/minitest-2.5.1.gem +0 -0
- data/vendor/cache/mocha-0.13.1.gem +0 -0
- data/vendor/cache/rake-10.0.2.gem +0 -0
- data/vendor/cache/rspec-core-2.8.0.gem +0 -0
- data/vendor/cache/rspec-expectations-2.8.0.gem +0 -0
- data/vendor/cache/rspec-mocks-2.8.0.gem +0 -0
- metadata +676 -0
@@ -0,0 +1,92 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module Action
|
5
|
+
# The action warden is a middleware which injects itself between
|
6
|
+
# every other middleware, watching for exceptions which are raised
|
7
|
+
# and performing proper cleanup on every action by calling the `recover`
|
8
|
+
# method. The warden therefore allows middlewares to not worry about
|
9
|
+
# exceptional events, and by providing a simple callback, can clean up
|
10
|
+
# in any erroneous case.
|
11
|
+
#
|
12
|
+
# Warden will "just work" behind the scenes, and is not of particular
|
13
|
+
# interest except to those who are curious about the internal workings
|
14
|
+
# of Vagrant.
|
15
|
+
class Warden
|
16
|
+
attr_accessor :actions, :stack
|
17
|
+
|
18
|
+
def initialize(actions, env)
|
19
|
+
@stack = []
|
20
|
+
@actions = actions.map { |m| finalize_action(m, env) }
|
21
|
+
@logger = Log4r::Logger.new("vagrant::action::warden")
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(env)
|
25
|
+
return if @actions.empty?
|
26
|
+
|
27
|
+
begin
|
28
|
+
# Call the next middleware in the sequence, appending to the stack
|
29
|
+
# of "recoverable" middlewares in case something goes wrong!
|
30
|
+
raise Errors::VagrantInterrupt if env[:interrupted]
|
31
|
+
action = @actions.shift
|
32
|
+
@logger.info("Calling action: #{action}")
|
33
|
+
@stack.unshift(action).first.call(env)
|
34
|
+
raise Errors::VagrantInterrupt if env[:interrupted]
|
35
|
+
rescue SystemExit
|
36
|
+
# This means that an "exit" or "abort" was called. In these cases,
|
37
|
+
# we just exit immediately.
|
38
|
+
raise
|
39
|
+
rescue Exception => e
|
40
|
+
@logger.error("Error occurred: #{e}")
|
41
|
+
env["vagrant.error"] = e
|
42
|
+
|
43
|
+
# Something went horribly wrong. Start the rescue chain then
|
44
|
+
# reraise the exception to properly kick us out of limbo here.
|
45
|
+
begin_rescue(env)
|
46
|
+
raise
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Begins the recovery sequence for all middlewares which have run.
|
51
|
+
# It does this by calling `recover` (if it exists) on each middleware
|
52
|
+
# which has already run, in reverse order.
|
53
|
+
def begin_rescue(env)
|
54
|
+
@stack.each do |act|
|
55
|
+
if act.respond_to?(:recover)
|
56
|
+
@logger.info("Calling recover: #{act}")
|
57
|
+
act.recover(env)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Clear stack so that warden down the middleware chain doesn't
|
62
|
+
# rescue again.
|
63
|
+
@stack.clear
|
64
|
+
end
|
65
|
+
|
66
|
+
# A somewhat confusing function which simply initializes each
|
67
|
+
# middleware properly to call the next middleware in the sequence.
|
68
|
+
def finalize_action(action, env)
|
69
|
+
klass, args, block = action
|
70
|
+
|
71
|
+
# Default the arguments to an empty array. Otherwise in Ruby 1.8
|
72
|
+
# a `nil` args will actually pass `nil` into the class.
|
73
|
+
args ||= []
|
74
|
+
|
75
|
+
if klass.is_a?(Class)
|
76
|
+
# A action klass which is to be instantiated with the
|
77
|
+
# app, env, and any arguments given
|
78
|
+
klass.new(self, env, *args, &block)
|
79
|
+
elsif klass.respond_to?(:call)
|
80
|
+
# Make it a lambda which calls the item then forwards
|
81
|
+
# up the chain
|
82
|
+
lambda do |e|
|
83
|
+
klass.call(e)
|
84
|
+
self.call(e)
|
85
|
+
end
|
86
|
+
else
|
87
|
+
raise "Invalid action: #{action.inspect}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
data/lib/vagrant/box.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
module Vagrant
|
2
|
+
# Represents a "box," which is simply a packaged vagrant environment.
|
3
|
+
# Boxes are simply `tar` files which contain an exported VirtualBox
|
4
|
+
# virtual machine, at the least. They are created with `vagrant package`
|
5
|
+
# and may contain additional files if specified by the creator. This
|
6
|
+
# class serves to help manage these boxes, although most of the logic
|
7
|
+
# is kicked out to middlewares.
|
8
|
+
class Box
|
9
|
+
# The name of the box.
|
10
|
+
attr_reader :name
|
11
|
+
|
12
|
+
# The directory where this box is stored
|
13
|
+
attr_reader :directory
|
14
|
+
|
15
|
+
# Creates a new box instance. Given an optional `name` parameter,
|
16
|
+
# newly created instance will have that name, otherwise it defaults
|
17
|
+
# to `nil`.
|
18
|
+
#
|
19
|
+
# **Note:** This method does not actually _create_ the box, but merely
|
20
|
+
# returns a new, abstract representation of it. To add a box, see {#add}.
|
21
|
+
def initialize(name, directory, action_runner)
|
22
|
+
@name = name
|
23
|
+
@directory = directory
|
24
|
+
@action_runner = action_runner
|
25
|
+
end
|
26
|
+
|
27
|
+
# Begins the process of destroying this box. This cannot be undone!
|
28
|
+
def destroy
|
29
|
+
@action_runner.run(:box_remove, { :box_name => @name, :box_directory => @directory })
|
30
|
+
end
|
31
|
+
|
32
|
+
# Begins sequence to repackage this box.
|
33
|
+
def repackage(options=nil)
|
34
|
+
@action_runner.run(:box_repackage, { :box_name => @name, :box_directory => @directory })
|
35
|
+
end
|
36
|
+
|
37
|
+
# Implemented for comparison with other boxes. Comparison is implemented
|
38
|
+
# by simply comparing name.
|
39
|
+
def <=>(other)
|
40
|
+
return super if !other.is_a?(self.class)
|
41
|
+
name <=> other.name
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
# Represents a collection of boxes, providing helpful methods for
|
5
|
+
# finding boxes.
|
6
|
+
class BoxCollection
|
7
|
+
include Enumerable
|
8
|
+
extend Forwardable
|
9
|
+
def_delegators :@boxes, :length, :each
|
10
|
+
|
11
|
+
# The directory that the boxes are being searched for.
|
12
|
+
attr_reader :directory
|
13
|
+
|
14
|
+
# Initializes the class to search for boxes in the given directory.
|
15
|
+
def initialize(directory, action_runner)
|
16
|
+
@directory = directory
|
17
|
+
@boxes = []
|
18
|
+
@action_runner = action_runner
|
19
|
+
|
20
|
+
reload!
|
21
|
+
end
|
22
|
+
|
23
|
+
# Find a box in the collection by the given name. The name must
|
24
|
+
# be a string, for now.
|
25
|
+
def find(name)
|
26
|
+
@boxes.each do |box|
|
27
|
+
return box if box.name == name
|
28
|
+
end
|
29
|
+
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
# Adds a box to this collection with the given name and located
|
34
|
+
# at the given URL.
|
35
|
+
def add(name, url)
|
36
|
+
raise Errors::BoxAlreadyExists, :name => name if find(name)
|
37
|
+
|
38
|
+
@action_runner.run(:box_add,
|
39
|
+
:box_name => name,
|
40
|
+
:box_url => url,
|
41
|
+
:box_directory => @directory.join(name))
|
42
|
+
end
|
43
|
+
|
44
|
+
# Loads the list of all boxes from the source. This modifies the
|
45
|
+
# current array.
|
46
|
+
def reload!
|
47
|
+
@boxes.clear
|
48
|
+
|
49
|
+
Dir.open(@directory) do |dir|
|
50
|
+
dir.each do |d|
|
51
|
+
next if d == "." || d == ".." || !@directory.join(d).directory?
|
52
|
+
@boxes << Box.new(d, @directory.join(d), @action_runner)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
data/lib/vagrant/cli.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
module Vagrant
|
5
|
+
# Manages the command line interface to Vagrant.
|
6
|
+
class CLI < Command::Base
|
7
|
+
def initialize(argv, env)
|
8
|
+
super
|
9
|
+
|
10
|
+
@logger = Log4r::Logger.new("vagrant::cli")
|
11
|
+
@main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
|
12
|
+
|
13
|
+
@logger.info("CLI: #{@main_args.inspect} #{@sub_command.inspect} #{@sub_args.inspect}")
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute
|
17
|
+
if @main_args.include?("-v") || @main_args.include?("--version")
|
18
|
+
# Version short-circuits the whole thing. Just print
|
19
|
+
# the version and exit.
|
20
|
+
@env.ui.info(I18n.t("vagrant.commands.version.output",
|
21
|
+
:version => Vagrant::VERSION),
|
22
|
+
:prefix => false)
|
23
|
+
|
24
|
+
return 0
|
25
|
+
elsif @main_args.include?("-h") || @main_args.include?("--help")
|
26
|
+
# Help is next in short-circuiting everything. Print
|
27
|
+
# the help and exit.
|
28
|
+
help
|
29
|
+
return 0
|
30
|
+
end
|
31
|
+
|
32
|
+
# If we reached this far then we must have a subcommand. If not,
|
33
|
+
# then we also just print the help and exit.
|
34
|
+
command_class = Vagrant.commands.get(@sub_command.to_sym) if @sub_command
|
35
|
+
if !command_class || !@sub_command
|
36
|
+
help
|
37
|
+
return 0
|
38
|
+
end
|
39
|
+
@logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
|
40
|
+
|
41
|
+
# Initialize and execute the command class, returning the exit status.
|
42
|
+
result = command_class.new(@sub_args, @env).execute
|
43
|
+
result = 0 if !result.is_a?(Fixnum)
|
44
|
+
return result
|
45
|
+
end
|
46
|
+
|
47
|
+
# This prints out the help for the CLI.
|
48
|
+
def help
|
49
|
+
# We use the optionparser for this. Its just easier. We don't use
|
50
|
+
# an optionparser above because I don't think the performance hits
|
51
|
+
# of creating a whole object are worth checking only a couple flags.
|
52
|
+
opts = OptionParser.new do |opts|
|
53
|
+
opts.banner = "Usage: vagrant [-v] [-h] command [<args>]"
|
54
|
+
opts.separator ""
|
55
|
+
opts.on("-v", "--version", "Print the version and exit.")
|
56
|
+
opts.on("-h", "--help", "Print this help.")
|
57
|
+
opts.separator ""
|
58
|
+
opts.separator "Available subcommands:"
|
59
|
+
|
60
|
+
# Add the available subcommands as separators in order to print them
|
61
|
+
# out as well.
|
62
|
+
keys = []
|
63
|
+
Vagrant.commands.each { |key, value| keys << key.to_s }
|
64
|
+
|
65
|
+
keys.sort.each do |key|
|
66
|
+
opts.separator " #{key}"
|
67
|
+
end
|
68
|
+
|
69
|
+
opts.separator ""
|
70
|
+
opts.separator "For help on any individual command run `vagrant COMMAND -h`"
|
71
|
+
end
|
72
|
+
|
73
|
+
@env.ui.info(opts.help, :prefix => false)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Vagrant
|
2
|
+
module Command
|
3
|
+
autoload :Base, 'vagrant/command/base'
|
4
|
+
|
5
|
+
autoload :Box, 'vagrant/command/box'
|
6
|
+
autoload :BoxAdd, 'vagrant/command/box_add'
|
7
|
+
autoload :BoxRemove, 'vagrant/command/box_remove'
|
8
|
+
autoload :BoxRepackage, 'vagrant/command/box_repackage'
|
9
|
+
autoload :BoxList, 'vagrant/command/box_list'
|
10
|
+
autoload :Destroy, 'vagrant/command/destroy'
|
11
|
+
autoload :Gem, 'vagrant/command/gem'
|
12
|
+
autoload :Halt, 'vagrant/command/halt'
|
13
|
+
autoload :Init, 'vagrant/command/init'
|
14
|
+
autoload :Package, 'vagrant/command/package'
|
15
|
+
autoload :Provision, 'vagrant/command/provision'
|
16
|
+
autoload :Reload, 'vagrant/command/reload'
|
17
|
+
autoload :Resume, 'vagrant/command/resume'
|
18
|
+
autoload :SSH, 'vagrant/command/ssh'
|
19
|
+
autoload :SSHConfig, 'vagrant/command/ssh_config'
|
20
|
+
autoload :Status, 'vagrant/command/status'
|
21
|
+
autoload :Suspend, 'vagrant/command/suspend'
|
22
|
+
autoload :Up, 'vagrant/command/up'
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'log4r'
|
2
|
+
|
3
|
+
require "vagrant/util/safe_puts"
|
4
|
+
|
5
|
+
module Vagrant
|
6
|
+
module Command
|
7
|
+
# Base class for any CLI commands.
|
8
|
+
#
|
9
|
+
# This class provides documentation on the interface as well as helper
|
10
|
+
# functions that a command has.
|
11
|
+
class Base
|
12
|
+
include Util::SafePuts
|
13
|
+
|
14
|
+
def initialize(argv, env)
|
15
|
+
@argv = argv
|
16
|
+
@env = env
|
17
|
+
@logger = Log4r::Logger.new("vagrant::command::#{self.class.to_s.downcase}")
|
18
|
+
end
|
19
|
+
|
20
|
+
# This is what is called on the class to actually execute it. Any
|
21
|
+
# subclasses should implement this method and do any option parsing
|
22
|
+
# and validation here.
|
23
|
+
def execute; end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
# Parses the options given an OptionParser instance.
|
28
|
+
#
|
29
|
+
# This is a convenience method that properly handles duping the
|
30
|
+
# originally argv array so that it is not destroyed.
|
31
|
+
#
|
32
|
+
# This method will also automatically detect "-h" and "--help"
|
33
|
+
# and print help. And if any invalid options are detected, the help
|
34
|
+
# will be printed, as well.
|
35
|
+
#
|
36
|
+
# If this method returns `nil`, then you should assume that help
|
37
|
+
# was printed and parsing failed.
|
38
|
+
def parse_options(opts=nil)
|
39
|
+
# Creating a shallow copy of the arguments so the OptionParser
|
40
|
+
# doesn't destroy the originals.
|
41
|
+
argv = @argv.dup
|
42
|
+
|
43
|
+
# Default opts to a blank optionparser if none is given
|
44
|
+
opts ||= OptionParser.new
|
45
|
+
|
46
|
+
# Add the help option, which must be on every command.
|
47
|
+
opts.on_tail("-h", "--help", "Print this help") do
|
48
|
+
safe_puts(opts.help)
|
49
|
+
return nil
|
50
|
+
end
|
51
|
+
|
52
|
+
opts.parse!(argv)
|
53
|
+
return argv
|
54
|
+
rescue OptionParser::InvalidOption
|
55
|
+
raise Errors::CLIInvalidOptions, :help => opts.help.chomp
|
56
|
+
end
|
57
|
+
|
58
|
+
# Yields a VM for each target VM for the command.
|
59
|
+
#
|
60
|
+
# This is a convenience method for easily implementing methods that
|
61
|
+
# take a target VM (in the case of multi-VM) or every VM if no
|
62
|
+
# specific VM name is specified.
|
63
|
+
#
|
64
|
+
# @param [String] name The name of the VM. Nil if every VM.
|
65
|
+
# @param [Boolean] single_target If true, then an exception will be
|
66
|
+
# raised if more than one target is found.
|
67
|
+
def with_target_vms(names=nil, options=nil)
|
68
|
+
# Using VMs requires a Vagrant environment to be properly setup
|
69
|
+
raise Errors::NoEnvironmentError if !@env.root_path
|
70
|
+
|
71
|
+
# Setup the options hash
|
72
|
+
options ||= {}
|
73
|
+
|
74
|
+
# Require that names be an array
|
75
|
+
names ||= []
|
76
|
+
names = [names] if !names.is_a?(Array)
|
77
|
+
|
78
|
+
# First determine the proper array of VMs.
|
79
|
+
vms = []
|
80
|
+
if names.length > 0
|
81
|
+
names.each do |name|
|
82
|
+
raise Errors::MultiVMEnvironmentRequired if !@env.multivm?
|
83
|
+
|
84
|
+
if name =~ /^\/(.+?)\/$/
|
85
|
+
# This is a regular expression name, so we convert to a regular
|
86
|
+
# expression and allow that sort of matching.
|
87
|
+
regex = Regexp.new($1.to_s)
|
88
|
+
|
89
|
+
@env.vms.each do |name, vm|
|
90
|
+
vms << vm if name =~ regex
|
91
|
+
end
|
92
|
+
|
93
|
+
raise Errors::VMNoMatchError if vms.empty?
|
94
|
+
else
|
95
|
+
# String name, just look for a specific VM
|
96
|
+
vms << @env.vms[name.to_sym]
|
97
|
+
raise Errors::VMNotFoundError, :name => name if !vms[0]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
else
|
101
|
+
vms = @env.vms_ordered
|
102
|
+
end
|
103
|
+
|
104
|
+
# Make sure we're only working with one VM if single target
|
105
|
+
raise Errors::MultiVMTargetRequired if options[:single_target] && vms.length != 1
|
106
|
+
|
107
|
+
# If we asked for reversed ordering, then reverse it
|
108
|
+
vms.reverse! if options[:reverse]
|
109
|
+
|
110
|
+
# Go through each VM and yield it!
|
111
|
+
vms.each do |old_vm|
|
112
|
+
# We get a new VM from the environment here to avoid potentially
|
113
|
+
# stale VMs (if there was a config reload on the environment
|
114
|
+
# or something).
|
115
|
+
vm = @env.vms[old_vm.name]
|
116
|
+
yield vm
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# This method will split the argv given into three parts: the
|
121
|
+
# flags to this command, the subcommand, and the flags to the
|
122
|
+
# subcommand. For example:
|
123
|
+
#
|
124
|
+
# -v status -h -v
|
125
|
+
#
|
126
|
+
# The above would yield 3 parts:
|
127
|
+
#
|
128
|
+
# ["-v"]
|
129
|
+
# "status"
|
130
|
+
# ["-h", "-v"]
|
131
|
+
#
|
132
|
+
# These parts are useful because the first is a list of arguments
|
133
|
+
# given to the current command, the second is a subcommand, and the
|
134
|
+
# third are the commands given to the subcommand.
|
135
|
+
#
|
136
|
+
# @return [Array] The three parts.
|
137
|
+
def split_main_and_subcommand(argv)
|
138
|
+
# Initialize return variables
|
139
|
+
main_args = nil
|
140
|
+
sub_command = nil
|
141
|
+
sub_args = []
|
142
|
+
|
143
|
+
# We split the arguments into two: One set containing any
|
144
|
+
# flags before a word, and then the rest. The rest are what
|
145
|
+
# get actually sent on to the subcommand.
|
146
|
+
argv.each_index do |i|
|
147
|
+
if !argv[i].start_with?("-")
|
148
|
+
# We found the beginning of the sub command. Split the
|
149
|
+
# args up.
|
150
|
+
main_args = argv[0, i]
|
151
|
+
sub_command = argv[i]
|
152
|
+
sub_args = argv[i + 1, argv.length - i + 1]
|
153
|
+
|
154
|
+
# Break so we don't find the next non flag and shift our
|
155
|
+
# main args.
|
156
|
+
break
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# Handle the case that argv was empty or didn't contain any subcommand
|
161
|
+
main_args = argv.dup if main_args.nil?
|
162
|
+
|
163
|
+
return [main_args, sub_command, sub_args]
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|