nixme-vagrant 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. data/.gitignore +15 -0
  2. data/.yardopts +1 -0
  3. data/CHANGELOG.md +261 -0
  4. data/Gemfile +21 -0
  5. data/LICENSE +21 -0
  6. data/README.md +61 -0
  7. data/Rakefile +22 -0
  8. data/bin/vagrant +22 -0
  9. data/config/default.rb +39 -0
  10. data/contrib/README.md +12 -0
  11. data/contrib/emacs/vagrant.el +8 -0
  12. data/contrib/vim/vagrantfile.vim +9 -0
  13. data/keys/README.md +17 -0
  14. data/keys/vagrant +27 -0
  15. data/keys/vagrant.ppk +26 -0
  16. data/keys/vagrant.pub +1 -0
  17. data/lib/vagrant.rb +42 -0
  18. data/lib/vagrant/action.rb +134 -0
  19. data/lib/vagrant/action/box.rb +11 -0
  20. data/lib/vagrant/action/box/destroy.rb +21 -0
  21. data/lib/vagrant/action/box/download.rb +72 -0
  22. data/lib/vagrant/action/box/package.rb +19 -0
  23. data/lib/vagrant/action/box/unpackage.rb +55 -0
  24. data/lib/vagrant/action/box/verify.rb +23 -0
  25. data/lib/vagrant/action/builder.rb +124 -0
  26. data/lib/vagrant/action/builtin.rb +104 -0
  27. data/lib/vagrant/action/env.rb +7 -0
  28. data/lib/vagrant/action/env/set.rb +18 -0
  29. data/lib/vagrant/action/environment.rb +50 -0
  30. data/lib/vagrant/action/general.rb +8 -0
  31. data/lib/vagrant/action/general/package.rb +109 -0
  32. data/lib/vagrant/action/general/validate.rb +19 -0
  33. data/lib/vagrant/action/vm.rb +31 -0
  34. data/lib/vagrant/action/vm/boot.rb +48 -0
  35. data/lib/vagrant/action/vm/check_box.rb +28 -0
  36. data/lib/vagrant/action/vm/check_guest_additions.rb +30 -0
  37. data/lib/vagrant/action/vm/clean_machine_folder.rb +43 -0
  38. data/lib/vagrant/action/vm/clear_forwarded_ports.rb +39 -0
  39. data/lib/vagrant/action/vm/clear_nfs_exports.rb +20 -0
  40. data/lib/vagrant/action/vm/clear_shared_folders.rb +32 -0
  41. data/lib/vagrant/action/vm/customize.rb +21 -0
  42. data/lib/vagrant/action/vm/destroy.rb +19 -0
  43. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +30 -0
  44. data/lib/vagrant/action/vm/discard_state.rb +22 -0
  45. data/lib/vagrant/action/vm/export.rb +52 -0
  46. data/lib/vagrant/action/vm/forward_ports.rb +133 -0
  47. data/lib/vagrant/action/vm/forward_ports_helpers.rb +28 -0
  48. data/lib/vagrant/action/vm/halt.rb +29 -0
  49. data/lib/vagrant/action/vm/host_name.rb +21 -0
  50. data/lib/vagrant/action/vm/import.rb +35 -0
  51. data/lib/vagrant/action/vm/match_mac_address.rb +21 -0
  52. data/lib/vagrant/action/vm/network.rb +139 -0
  53. data/lib/vagrant/action/vm/nfs.rb +159 -0
  54. data/lib/vagrant/action/vm/nfs_helpers.rb +11 -0
  55. data/lib/vagrant/action/vm/package.rb +23 -0
  56. data/lib/vagrant/action/vm/package_vagrantfile.rb +33 -0
  57. data/lib/vagrant/action/vm/provision.rb +41 -0
  58. data/lib/vagrant/action/vm/resume.rb +20 -0
  59. data/lib/vagrant/action/vm/share_folders.rb +70 -0
  60. data/lib/vagrant/action/vm/suspend.rb +20 -0
  61. data/lib/vagrant/action/warden.rb +79 -0
  62. data/lib/vagrant/box.rb +90 -0
  63. data/lib/vagrant/box_collection.rb +53 -0
  64. data/lib/vagrant/cli.rb +55 -0
  65. data/lib/vagrant/command.rb +25 -0
  66. data/lib/vagrant/command/base.rb +106 -0
  67. data/lib/vagrant/command/box.rb +33 -0
  68. data/lib/vagrant/command/destroy.rb +17 -0
  69. data/lib/vagrant/command/group_base.rb +107 -0
  70. data/lib/vagrant/command/halt.rb +18 -0
  71. data/lib/vagrant/command/helpers.rb +33 -0
  72. data/lib/vagrant/command/init.rb +14 -0
  73. data/lib/vagrant/command/named_base.rb +14 -0
  74. data/lib/vagrant/command/package.rb +41 -0
  75. data/lib/vagrant/command/provision.rb +17 -0
  76. data/lib/vagrant/command/reload.rb +17 -0
  77. data/lib/vagrant/command/resume.rb +17 -0
  78. data/lib/vagrant/command/ssh.rb +42 -0
  79. data/lib/vagrant/command/ssh_config.rb +26 -0
  80. data/lib/vagrant/command/status.rb +22 -0
  81. data/lib/vagrant/command/suspend.rb +17 -0
  82. data/lib/vagrant/command/up.rb +19 -0
  83. data/lib/vagrant/command/upgrade_to_060.rb +45 -0
  84. data/lib/vagrant/command/version.rb +13 -0
  85. data/lib/vagrant/config.rb +123 -0
  86. data/lib/vagrant/config/base.rb +85 -0
  87. data/lib/vagrant/config/error_recorder.rb +19 -0
  88. data/lib/vagrant/config/nfs.rb +10 -0
  89. data/lib/vagrant/config/package.rb +9 -0
  90. data/lib/vagrant/config/ssh.rb +33 -0
  91. data/lib/vagrant/config/top.rb +61 -0
  92. data/lib/vagrant/config/vagrant.rb +16 -0
  93. data/lib/vagrant/config/vm.rb +137 -0
  94. data/lib/vagrant/config/vm/provisioner.rb +56 -0
  95. data/lib/vagrant/config/vm/sub_vm.rb +17 -0
  96. data/lib/vagrant/data_store.rb +70 -0
  97. data/lib/vagrant/downloaders.rb +7 -0
  98. data/lib/vagrant/downloaders/base.rb +23 -0
  99. data/lib/vagrant/downloaders/file.rb +22 -0
  100. data/lib/vagrant/downloaders/http.rb +64 -0
  101. data/lib/vagrant/environment.rb +392 -0
  102. data/lib/vagrant/errors.rb +332 -0
  103. data/lib/vagrant/hosts.rb +7 -0
  104. data/lib/vagrant/hosts/base.rb +77 -0
  105. data/lib/vagrant/hosts/bsd.rb +52 -0
  106. data/lib/vagrant/hosts/linux.rb +47 -0
  107. data/lib/vagrant/plugin.rb +57 -0
  108. data/lib/vagrant/provisioners.rb +9 -0
  109. data/lib/vagrant/provisioners/base.rb +63 -0
  110. data/lib/vagrant/provisioners/chef.rb +130 -0
  111. data/lib/vagrant/provisioners/chef_server.rb +97 -0
  112. data/lib/vagrant/provisioners/chef_solo.rb +139 -0
  113. data/lib/vagrant/provisioners/puppet.rb +137 -0
  114. data/lib/vagrant/provisioners/puppet_server.rb +55 -0
  115. data/lib/vagrant/provisioners/shell.rb +52 -0
  116. data/lib/vagrant/ssh.rb +173 -0
  117. data/lib/vagrant/ssh/session.rb +119 -0
  118. data/lib/vagrant/systems.rb +10 -0
  119. data/lib/vagrant/systems/base.rb +87 -0
  120. data/lib/vagrant/systems/debian.rb +36 -0
  121. data/lib/vagrant/systems/freebsd.rb +84 -0
  122. data/lib/vagrant/systems/gentoo.rb +27 -0
  123. data/lib/vagrant/systems/linux.rb +79 -0
  124. data/lib/vagrant/systems/linux/config.rb +21 -0
  125. data/lib/vagrant/systems/linux/error.rb +9 -0
  126. data/lib/vagrant/systems/redhat.rb +39 -0
  127. data/lib/vagrant/systems/solaris.rb +62 -0
  128. data/lib/vagrant/test_helpers.rb +128 -0
  129. data/lib/vagrant/ui.rb +69 -0
  130. data/lib/vagrant/util.rb +13 -0
  131. data/lib/vagrant/util/busy.rb +59 -0
  132. data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
  133. data/lib/vagrant/util/plain_logger.rb +25 -0
  134. data/lib/vagrant/util/platform.rb +58 -0
  135. data/lib/vagrant/util/resource_logger.rb +63 -0
  136. data/lib/vagrant/util/retryable.rb +25 -0
  137. data/lib/vagrant/util/stacked_proc_runner.rb +35 -0
  138. data/lib/vagrant/util/template_renderer.rb +83 -0
  139. data/lib/vagrant/version.rb +6 -0
  140. data/lib/vagrant/vm.rb +176 -0
  141. data/templates/chef_server_client.erb +18 -0
  142. data/templates/chef_solo_solo.erb +19 -0
  143. data/templates/commands/init/Vagrantfile.erb +63 -0
  144. data/templates/config/validation_failed.erb +7 -0
  145. data/templates/locales/en.yml +531 -0
  146. data/templates/network_entry_debian.erb +8 -0
  147. data/templates/network_entry_gentoo.erb +7 -0
  148. data/templates/network_entry_redhat.erb +8 -0
  149. data/templates/nfs/exports.erb +5 -0
  150. data/templates/nfs/exports_linux.erb +5 -0
  151. data/templates/package_Vagrantfile.erb +11 -0
  152. data/templates/ssh_config.erb +9 -0
  153. data/test/locales/en.yml +8 -0
  154. data/test/test_helper.rb +26 -0
  155. data/test/vagrant/action/box/destroy_test.rb +18 -0
  156. data/test/vagrant/action/box/download_test.rb +125 -0
  157. data/test/vagrant/action/box/package_test.rb +25 -0
  158. data/test/vagrant/action/box/unpackage_test.rb +84 -0
  159. data/test/vagrant/action/box/verify_test.rb +30 -0
  160. data/test/vagrant/action/builder_test.rb +203 -0
  161. data/test/vagrant/action/env/set_test.rb +24 -0
  162. data/test/vagrant/action/environment_test.rb +27 -0
  163. data/test/vagrant/action/general/package_test.rb +268 -0
  164. data/test/vagrant/action/general/validate_test.rb +31 -0
  165. data/test/vagrant/action/vm/boot_test.rb +66 -0
  166. data/test/vagrant/action/vm/check_box_test.rb +56 -0
  167. data/test/vagrant/action/vm/check_guest_additions_test.rb +9 -0
  168. data/test/vagrant/action/vm/clean_machine_folder_test.rb +84 -0
  169. data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +72 -0
  170. data/test/vagrant/action/vm/clear_nfs_exports_test.rb +22 -0
  171. data/test/vagrant/action/vm/clear_shared_folders_test.rb +49 -0
  172. data/test/vagrant/action/vm/customize_test.rb +30 -0
  173. data/test/vagrant/action/vm/destroy_test.rb +25 -0
  174. data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +49 -0
  175. data/test/vagrant/action/vm/discard_state_test.rb +45 -0
  176. data/test/vagrant/action/vm/export_test.rb +107 -0
  177. data/test/vagrant/action/vm/forward_ports_helpers_test.rb +70 -0
  178. data/test/vagrant/action/vm/forward_ports_test.rb +194 -0
  179. data/test/vagrant/action/vm/halt_test.rb +79 -0
  180. data/test/vagrant/action/vm/host_name_test.rb +36 -0
  181. data/test/vagrant/action/vm/import_test.rb +66 -0
  182. data/test/vagrant/action/vm/match_mac_address_test.rb +36 -0
  183. data/test/vagrant/action/vm/network_test.rb +286 -0
  184. data/test/vagrant/action/vm/nfs_helpers_test.rb +26 -0
  185. data/test/vagrant/action/vm/nfs_test.rb +260 -0
  186. data/test/vagrant/action/vm/package_test.rb +25 -0
  187. data/test/vagrant/action/vm/package_vagrantfile_test.rb +46 -0
  188. data/test/vagrant/action/vm/provision_test.rb +90 -0
  189. data/test/vagrant/action/vm/resume_test.rb +35 -0
  190. data/test/vagrant/action/vm/share_folders_test.rb +139 -0
  191. data/test/vagrant/action/vm/suspend_test.rb +35 -0
  192. data/test/vagrant/action/warden_test.rb +119 -0
  193. data/test/vagrant/action_test.rb +89 -0
  194. data/test/vagrant/box_collection_test.rb +45 -0
  195. data/test/vagrant/box_test.rb +74 -0
  196. data/test/vagrant/cli_test.rb +35 -0
  197. data/test/vagrant/command/base_test.rb +23 -0
  198. data/test/vagrant/command/group_base_test.rb +15 -0
  199. data/test/vagrant/command/helpers_test.rb +88 -0
  200. data/test/vagrant/command/package_test.rb +27 -0
  201. data/test/vagrant/config/base_test.rb +52 -0
  202. data/test/vagrant/config/error_recorder_test.rb +18 -0
  203. data/test/vagrant/config/ssh_test.rb +12 -0
  204. data/test/vagrant/config/vagrant_test.rb +35 -0
  205. data/test/vagrant/config/vm/provisioner_test.rb +92 -0
  206. data/test/vagrant/config/vm_test.rb +86 -0
  207. data/test/vagrant/config_test.rb +162 -0
  208. data/test/vagrant/data_store_test.rb +77 -0
  209. data/test/vagrant/downloaders/base_test.rb +28 -0
  210. data/test/vagrant/downloaders/file_test.rb +48 -0
  211. data/test/vagrant/downloaders/http_test.rb +80 -0
  212. data/test/vagrant/environment_test.rb +508 -0
  213. data/test/vagrant/errors_test.rb +42 -0
  214. data/test/vagrant/hosts/base_test.rb +46 -0
  215. data/test/vagrant/hosts/bsd_test.rb +53 -0
  216. data/test/vagrant/hosts/linux_test.rb +54 -0
  217. data/test/vagrant/plugin_test.rb +9 -0
  218. data/test/vagrant/provisioners/base_test.rb +63 -0
  219. data/test/vagrant/provisioners/chef_server_test.rb +186 -0
  220. data/test/vagrant/provisioners/chef_solo_test.rb +219 -0
  221. data/test/vagrant/provisioners/chef_test.rb +179 -0
  222. data/test/vagrant/provisioners/puppet_server_test.rb +68 -0
  223. data/test/vagrant/provisioners/puppet_test.rb +182 -0
  224. data/test/vagrant/provisioners/shell_test.rb +68 -0
  225. data/test/vagrant/ssh/session_test.rb +40 -0
  226. data/test/vagrant/ssh_test.rb +342 -0
  227. data/test/vagrant/systems/base_test.rb +18 -0
  228. data/test/vagrant/systems/linux_test.rb +114 -0
  229. data/test/vagrant/ui_test.rb +29 -0
  230. data/test/vagrant/util/busy_test.rb +106 -0
  231. data/test/vagrant/util/hash_with_indifferent_access_test.rb +39 -0
  232. data/test/vagrant/util/plain_logger_test.rb +17 -0
  233. data/test/vagrant/util/platform_test.rb +18 -0
  234. data/test/vagrant/util/resource_logger_test.rb +78 -0
  235. data/test/vagrant/util/retryable_test.rb +38 -0
  236. data/test/vagrant/util/stacked_proc_runner_test.rb +43 -0
  237. data/test/vagrant/util/template_renderer_test.rb +145 -0
  238. data/test/vagrant/vm_test.rb +291 -0
  239. data/vagrant.gemspec +36 -0
  240. metadata +442 -0
