vagrant-yaml 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,33 +9,65 @@ module VagrantYaml
9
9
  def execute
10
10
  options = {}
11
11
 
12
+ # Boolean whether we should actually go through with the update
13
+ # or not. This is true only if the "--force" flag is set or if the
14
+ # user confirms it.
15
+ do_update = false
16
+
12
17
  opts = OptionParser.new do |opts|
13
- opts.banner = "Usage: vagrant yaml update [box-name] [box-url]"
18
+ opts.banner = "Usage: vagrant yaml update"
19
+
20
+ opts.on("-f", "--force", "Update without confirmation.") do |f|
21
+ options[:force] = f
22
+ end
14
23
  end
15
24
 
16
25
  # Parse the options
17
26
  argv = parse_options(opts)
18
27
  return if !argv
19
28
 
29
+ if options[:force]
30
+ do_update = true
31
+ else
32
+ choice = nil
33
+ begin
34
+ choice = @env.ui.ask(I18n.t("vagrant.plugins.yaml.commands.update.confirmation"))
35
+
36
+ rescue Errors::UIExpectsTTY
37
+ # We raise a more specific error but one which basically
38
+ # means the same thing.
39
+ raise Errors::UpdateRequiresForce
40
+ end
41
+ do_update = choice.upcase == "Y"
42
+ end
43
+
44
+ if do_update
45
+ @logger.info("Updating project with latest Vagrantfile from vagrant-yaml.")
46
+ update
47
+ else
48
+ @logger.info("Not updating project since confirmation was declined.")
49
+ @env.ui.success(I18n.t("vagrant.plugins.yaml.commands.update.will_not_update"),
50
+ :prefix => false)
51
+ end
52
+ end
53
+
54
+ def update
20
55
  save_path = @env.cwd.join("Vagrantfile")
21
- # raise Errors::VagrantfileExistsError if save_path.exist?
22
56
 
23
- template_path = ::Vagrant.source_root.join("templates/commands/init/Vagrantfile")
24
- contents = Vagrant::Util::TemplateRenderer.render(template_path,
25
- :box_name => argv[0] || "base",
26
- :box_url => argv[1])
57
+ template_path = ::VagrantYaml.source_root.join("templates/Vagrantfile")
58
+ contents = Vagrant::Util::TemplateRenderer.render(template_path)
27
59
 
28
60
  # Write out the contents
29
61
  save_path.open("w+") do |f|
30
62
  f.write(contents)
31
63
  end
32
64
 
33
- @env.ui.info(I18n.t("vagrant.plugins.yaml.commands.init.success"),
65
+ @env.ui.info(I18n.t("vagrant.plugins.yaml.commands.update.success"),
34
66
  :prefix => false)
35
67
 
36
68
  # Success, exit status 0
37
69
  0
38
- end
70
+ end
39
71
  end
40
72
  end
41
73
  end
@@ -1,3 +1,3 @@
1
1
  module VagrantYaml
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -11,6 +11,14 @@ en:
11
11
  the Yaml files it finds in /vms-enabled. You are now ready to `vagrant up` your
12
12
  first virtual environment! Please read the comments in the default Yaml VM
13
13
  config file to see how it works.
14
+ update:
15
+ success: |-
16
+ Vagrantfile updated using the latesy one from vagrant-yaml.
17
+ confirmation: |-
18
+ This operation will overwrite the Vagrantfile in this project with the one in the
19
+ vagrant-yaml gem. Do you want to proceed?
20
+ will_not_update: |-
21
+ User aborted. Vagrantfile was not updated.
14
22
 
15
23
  errors:
16
24
  vagrantfile_exists: |-
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-yaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: