vagrant 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (234) hide show
  1. data/.gitignore +1 -0
  2. data/.yardopts +1 -0
  3. data/CHANGELOG.md +56 -0
  4. data/Gemfile +14 -3
  5. data/Gemfile.lock +38 -11
  6. data/README.md +1 -1
  7. data/bin/vagrant +20 -5
  8. data/config/default.rb +6 -8
  9. data/lib/vagrant.rb +40 -13
  10. data/lib/vagrant/action.rb +56 -16
  11. data/lib/vagrant/action/box/destroy.rb +3 -1
  12. data/lib/vagrant/action/box/download.rb +8 -13
  13. data/lib/vagrant/action/box/unpackage.rb +8 -11
  14. data/lib/vagrant/action/box/verify.rb +3 -3
  15. data/lib/vagrant/action/builder.rb +3 -30
  16. data/lib/vagrant/action/builtin.rb +6 -1
  17. data/lib/vagrant/action/environment.rb +14 -62
  18. data/lib/vagrant/action/general/package.rb +29 -22
  19. data/lib/vagrant/action/vm/boot.rb +5 -12
  20. data/lib/vagrant/action/vm/check_box.rb +4 -4
  21. data/lib/vagrant/action/vm/check_guest_additions.rb +4 -6
  22. data/lib/vagrant/action/vm/clear_forwarded_ports.rb +2 -2
  23. data/lib/vagrant/action/vm/clear_nfs_exports.rb +1 -1
  24. data/lib/vagrant/action/vm/clear_shared_folders.rb +1 -1
  25. data/lib/vagrant/action/vm/customize.rb +1 -1
  26. data/lib/vagrant/action/vm/destroy.rb +1 -2
  27. data/lib/vagrant/action/vm/destroy_unused_network_interfaces.rb +1 -1
  28. data/lib/vagrant/action/vm/disable_networks.rb +11 -9
  29. data/lib/vagrant/action/vm/discard_state.rb +2 -2
  30. data/lib/vagrant/action/vm/export.rb +10 -11
  31. data/lib/vagrant/action/vm/forward_ports.rb +21 -9
  32. data/lib/vagrant/action/vm/halt.rb +3 -8
  33. data/lib/vagrant/action/vm/import.rb +16 -14
  34. data/lib/vagrant/action/vm/match_mac_address.rb +1 -1
  35. data/lib/vagrant/action/vm/network.rb +9 -16
  36. data/lib/vagrant/action/vm/nfs.rb +14 -18
  37. data/lib/vagrant/action/vm/provision.rb +5 -5
  38. data/lib/vagrant/action/vm/resume.rb +1 -1
  39. data/lib/vagrant/action/vm/share_folders.rb +6 -44
  40. data/lib/vagrant/action/vm/suspend.rb +1 -1
  41. data/lib/vagrant/action/warden.rb +74 -0
  42. data/lib/vagrant/box.rb +18 -82
  43. data/lib/vagrant/box_collection.rb +47 -0
  44. data/lib/vagrant/cli.rb +55 -0
  45. data/lib/vagrant/command/base.rb +106 -0
  46. data/lib/vagrant/command/box.rb +33 -0
  47. data/lib/vagrant/command/destroy.rb +17 -0
  48. data/lib/vagrant/command/group_base.rb +99 -0
  49. data/lib/vagrant/command/halt.rb +18 -0
  50. data/lib/vagrant/command/helpers.rb +33 -0
  51. data/lib/vagrant/command/init.rb +14 -0
  52. data/lib/vagrant/command/named_base.rb +14 -0
  53. data/lib/vagrant/command/package.rb +41 -0
  54. data/lib/vagrant/command/provision.rb +17 -0
  55. data/lib/vagrant/command/reload.rb +17 -0
  56. data/lib/vagrant/command/resume.rb +17 -0
  57. data/lib/vagrant/command/ssh.rb +41 -0
  58. data/lib/vagrant/command/ssh_config.rb +21 -0
  59. data/lib/vagrant/command/status.rb +23 -0
  60. data/lib/vagrant/command/suspend.rb +17 -0
  61. data/lib/vagrant/command/up.rb +20 -0
  62. data/lib/vagrant/command/upgrade_to_060.rb +45 -0
  63. data/lib/vagrant/command/version.rb +13 -0
  64. data/lib/vagrant/config.rb +107 -189
  65. data/lib/vagrant/config/base.rb +67 -0
  66. data/lib/vagrant/config/error_recorder.rb +19 -0
  67. data/lib/vagrant/config/nfs.rb +10 -0
  68. data/lib/vagrant/config/package.rb +9 -0
  69. data/lib/vagrant/config/ssh.rb +28 -0
  70. data/lib/vagrant/config/vagrant.rb +21 -0
  71. data/lib/vagrant/config/vm.rb +111 -0
  72. data/lib/vagrant/data_store.rb +68 -0
  73. data/lib/vagrant/downloaders/file.rb +3 -3
  74. data/lib/vagrant/downloaders/http.rb +5 -5
  75. data/lib/vagrant/environment.rb +246 -243
  76. data/lib/vagrant/errors.rb +306 -0
  77. data/lib/vagrant/hosts/base.rb +1 -1
  78. data/lib/vagrant/hosts/bsd.rb +3 -9
  79. data/lib/vagrant/hosts/linux.rb +3 -9
  80. data/lib/vagrant/plugin.rb +50 -0
  81. data/lib/vagrant/provisioners/base.rb +0 -6
  82. data/lib/vagrant/provisioners/chef.rb +63 -58
  83. data/lib/vagrant/provisioners/chef_server.rb +9 -11
  84. data/lib/vagrant/provisioners/chef_solo.rb +2 -2
  85. data/lib/vagrant/ssh.rb +34 -37
  86. data/lib/vagrant/systems/base.rb +0 -13
  87. data/lib/vagrant/systems/linux.rb +10 -33
  88. data/lib/vagrant/systems/solaris.rb +59 -0
  89. data/lib/vagrant/test_helpers.rb +109 -0
  90. data/lib/vagrant/ui.rb +65 -0
  91. data/lib/vagrant/util.rb +9 -19
  92. data/lib/vagrant/util/glob_loader.rb +19 -17
  93. data/lib/vagrant/util/hash_with_indifferent_access.rb +63 -0
  94. data/lib/vagrant/util/plain_logger.rb +2 -0
  95. data/lib/vagrant/util/platform.rb +2 -0
  96. data/lib/vagrant/util/resource_logger.rb +5 -70
  97. data/lib/vagrant/util/retryable.rb +25 -0
  98. data/lib/vagrant/util/template_renderer.rb +1 -1
  99. data/lib/vagrant/version.rb +1 -1
  100. data/lib/vagrant/vm.rb +27 -13
  101. data/templates/commands/init/Vagrantfile.erb +13 -0
  102. data/templates/config/validation_failed.erb +7 -0
  103. data/templates/locales/en.yml +402 -0
  104. data/templates/package_Vagrantfile.erb +1 -1
  105. data/test/locales/en.yml +8 -0
  106. data/test/test_helper.rb +19 -103
  107. data/test/vagrant/action/box/destroy_test.rb +7 -19
  108. data/test/vagrant/action/box/download_test.rb +9 -25
  109. data/test/vagrant/action/box/package_test.rb +2 -2
  110. data/test/vagrant/action/box/unpackage_test.rb +8 -34
  111. data/test/vagrant/action/box/verify_test.rb +10 -19
  112. data/test/vagrant/action/builder_test.rb +0 -15
  113. data/test/vagrant/action/env/set_test.rb +1 -1
  114. data/test/vagrant/action/environment_test.rb +8 -26
  115. data/test/vagrant/action/general/package_test.rb +53 -53
  116. data/test/vagrant/action/vm/boot_test.rb +5 -22
  117. data/test/vagrant/action/vm/check_box_test.rb +35 -25
  118. data/test/vagrant/action/vm/clean_machine_folder_test.rb +1 -1
  119. data/test/vagrant/action/vm/clear_forwarded_ports_test.rb +1 -1
  120. data/test/vagrant/action/vm/clear_nfs_exports_test.rb +1 -1
  121. data/test/vagrant/action/vm/clear_shared_folders_test.rb +1 -1
  122. data/test/vagrant/action/vm/customize_test.rb +2 -1
  123. data/test/vagrant/action/vm/destroy_test.rb +1 -2
  124. data/test/vagrant/action/vm/destroy_unused_network_interfaces_test.rb +1 -1
  125. data/test/vagrant/action/vm/disable_networks_test.rb +10 -1
  126. data/test/vagrant/action/vm/discard_state_test.rb +10 -1
  127. data/test/vagrant/action/vm/export_test.rb +9 -37
  128. data/test/vagrant/action/vm/forward_ports_helpers_test.rb +2 -2
  129. data/test/vagrant/action/vm/forward_ports_test.rb +19 -16
  130. data/test/vagrant/action/vm/halt_test.rb +11 -1
  131. data/test/vagrant/action/vm/import_test.rb +37 -21
  132. data/test/vagrant/action/vm/match_mac_address_test.rb +1 -1
  133. data/test/vagrant/action/vm/network_test.rb +8 -7
  134. data/test/vagrant/action/vm/nfs_helpers_test.rb +6 -3
  135. data/test/vagrant/action/vm/nfs_test.rb +20 -45
  136. data/test/vagrant/action/vm/package_test.rb +1 -1
  137. data/test/vagrant/action/vm/package_vagrantfile_test.rb +1 -1
  138. data/test/vagrant/action/vm/provision_test.rb +10 -17
  139. data/test/vagrant/action/vm/resume_test.rb +1 -1
  140. data/test/vagrant/action/vm/share_folders_test.rb +25 -106
  141. data/test/vagrant/action/vm/suspend_test.rb +1 -1
  142. data/test/vagrant/action/warden_test.rb +105 -0
  143. data/test/vagrant/action_test.rb +5 -27
  144. data/test/vagrant/box_collection_test.rb +44 -0
  145. data/test/vagrant/box_test.rb +5 -105
  146. data/test/vagrant/cli_test.rb +35 -0
  147. data/test/vagrant/command/base_test.rb +23 -0
  148. data/test/vagrant/command/group_base_test.rb +15 -0
  149. data/test/vagrant/command/helpers_test.rb +88 -0
  150. data/test/vagrant/config/base_test.rb +52 -0
  151. data/test/vagrant/config/error_recorder_test.rb +18 -0
  152. data/test/vagrant/config/ssh_test.rb +12 -0
  153. data/test/vagrant/config/vagrant_test.rb +11 -0
  154. data/test/vagrant/config/vm_test.rb +70 -0
  155. data/test/vagrant/config_test.rb +113 -206
  156. data/test/vagrant/data_store_test.rb +68 -0
  157. data/test/vagrant/downloaders/base_test.rb +1 -1
  158. data/test/vagrant/downloaders/file_test.rb +4 -3
  159. data/test/vagrant/downloaders/http_test.rb +14 -4
  160. data/test/vagrant/environment_test.rb +290 -590
  161. data/test/vagrant/errors_test.rb +42 -0
  162. data/test/vagrant/hosts/base_test.rb +1 -1
  163. data/test/vagrant/hosts/bsd_test.rb +3 -6
  164. data/test/vagrant/hosts/linux_test.rb +3 -5
  165. data/test/vagrant/plugin_test.rb +9 -0
  166. data/test/vagrant/provisioners/base_test.rb +1 -1
  167. data/test/vagrant/provisioners/chef_server_test.rb +31 -35
  168. data/test/vagrant/provisioners/chef_solo_test.rb +1 -1
  169. data/test/vagrant/provisioners/chef_test.rb +7 -7
  170. data/test/vagrant/ssh_session_test.rb +3 -10
  171. data/test/vagrant/ssh_test.rb +25 -33
  172. data/test/vagrant/systems/linux_test.rb +6 -71
  173. data/test/vagrant/ui_test.rb +29 -0
  174. data/test/vagrant/util/hash_with_indifferent_access_test.rb +39 -0
  175. data/test/vagrant/util/resource_logger_test.rb +14 -81
  176. data/test/vagrant/util/retryable_test.rb +38 -0
  177. data/test/vagrant/util/template_renderer_test.rb +4 -4
  178. data/test/vagrant/vm_test.rb +47 -26
  179. data/vagrant.gemspec +14 -12
  180. metadata +142 -108
  181. data/bin/.gitignore +0 -0
  182. data/lib/vagrant/action/action_exception.rb +0 -16
  183. data/lib/vagrant/action/env/error_halt.rb +0 -16
  184. data/lib/vagrant/action/exception_catcher.rb +0 -14
  185. data/lib/vagrant/action/vm/persist.rb +0 -22
  186. data/lib/vagrant/active_list.rb +0 -83
  187. data/lib/vagrant/command.rb +0 -27
  188. data/lib/vagrant/commands/base.rb +0 -181
  189. data/lib/vagrant/commands/box.rb +0 -16
  190. data/lib/vagrant/commands/box/add.rb +0 -30
  191. data/lib/vagrant/commands/box/list.rb +0 -30
  192. data/lib/vagrant/commands/box/remove.rb +0 -30
  193. data/lib/vagrant/commands/box/repackage.rb +0 -35
  194. data/lib/vagrant/commands/destroy.rb +0 -37
  195. data/lib/vagrant/commands/halt.rb +0 -43
  196. data/lib/vagrant/commands/init.rb +0 -36
  197. data/lib/vagrant/commands/package.rb +0 -81
  198. data/lib/vagrant/commands/provision.rb +0 -31
  199. data/lib/vagrant/commands/reload.rb +0 -36
  200. data/lib/vagrant/commands/resume.rb +0 -35
  201. data/lib/vagrant/commands/ssh.rb +0 -78
  202. data/lib/vagrant/commands/ssh_config.rb +0 -45
  203. data/lib/vagrant/commands/status.rb +0 -125
  204. data/lib/vagrant/commands/suspend.rb +0 -36
  205. data/lib/vagrant/commands/up.rb +0 -44
  206. data/lib/vagrant/exceptions/uncallable_action.rb +0 -17
  207. data/lib/vagrant/util/translator.rb +0 -35
  208. data/templates/strings.yml +0 -341
  209. data/templates/unison/crontab_entry.erb +0 -1
  210. data/templates/unison/script.erb +0 -71
  211. data/test/vagrant/action/env/error_halt_test.rb +0 -21
  212. data/test/vagrant/action/exception_catcher_test.rb +0 -30
  213. data/test/vagrant/action/vm/persist_test.rb +0 -50
  214. data/test/vagrant/active_list_test.rb +0 -173
  215. data/test/vagrant/command_test.rb +0 -53
  216. data/test/vagrant/commands/base_test.rb +0 -139
  217. data/test/vagrant/commands/box/add_test.rb +0 -34
  218. data/test/vagrant/commands/box/list_test.rb +0 -32
  219. data/test/vagrant/commands/box/remove_test.rb +0 -41
  220. data/test/vagrant/commands/box/repackage_test.rb +0 -52
  221. data/test/vagrant/commands/destroy_test.rb +0 -44
  222. data/test/vagrant/commands/halt_test.rb +0 -50
  223. data/test/vagrant/commands/init_test.rb +0 -71
  224. data/test/vagrant/commands/package_test.rb +0 -97
  225. data/test/vagrant/commands/provision_test.rb +0 -60
  226. data/test/vagrant/commands/reload_test.rb +0 -47
  227. data/test/vagrant/commands/resume_test.rb +0 -44
  228. data/test/vagrant/commands/ssh_config_test.rb +0 -77
  229. data/test/vagrant/commands/ssh_test.rb +0 -129
  230. data/test/vagrant/commands/status_test.rb +0 -40
  231. data/test/vagrant/commands/suspend_test.rb +0 -44
  232. data/test/vagrant/commands/up_test.rb +0 -49
  233. data/test/vagrant/util/translator_test.rb +0 -61
  234. data/test/vagrant/util_test.rb +0 -27