@@ -0,0 +1,55 @@
1
+ require 'thor'
2
+
3
+ module Vagrant
4
+ # Entrypoint for the Vagrant CLI. This class should never be
5
+ # initialized directly (like a typical Thor class). Instead,
6
+ # use {Environment#cli} to invoke the CLI.
7
+ #
8
+ # # Defining Custom CLI Commands
9
+ #
10
+ # If you're looking to define custom CLI commands, then look at
11
+ # one of the two following classes:
12
+ #
13
+ # * {Command::Base} - Implementing a single command such as `vagrant up`, e.g.
14
+ # one without subcommands. Also take a look at {Command::NamedBase}.
15
+ # * {Command::GroupBase} - Implementing a command with subcommands, such as
16
+ # `vagrant box`, which has the `list`, `add`, etc. subcommands.
17
+ #
18
+ # The above linked classes contain the main documentation for each
19
+ # type of command.
20
+ class CLI < Thor
21
+ # Registers the given class with the CLI so it can be accessed.
22
+ # The class must be a subclass of either {Command::Base} or {Command::GroupBase}.
23
+ # Don't call this method directly, instead call the {Command::Base.register}
24
+ # or {Command::GroupBase.register} methods.
25
+ #
26
+ # @param [Class] klass Command class
27
+ # @param [String] name Command name, accessed at `vagrant NAME`
28
+ # @param [String] usage Command usage, such as "vagrant NAME [--option]"
29
+ # @param [String] description Description of the command shown during the
30
+ # command listing.
31
+ # @param [Hash] opts Other options (not gone into detail here, look at
32
+ # the source instead).
33
+ def self.register(klass, name, usage, description, opts=nil)
34
+ opts ||= {}
35
+
36
+ if klass <= Command::GroupBase
37
+ # A subclass of GroupBase is a subcommand, since it contains
38
+ # many smaller commands within it.
39
+ desc usage, description, opts
40
+ subcommand name, klass
41
+ elsif klass <= Command::Base
42
+ # A subclass of Base is a single command, since it
43
+ # is invoked as a whole (as Thor::Group)
44
+ desc usage, description, opts
45
+ define_method(name) { |*args| invoke klass, args }
46
+ end
47
+
48
+ if opts[:alias]
49
+ # Alises are defined for this command, so properly alias the
50
+ # newly defined method/subcommand:
51
+ map opts[:alias] => name
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,25 @@
1
+ module Vagrant
2
+ module Command
3
+ autoload :Base, 'vagrant/command/base'
4
+ autoload :GroupBase, 'vagrant/command/group_base'
5
+ autoload :Helpers, 'vagrant/command/helpers'
6
+ autoload :NamedBase, 'vagrant/command/named_base'
7
+ end
8
+ end
9
+
10
+ # The built-in commands must always be loaded
11
+ require 'vagrant/command/box'
12
+ require 'vagrant/command/destroy'
13
+ require 'vagrant/command/halt'
14
+ require 'vagrant/command/init'
15
+ require 'vagrant/command/package'
16
+ require 'vagrant/command/provision'
17
+ require 'vagrant/command/reload'
18
+ require 'vagrant/command/resume'
19
+ require 'vagrant/command/ssh'
20
+ require 'vagrant/command/ssh_config'
21
+ require 'vagrant/command/status'
22
+ require 'vagrant/command/suspend'
23
+ require 'vagrant/command/up'
24
+ require 'vagrant/command/upgrade_to_060'
25
+ require 'vagrant/command/version'
@@ -0,0 +1,106 @@
1
+ require 'thor/group'
2
+ require 'thor/actions'
3
+
4
+ module Vagrant
5
+ module Command
6
+ # A {Base} is the superclass for all commands which are single
7
+ # commands, e.g. `vagrant init`, `vagrant up`. Not commands like
8
+ # `vagrant box add`. For commands which have more subcommands, use
9
+ # a {GroupBase}.
10
+ #
11
+ # A {Base} is a subclass of `Thor::Group`, so view the documentation
12
+ # there on how to add arguments, descriptions etc. The important note
13
+ # about this is that when invoked, _all public methods_ will be called
14
+ # in the order they are defined. If you don't want a method called when
15
+ # the command is invoked, it must be made `protected` or `private`.
16
+ #
17
+ # The best way to get examples of how to create your own command is to
18
+ # view the various Vagrant commands, which are relatively simple, and
19
+ # can be found in the Vagrant source tree at `lib/vagrant/command/`.
20
+ #
21
+ # # Defining a New Command
22
+ #
23
+ # To define a new single command, create a new class which inherits
24
+ # from this class, then call {register} to register the command. That's
25
+ # it! When the command is invoked, _all public methods_ will be called.
26
+ # Below is an example `SayHello` class:
27
+ #
28
+ # class SayHello < Vagrant::Command::Base
29
+ # register "hello", "Says hello"
30
+ #
31
+ # def hello
32
+ # env.ui.info "Hello"
33
+ # end
34
+ # end
35
+ #
36
+ # In this case, the above class is invokable via `vagrant hello`. To give
37
+ # this a try, just copy and paste the above into a Vagrantfile somewhere.
38
+ # The command will be available for that project!
39
+ #
40
+ # Also note that the above example uses `env.ui` to output. It is recommended
41
+ # you use this instead of raw "puts" since it is configurable and provides
42
+ # additional functionality, such as colors and asking for user input. See
43
+ # the {UI} class for more information.
44
+ #
45
+ # ## Defining Command-line Options
46
+ #
47
+ # Most command line actions won't be as simple as `vagrant hello`, and will
48
+ # probably require parameters or switches. Luckily, Thor makes adding these
49
+ # easy:
50
+ #
51
+ # class SayHello < Vagrant::Command::Base
52
+ # register "hello", "Says hello"
53
+ # argument :name, :type => :string
54
+ #
55
+ # def hello
56
+ # env.ui.info "Hello, #{name}"
57
+ # end
58
+ # end
59
+ #
60
+ # Then, the above can be invoked with `vagrant hello Mitchell` which would
61
+ # output "Hello, Mitchell." If instead you're looking for switches, such as
62
+ # "--name Mitchell", then take a look at `class_option`, an example of which
63
+ # can be found in the {PackageCommand}.
64
+ class Base < Thor::Group
65
+ include Thor::Actions
66
+ include Helpers
67
+
68
+ attr_reader :env
69
+
70
+ # Register the command with the main Vagrant CLI under the
71
+ # given name. The name will be used for accessing it from the CLI,
72
+ # so if you name it "lamp", then the command to invoke this
73
+ # will be `vagrant lamp`.
74
+ #
75
+ # The description is used when the help is listed, and is meant to be
76
+ # a brief (one sentence) description of what the command does.
77
+ #
78
+ # Some additional options may be passed in as the last parameter:
79
+ #
80
+ # * `:alias` - If given as an array or string, these will be aliases
81
+ # for the same command. For example, `vagrant version` is also
82
+ # `vagrant --version` and `vagrant -v`
83
+ #
84
+ # @param [String] usage
85
+ # @param [String] description
86
+ # @param [Hash] opts
87
+ def self.register(usage, description, opts=nil)
88
+ desc description
89
+ CLI.register(self, extract_name_from_usage(usage), usage, desc, opts)
90
+ end
91
+
92
+ def initialize(*args)
93
+ super
94
+ initialize_environment(*args)
95
+ end
96
+
97
+ protected
98
+
99
+ # Extracts the name of the command from a usage string. Example:
100
+ # `init [box_name] [box_url]` becomes just `init`.
101
+ def self.extract_name_from_usage(usage)
102
+ /^([-_a-zA-Z0-9]+)(\s+(.+?))?$/.match(usage).to_a[1]
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,33 @@
1
+ module Vagrant
2
+ module Command
3
+ class BoxCommand < GroupBase
4
+ register "box", "Commands to manage system boxes"
5
+
6
+ desc "add NAME URI", "Add a box to the system"
7
+ def add(name, uri)
8
+ Box.add(env, name, uri)
9
+ end
10
+
11
+ desc "remove NAME", "Remove a box from the system"
12
+ def remove(name)
13
+ b = env.boxes.find(name)
14
+ raise Errors::BoxNotFound, :name => name if !b
15
+ b.destroy
16
+ end
17
+
18
+ desc "repackage NAME", "Repackage an installed box into a `.box` file."
19
+ def repackage(name)
20
+ b = env.boxes.find(name)
21
+ raise Errors::BoxNotFound, :name => name if !b
22
+ b.repackage
23
+ end
24
+
25
+ desc "list", "Lists all installed boxes"
26
+ def list
27
+ boxes = env.boxes.sort
28
+ return env.ui.warn(I18n.t("vagrant.commands.box.no_installed_boxes"), :prefix => false) if boxes.empty?
29
+ boxes.each { |b| env.ui.info(b.name, :prefix => false) }
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,17 @@
1
+ module Vagrant
2
+ module Command
3
+ class DestroyCommand < NamedBase
4
+ register "destroy", "Destroy the environment, deleting the created virtual machines"
5
+
6
+ def execute
7
+ target_vms.each do |vm|
8
+ if vm.created?
9
+ vm.destroy
10
+ else
11
+ vm.env.ui.info I18n.t("vagrant.commands.common.vm_not_created")
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,107 @@
1
+ require 'thor'
2
+ require 'thor/actions'
3
+
4
+ module Vagrant
5
+ module Command
6
+ # A {GroupBase} is the superclass which should be used if you're
7
+ # creating a CLI command which has subcommands such as `vagrant box`,
8
+ # which has subcommands such as `add`, `remove`, `list`. If you're
9
+ # creating a simple command which has no subcommands, such as `vagrant up`,
10
+ # then use {Base} instead.
11
+ #
12
+ # Unlike {Base}, where all public methods are executed, in a {GroupBase},
13
+ # each public method defines a separate task which can be invoked. The best
14
+ # way to get examples of how to create a {GroupBase} command is to look
15
+ # at the built-in commands, such as {BoxCommand}.
16
+ #
17
+ # # Defining a New Command
18
+ #
19
+ # To define a new command with subcommands, create a new class which inherits
20
+ # from this class, then call {register} to register the command. That's it! When
21
+ # the command is invoked, the method matching the subcommand is invoked. An
22
+ # example is shown below:
23
+ #
24
+ # class SayCommand < Vagrant::Command::GroupBase
25
+ # register "say", "Say hello or goodbye"
26
+ #
27
+ # desc "hello", "say hello"
28
+ # def hello
29
+ # env.ui.info "Hello"
30
+ # end
31
+ #
32
+ # desc "goodbye", "say goodbye"
33
+ # def goodbye
34
+ # env.ui.info "Goodbye"
35
+ # end
36
+ # end
37
+ #
38
+ # In this case, the above class is invokable via `vagrant say hello` or
39
+ # `vagrant say goodbye`. To give it a try yourself, just copy and paste
40
+ # the above into a Vagrantfile somewhere, and run `vagrant` from within
41
+ # that directory. You should see the new command!
42
+ #
43
+ # Also notice that in the above, each task follows a `desc` call. This
44
+ # call is used to provide usage and description for each task, and is
45
+ # required.
46
+ #
47
+ # ## Defining Command-line Options
48
+ #
49
+ # ### Arguments
50
+ #
51
+ # To define arguments to your commands, such as `vagrant say hello mitchell`,
52
+ # then you simply define them as arguments to the method implementing the
53
+ # task. An example is shown below (only the method, to keep things brief):
54
+ #
55
+ # def hello(name)
56
+ # env.ui.info "Hello, #{name}"
57
+ # end
58
+ #
59
+ # Then, if `vagrant say hello mitchell` was called, then the output would
60
+ # be "Hello, mitchell"
61
+ #
62
+ # ### Switches or Other Options
63
+ #
64
+ # TODO
65
+ class GroupBase < Thor
66
+ include Thor::Actions
67
+ include Helpers
68
+
69
+ attr_reader :env
70
+
71
+ # Register the command with the main Vagrant CLI under the given
72
+ # usage. The usage will be used for accessing it from the CLI,
73
+ # so if you give it a usage of `lamp [subcommand]`, then the command
74
+ # to invoke this will be `vagrant lamp` (with a subcommand).
75
+ #
76
+ # The description is used when a listing of the commands is given
77
+ # and is meant to be a brief (one sentence) description of what this
78
+ # command does.
79
+ #
80
+ # Some additional options may be passed in as the last parameter:
81
+ #
82
+ # * `:alias` - If given as an array or string, these will be aliases
83
+ # for the same command. For example, `vagrant version` is also
84
+ # `vagrant --version` and `vagrant -v`
85
+ #
86
+ # @param [String] usage
87
+ # @param [String] description
88
+ # @param [Hash] opts
89
+ def self.register(usage, description, opts=nil)
90
+ @_name = Base.extract_name_from_usage(usage)
91
+ CLI.register(self, @_name, usage, description, opts)
92
+ end
93
+
94
+ def initialize(*args)
95
+ super
96
+ initialize_environment(*args)
97
+ end
98
+
99
+ protected
100
+
101
+ # Override the basename to include the subcommand name.
102
+ def self.basename
103
+ "#{super} #{@_name}"
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,18 @@
1
+ module Vagrant
2
+ module Command
3
+ class HaltCommand < NamedBase
4
+ class_option :force, :type => :boolean, :default => false, :aliases => "-f"
5
+ register "halt", "Halt the running VMs in the environment"
6
+
7
+ def execute
8
+ target_vms.each do |vm|
9
+ if vm.created?
10
+ vm.halt(options)
11
+ else
12
+ vm.env.ui.info I18n.t("vagrant.commands.common.vm_not_created")
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ module Vagrant
2
+ module Command
3
+ module Helpers
4
+ # Initializes the environment by pulling the environment out of
5
+ # the configuration hash and sets up the UI if necessary.
6
+ def initialize_environment(args, options, config)
7
+ raise Errors::CLIMissingEnvironment if !config[:env]
8
+ @env = config[:env]
9
+ end
10
+
11
+ # This returns an array of {VM} objects depending on the arguments
12
+ # given to the command.
13
+ def target_vms(name=nil)
14
+ raise Errors::NoEnvironmentError if !env.root_path
15
+
16
+ name ||= self.name rescue nil
17
+
18
+ @target_vms ||= begin
19
+ if env.multivm?
20
+ return env.vms_ordered if !name
21
+ vm = env.vms[name.to_sym]
22
+ raise Errors::VMNotFoundError, :name => name if !vm
23
+ else
24
+ raise Errors::MultiVMEnvironmentRequired if name
25
+ vm = env.vms.values.first
26
+ end
27
+
28
+ [vm]
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,14 @@
1
+ module Vagrant
2
+ module Command
3
+ class InitCommand < Base
4
+ argument :box_name, :type => :string, :optional => true, :default => "base"
5
+ argument :box_url, :type => :string, :optional => true
6
+ source_root File.expand_path("templates/commands/init", Vagrant.source_root)
7
+ register "init [box_name] [box_url]", "Initializes the current folder for Vagrant usage"
8
+
9
+ def execute
10
+ template "Vagrantfile.erb", "Vagrantfile"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module Vagrant
2
+ module Command
3
+ # Same as {Base} except adds the `name` argument for you. This superclass
4
+ # is useful if you're creating a command which should be able to target
5
+ # a specific VM in a multi-VM environment. For example, in a multi-VM
6
+ # environment, `vagrant up` "ups" all defined VMs, but you can specify a
7
+ # name such as `vagrant up web` to target only a specific VM. That name
8
+ # argument is from {NamedBase}. Of course, you can always add it manually
9
+ # yourself, as well.
10
+ class NamedBase < Base
11
+ argument :name, :type => :string, :optional => true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,41 @@
1
+ module Vagrant
2
+ module Command
3
+ class PackageCommand < NamedBase
4
+ class_option :base, :type => :string, :default => nil
5
+ class_option :output, :type => :string, :default => nil
6
+ class_option :include, :type => :array, :default => nil
7
+ class_option :vagrantfile, :type => :string, :default => nil
8
+ register "package", "Package a Vagrant environment for distribution"
9
+
10
+ def execute
11
+ return package_base if options[:base]
12
+ package_target
13
+ end
14
+
15
+ protected
16
+
17
+ def package_base
18
+ vm = VM.find(options[:base], env)
19
+ raise Errors::BaseVMNotFound, :name => options[:base] if !vm.created?
20
+ package_vm(vm)
21
+ end
22
+
23
+ def package_target
24
+ raise Errors::MultiVMTargetRequired, :command => "package" if target_vms.length > 1
25
+ vm = target_vms.first
26
+ raise Errors::VMNotCreatedError if !vm.created?
27
+ package_vm(vm)
28
+ end
29
+
30
+ def package_vm(vm)
31
+ opts = options.inject({}) do |acc, data|
32
+ k,v = data
33
+ acc["package.#{k}"] = v
34
+ acc
35
+ end
36
+
37
+ vm.package(opts)
38
+ end
39
+ end
40
+ end
41
+ end