data/bin/.gitignore DELETED
File without changes
@@ -1,16 +0,0 @@
1
- module Vagrant
2
- class Action
3
- class ActionException < Exception
4
- attr_reader :key
5
- attr_reader :data
6
-
7
- def initialize(key, data = {})
8
- @key = key
9
- @data = data
10
-
11
- message = Vagrant::Util::Translator.t(key, data)
12
- super(message)
13
- end
14
- end
15
- end
16
- end
@@ -1,16 +0,0 @@
1
- module Vagrant
2
- class Action
3
- module Env
4
- # A middleware which simply halts if the environment is erroneous.
5
- class ErrorHalt
6
- def initialize(app,env)
7
- @app = app
8
- end
9
-
10
- def call(env)
11
- @app.call(env) if !env.error?
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,14 +0,0 @@
1
- module Vagrant
2
- class Action
3
- # A helper to catch any ActionExceptions raised and to
4
- # apply the error to the environment.
5
- module ExceptionCatcher
6
- def catch_action_exception(env)
7
- yield env
8
- rescue ActionException => e
9
- env.error!(e.key, e.data)
10
- false
11
- end
12
- end
13
- end
14
- end
@@ -1,22 +0,0 @@
1
- module Vagrant
2
- class Action
3
- module VM
4
- class Persist
5
- def initialize(app, env)
6
- @app = app
7
-
8
- # Error the environment if the dotfile is not valid
9
- env.error!(:dotfile_error, :env => env.env) if File.exist?(env.env.dotfile_path) &&
10
- !File.file?(env.env.dotfile_path)
11
- end
12
-
13
- def call(env)
14
- env.logger.info "Persisting the VM UUID (#{env["vm"].uuid})"
15
- env.env.update_dotfile
16
-
17
- @app.call(env)
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,83 +0,0 @@
1
- module Vagrant
2
- # This class represents the active list of vagrant virtual
3
- # machines.
4
- class ActiveList
5
- FILENAME = "active.json"
6
-
7
- @@list = nil
8
-
9
- # The environment this active list belongs to
10
- attr_accessor :env
11
-
12
- # Creates the instance of the ActiveList, with the given environment
13
- # if specified
14
- def initialize(env=nil)
15
- @env = env
16
- end
17
-
18
- # Parses and returns the list of UUIDs from the active VM
19
- # JSON file. This will cache the result, which can be reloaded
20
- # by setting the `reload` parameter to true.
21
- #
22
- # @return [Array<String>]
23
- def list(reload=false)
24
- return @list unless @list.nil? || reload
25
-
26
- @list ||= {}
27
- return @list unless File.file?(path)
28
- File.open(path, "r") do |f|
29
- begin
30
- @list = JSON.parse(f.read)
31
- rescue Exception
32
- @list = {}
33
- end
34
-
35
- # This forces earlier versions of Vagrant to use the new hash
36
- # format. Clearing out the old data isn't a big deal since it
37
- # was never used.
38
- @list = {} unless @list.is_a?(Hash)
39
- end
40
-
41
- @list
42
- end
43
-
44
- # Returns an array of UUIDs filtered so each is verified to exist.
45
- def filter_list
46
- list.each do |uuid, data|
47
- list.delete(uuid) unless Vagrant::VM.find(uuid, env)
48
- end
49
-
50
- list
51
- end
52
-
53
- # Adds a virtual environment to the list of active virtual machines
54
- def add(vm)
55
- list[vm.uuid] = {
56
- :path => env.root_path,
57
- :created_at => Time.now.to_i
58
- }
59
-
60
- save
61
- end
62
-
63
- # Remove a virtual environment from the list of active virtual machines
64
- def remove(vm)
65
- vm = vm.uuid if vm.is_a?(Vagrant::VM)
66
- list.delete(vm)
67
- save
68
- end
69
-
70
- # Persists the list down to the JSON file.
71
- def save
72
- File.open(path, "w+") do |f|
73
- f.write(filter_list.to_json)
74
- end
75
- end
76
-
77
- # Returns the path to the JSON file which holds the UUIDs of the
78
- # active virtual machines managed by Vagrant.
79
- def path
80
- File.join(env.home_path, FILENAME)
81
- end
82
- end
83
- end
@@ -1,27 +0,0 @@
1
- module Vagrant
2
- # This class handles commands from the command line program `vagrant`
3
- # and redirects them to the proper sub-command, setting up the environment
4
- # and executing.
5
- class Command
6
- attr_reader :env
7
-
8
- class << self
9
- # Executes a given subcommand within the current environment (from the
10
- # current working directory).
11
- def execute(*args)
12
- env = Environment.load!
13
- env.commands.subcommand(*args)
14
- end
15
- end
16
-
17
- def initialize(env)
18
- @env = env
19
- end
20
-
21
- # Execute a subcommand with the given name and args. This method properly
22
- # finds the subcommand, instantiates it, and executes.
23
- def subcommand(*args)
24
- Commands::Base.dispatch(env, *args)
25
- end
26
- end
27
- end
@@ -1,181 +0,0 @@
1
- require 'optparse'
2
-
3
- module Vagrant
4
- class Commands
5
- # This is the base command class which all sub-commands must
6
- # inherit from. Subclasses of bases are expected to implement two
7
- # methods: {#execute} and {#options_spec} (optional). The former
8
- # defines the actual behavior of the command while the latter is a spec
9
- # outlining the options that the command may take.
10
- class Base
11
- include Util
12
-
13
- attr_reader :env
14
-
15
- class << self
16
- # Contains the list of registered subcommands. The registered commands are
17
- # stored in a hash table and are therefore unordered.
18
- #
19
- # @return [Hash]
20
- def subcommands
21
- @subcommands ||= {}
22
- end
23
-
24
- # Registers a command with `vagrant`. This method allows 3rd parties to
25
- # dynamically add new commands to the `vagrant` command, allowing plugins
26
- # to act as 1st class citizens within vagrant.
27
- #
28
- # @param [String] key The subcommand which will invoke the registered command.
29
- # @param [Class] klass. The subcommand class (a subclass of {Base})
30
- def subcommand(key, klass)
31
- subcommands[key] = klass
32
- end
33
-
34
- # Dispatches a subcommand to the proper registered command. Otherwise, it
35
- # prints a help message.
36
- def dispatch(env, *args)
37
- klass = subcommands[args[0]] unless args.empty?
38
- if klass.nil?
39
- # Run _this_ command!
40
- command = self.new(env)
41
- command.execute(args)
42
- return
43
- end
44
-
45
- # Shift off the front arg, since we just consumed it in finding the
46
- # subcommand.
47
- args.shift
48
-
49
- # Dispatch to the next class
50
- klass.dispatch(env, *args)
51
- end
52
-
53
- # Sets or reads the description, depending on if the value is set in the
54
- # parameter.
55
- def description(value=nil)
56
- @description ||= ''
57
-
58
- return @description if value.nil?
59
- @description = value
60
- end
61
- end
62
-
63
- def initialize(env)
64
- @env = env
65
- end
66
-
67
- # This method should be overriden by subclasses. This is the method
68
- # which is called by {Vagrant::Command} when a command is being
69
- # executed. The `args` parameter is an array of parameters to the
70
- # command (similar to ARGV)
71
- def execute(args)
72
- parse_options(args)
73
-
74
- if options[:version]
75
- puts_version
76
- else
77
- # Just print out the help, since this top-level command does nothing
78
- # on its own
79
- show_help
80
- end
81
- end
82
-
83
- # This method is called by the base class to get the `optparse` configuration
84
- # for the command.
85
- def options_spec(opts)
86
- opts.banner = "Usage: vagrant SUBCOMMAND"
87
-
88
- opts.on("--version", "Output running Vagrant version.") do |v|
89
- options[:version] = v
90
- end
91
- end
92
-
93
- #-------------------------------------------------------------------
94
- # Methods below are not meant to be overriden/implemented by subclasses
95
- #-------------------------------------------------------------------
96
-
97
- # Parses the options for a given command and if a name was
98
- # given, it calls the single method, otherwise it calls the all
99
- # method. This helper is an abstraction which allows commands to
100
- # easily be used in both regular and multi-VM environments.
101
- def all_or_single(args, method_prefix)
102
- args = parse_options(args)
103
-
104
- single_method = "#{method_prefix}_single".to_sym
105
- if args[0]
106
- send(single_method, args[0])
107
- else
108
- env.vms.keys.each do |name|
109
- send(single_method, name)
110
- end
111
- end
112
- end
113
-
114
- # Shows the version
115
- def puts_version
116
- puts VERSION
117
- end
118
-
119
- # Returns the `OptionParser` instance to be used with this subcommand,
120
- # based on the specs defined in {#options_spec}.
121
- def option_parser(reload=false)
122
- @option_parser = nil if reload
123
- @option_parser ||= OptionParser.new do |opts|
124
- # The --help flag is available on all children commands, and will
125
- # immediately show help.
126
- opts.on("--help", "Show help for the current subcommand.") do
127
- show_help
128
- end
129
-
130
- options_spec(opts)
131
- end
132
- end
133
-
134
- # The options for the given command. This will just be an empty hash
135
- # until {#parse_options} is called.
136
- def options
137
- @options ||= {}
138
- end
139
-
140
- # Parse options out of the command-line. This method uses `optparse`
141
- # to parse command line options.
142
- def parse_options(args)
143
- option_parser.parse!(args)
144
- rescue OptionParser::InvalidOption
145
- show_help
146
- end
147
-
148
- # Gets the description of the command. This is similar grabbed from the
149
- # class level.
150
- def description
151
- self.class.description
152
- end
153
-
154
- # Prints the help for the given command. Prior to calling this method,
155
- # {#parse_options} must be called or a nilerror will be raised. This
156
- # is by design.
157
- def show_help
158
- if !description.empty?
159
- puts "Description: #{description}"
160
- end
161
-
162
- puts option_parser.help
163
-
164
- my_klass = self.class
165
- if !my_klass.subcommands.empty?
166
- puts "\nSupported subcommands:"
167
- my_klass.subcommands.keys.sort.each do |key|
168
- klass = my_klass.subcommands[key]
169
- next if klass.description.empty?
170
-
171
- puts "#{' ' * 8}#{key.ljust(20)}#{klass.description}"
172
- end
173
-
174
- puts "\nFor help on a specific subcommand, run `vagrant SUBCOMMAND --help`"
175
- end
176
-
177
- exit
178
- end
179
- end
180
- end
181
- end
@@ -1,16 +0,0 @@
1
- module Vagrant
2
- class Commands
3
- # Manages the `vagrant box` command, allowing the user to add
4
- # and remove boxes. This single command, given an array, determines
5
- # which action to take and calls the respective action method
6
- # (see {box_add} and {box_remove})
7
- class BoxCommand < Base
8
- Base.subcommand "box", self
9
- description "Box commands"
10
-
11
- def options_spec(opts)
12
- opts.banner = "Usage: vagrant box SUBCOMMAND"
13
- end
14
- end
15
- end
16
- end
@@ -1,30 +0,0 @@
1
- module Vagrant
2
- class Commands
3
- # Adds a box to the local filesystem, given a URI.
4
- module Box
5
- class Add < BoxCommand
6
- BoxCommand.subcommand "add", self
7
- description "Add a box"
8
-
9
- def execute(args)
10
- if args.length != 2
11
- show_help
12
- return
13
- end
14
-
15
- box = Vagrant::Box.find(env, args[0])
16
- if !box.nil?
17
- error_and_exit(:box_already_exists)
18
- return # for tests
19
- end
20
-
21
- Vagrant::Box.add(env, args[0], args[1])
22
- end
23
-
24
- def options_spec(opts)
25
- opts.banner = "Usage: vagrant box add NAME URI"
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,30 +0,0 @@
1
- module Vagrant
2
- class Commands
3
- # Lists all added boxes
4
- module Box
5
- class List < BoxCommand
6
- BoxCommand.subcommand "list", self
7
- description "List all installed boxes"
8
-
9
- def execute(args=[])
10
- boxes = Vagrant::Box.all(env).sort
11
-
12
- wrap_output do
13
- if !boxes.empty?
14
- puts "Installed Vagrant Boxes:\n\n"
15
- boxes.each do |box|
16
- puts box
17
- end
18
- else
19
- puts "No Vagrant Boxes Added!"
20
- end
21
- end
22
- end
23
-
24
- def options_spec(opts)
25
- opts.banner = "Usage: vagrant box list"
26
- end
27
- end
28
- end
29
- end
30
- end