vagrant-wizard 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2037e39c36f1bcac7076d8382b341d596458e39fb2706e8f7fd27e63dad674c1
4
- data.tar.gz: e954b4f407d95115de932b82ca7dca33b676202aab97ddabc3d66d40ef58a18e
3
+ metadata.gz: 8c183815a69a812fc4d310b0e52541bfe78ac6941a5e54602dafcb8c14377b41
4
+ data.tar.gz: c45e43ba46124236729f44cd5bbebd336a054ad1f574f73aff40758779aafae9
5
5
  SHA512:
6
- metadata.gz: 562bf75d191b95ce0f5d23063d234f5972d53ffa214dc08e8884833b9ec7497847fa9d5c4e622980c8b6ded0a5f98147f635433085278e13c6c6800901665dfb
7
- data.tar.gz: ef844d0970ea3f503b3540a7bde147bf8398c48e9b09002607b8f49d45815eda092c456988bb0630416f5aa23089961051a23fceb7cdea16f106abbe97ef484a
6
+ metadata.gz: 97ef469ce8de5218e80286a5f9d4f6f4db2cc60a155549fc50cbb8739c274fee16c109060b1dee25cf94be83078624cb0cc115e3c9cb18b9c9f5216c51c92169
7
+ data.tar.gz: d4799435b5f6a1b388754ba9ffed8ad1e1f1bb65b27e108d98e1cd4e407796405131e47b10d5bcf31bac6f1ad46c79ab79d793059e055e68ffc8f571da75c156
data/Gemfile.lock CHANGED
@@ -28,7 +28,8 @@ GIT
28
28
  PATH
29
29
  remote: .
30
30
  specs:
31
- vagrant-wizard (0.1.0)
31
+ vagrant-wizard (0.2.15)
32
+ tty-prompt (~> 0.19.0)
32
33
 
33
34
  GEM
34
35
  remote: https://rubygems.org/
@@ -78,7 +79,6 @@ GEM
78
79
  pastel (0.7.3)
79
80
  equatable (~> 0.6)
80
81
  tty-color (~> 0.5)
81
- rake (10.5.0)
82
82
  rb-fsevent (0.10.3)
83
83
  rb-inotify (0.10.0)
84
84
  ffi (~> 1.0)
@@ -132,9 +132,6 @@ PLATFORMS
132
132
  x64-mingw32
133
133
 
134
134
  DEPENDENCIES
135
- bundler (~> 1.17)
136
- rake (~> 10)
137
- tty-prompt
138
135
  vagrant!
139
136
  vagrant-wizard!
140
137
 
data/README.md CHANGED
@@ -4,14 +4,14 @@ Vagrant plugin to easily generate configuration files.
4
4
  ## Overview
5
5
  Vagrant Wizard allows users to generate YAML configuration files for their
6
6
  Vagrant environments using a predefined set of prompts described in a
7
- **vagrant-wizard.yml** file.
7
+ **config.wizard.yml** file.
8
8
 
9
9
  ## Usage
10
- By default, prompts are defined in **vagrant-wizard.yml** and determine which
10
+ By default, prompts are defined in **config.wizard.yml** and determine which
11
11
  information is requested from the user. The path to this file can be changed
12
12
  in your vagrantfile.
13
13
 
14
- An example **vagrant-wizard.yml** for a MEAN localdev environment might be:
14
+ An example **config.wizard.yml** for a MEAN localdev environment might be:
15
15
 
16
16
  ---
17
17
  prompts:
@@ -50,10 +50,10 @@ If the user passed the ``--advanced`` flag they will also be prompted
50
50
  to select the amount of memory to allow the virtual machine to use.
51
51
 
52
52
  Upon completing the prompts, a new YAML file is created containing the values
53
- entered by the user. By default, this file is named **vagrant-config.yml**.
53
+ entered by the user. By default, this file is named **config.yml**.
54
54
 
55
55
  ### Prompts
56
- The **vagrant-wizard.yml** file has only a ``prompts`` key which contains
56
+ The **config.wizard.yml** file has only a ``prompts`` key which contains
57
57
  a list of prompt definitions. Each prompt can accept the following fields:
58
58
 
59
59
  |Field |Description |
@@ -101,21 +101,20 @@ correspond to one of the ``value``s specified in the ``choices`` field.
101
101
  ### Default Configuration
102
102
  Occasionally there will be a need to store values in a configuration file that
103
103
  do not actually require user input. These configurations can be specified in
104
- **vagrant-wizard.default.yml**, and will automatically be passed to any
104
+ **config.defaults.yml**, and will automatically be passed to any
105
105
  configuration file that gets generated using Vagrant Wizard.
106
106
 
107
- If the configuration provided by **vagrant-wizard.default.yml** conflicts
108
- with the configuration specified by the user, the configuration specified
109
- by the user will overwrite the configuration specified in
110
- **vagrant-wizard.default.yml**.
107
+ If the configuration provided by **config.defaults.yml** conflicts with the
108
+ configuration specified by the user, the configuration specified by the user
109
+ will overwrite the configuration specified in **config.defaults.yml**.
111
110
 
112
111
  ### Presets
113
112
  Preset configurations can be created and stored in the **wizard-presets**
114
113
  directory. A preset is a YAML file whose filename ends in *.preset.yml* and
115
114
  which contains a list of key/value pairs which can be automatically used to
116
- answer prompts specified in **vagrant-wizard.yml**.
115
+ answer prompts specified in **config.wizard.yml**.
117
116
 
118
- For example, a preset for the example **vagrant-wizard.yml** file above might
117
+ For example, a preset for the example **config.wizard.yml** file above might
119
118
  be named ``node-10.preset.yml`` and look like this:
120
119
 
121
120
  meta:
@@ -136,11 +135,36 @@ vagrantfile.
136
135
 
137
136
  The following configuration options are available:
138
137
 
139
- |Config |Description |Default |
140
- |--------------------|------------------------------------------------------------------------|--------------------------------|
141
- |``config_path`` |Path to Vagrant Wizard config file |``./vagrant-wizard.yml`` |
142
- |``defaults_path`` |Path to default configuration file |``./vagrant-wizard.default.yml``|
143
- |``output_path`` |Path to output configuration file |``./vagrant-config.yml`` |
144
- |``presets_dir_path``|Path to presets directory |``./wizard-presets`` |
145
- |``prompt_overwrite``|Whether or not to prompt for confirmation before overwriting config file|``true`` |
146
- |``prompt_presets`` |Whether or not to prompt for preset selection |``true`` |
138
+ |Config |Description |Default |
139
+ |--------------------|------------------------------------------------------------------------|-------------------------|
140
+ |``wizard_path`` |Path to Vagrant Wizard config file |``./config.wizard.yml`` |
141
+ |``defaults_path`` |Path to configuration defaults file |``./config.defaults.yml``|
142
+ |``config_path`` |Path to output configuration file |``./config.yml`` |
143
+ |``presets_dir_path``|Path to presets directory |``./wizard-presets`` |
144
+ |``prompt_overwrite``|Whether or not to prompt for confirmation before overwriting config file|``true`` |
145
+ |``prompt_presets`` |Whether or not to prompt for preset selection |``true`` |
146
+
147
+ You may find yourself in an interesting predicament when trying to run
148
+ ``vagrant wizard`` for the first time. The ``wizard`` command requires
149
+ configuration information from your Vagrantfile to function, but your
150
+ Vagrantfile may not function without a configuration file present.
151
+
152
+ In these cases, you can use Vagrant Wizard's ``API`` object in your Vagrantfile
153
+ to force the wizard to appear if a configuration file does not already exist:
154
+
155
+ # Top of vagrantfile
156
+ settings = nil
157
+ if Vagrant.has_plugin?('vagrant-wizard')
158
+ require 'vagrant-wizard'
159
+ settings = (VagrantWizard::API.new).require_config
160
+ end
161
+ # Optionally attempt to load ./config.yml manually here if 'vagrant-wizard' is not installed.
162
+ # ...
163
+ if settings == nil
164
+ puts "No configuration file found at ./config.yml"
165
+ exit
166
+ end
167
+ # Proceed with regular Vagrant configuration
168
+ Vagrant.require_version ">= 2.1.2"
169
+ Vagrant.configure("2") do |config|
170
+ ...
@@ -1,8 +1,61 @@
1
+ require 'tty-prompt'
2
+
1
3
  module VagrantWizard
2
- require 'vagrant-wizard/version'
3
- require 'vagrant-wizard/plugin'
4
- require 'vagrant-wizard/config'
5
- require 'vagrant-wizard/loader'
6
- require 'vagrant-wizard/prompt-parser'
7
- require 'vagrant-wizard/inputs/input'
4
+ require_relative 'vagrant-wizard/version'
5
+ require_relative 'vagrant-wizard/plugin'
6
+ require_relative 'vagrant-wizard/config'
7
+ require_relative 'vagrant-wizard/prompt-display'
8
+
9
+ class API
10
+ attr_accessor :config_path
11
+ attr_accessor :defaults_path
12
+ attr_accessor :wizard_path
13
+ attr_accessor :presets_dir_path
14
+ attr_accessor :prompt_presets
15
+ attr_accessor :prompt_overwrite
16
+ attr_accessor :advanced
17
+
18
+ def initialize
19
+ @config_path = './config.yml'
20
+ @defaults_path = './config.defaults.yml'
21
+ @wizard_path = './config.wizard.yml'
22
+ @presets_dir_path = './wizard-presets'
23
+ @prompt_presets = true
24
+ @prompt_overwrite = true
25
+ @advanced = false
26
+ end
27
+
28
+ def require_config
29
+ if File.exist?(@config_path)
30
+ return YAML.load_file(@config_path)
31
+ end
32
+
33
+ puts "You do not have a configuration file set up for this Vagrant environment."
34
+
35
+ confirmationString = 'Would you like to create a configuration file using Vagrant Wizard?'
36
+ confirmation = TTY::Prompt.new
37
+
38
+ if (confirmation.yes?(confirmationString))
39
+ promptDisplay = PromptDisplay.new
40
+
41
+ promptDisplay.wizard_path = @wizard_path
42
+ promptDisplay.defaults_path = @defaults_path
43
+ promptDisplay.presets_dir_path = @presets_dir_path
44
+ promptDisplay.config_path = @config_path
45
+ promptDisplay.prompt_presets = @prompt_presets
46
+ promptDisplay.prompt_overwrite = @prompt_overwrite
47
+ promptDisplay.advanced = @advanced
48
+
49
+ promptDisplay.display
50
+
51
+ # User has been prompted, check again for config file.
52
+ if File.exist?(@config_path)
53
+ return YAML.load_file(@config_path)
54
+ end
55
+ end
56
+
57
+ return nil
58
+ end
59
+
60
+ end
8
61
  end
@@ -1,8 +1,11 @@
1
1
  require 'vagrant'
2
2
  require 'tty-prompt'
3
3
 
4
- require 'vagrant-wizard';
5
- require 'yaml';
4
+ require 'vagrant-wizard'
5
+ require 'vagrant-wizard/loader'
6
+ require 'vagrant-wizard/prompt-parser'
7
+
8
+ require 'yaml'
6
9
 
7
10
  module VagrantWizard
8
11
  module Commands
@@ -22,110 +25,17 @@ module VagrantWizard
22
25
  end
23
26
 
24
27
  def execute
25
- loader = VagrantWizard::Loader.new(@config.config_path)
26
- if (loader.data == nil)
27
- puts "Wizard config file cannot be found!"
28
- return
29
- end
30
-
31
- defaultData = Hash.new
32
- if (File.exist?(@config.defaults_path))
33
- defaultData = YAML.load(File.read(@config.defaults_path))
34
- end
35
-
36
- presets = Hash.new
37
- presets['(None)'] = {}
38
- preset = nil;
39
- if (@config.prompt_presets == true && Dir.exist?(@config.presets_dir_path))
40
- presetPrompt = TTY::Prompt.new
41
- showPresets = presetPrompt.yes?("Select from a preset configuration?")
42
- if (showPresets == true)
43
- presetFilesYml = Dir["#{@config.presets_dir_path}/*.preset.yml"]
44
- presetFilesYaml = Dir["#{@config.presets_dir_path}/*.preset.yaml"]
45
- presetFiles = presetFilesYml + presetFilesYaml
46
-
47
- presetFiles.each do |presetFile|
48
- presetData = YAML.load(File.read(presetFile))
49
- # Skip preset definitions that do not have a meta section
50
- if (presetData == false || !presetData.key?('meta'))
51
- next
52
- end
53
- presets[presetData['meta']['name']] = presetData['config']
54
- end
55
-
56
- presetChoice = TTY::Prompt.new
57
- preset = presetChoice.select('Select a preset', presets)
58
- end
59
- end
28
+ promptDisplay = PromptDisplay.new
60
29
 
61
- outputData = Hash.new
30
+ promptDisplay.wizard_path = @config.wizard_path
31
+ promptDisplay.defaults_path = @config.defaults_path
32
+ promptDisplay.presets_dir_path = @config.presets_dir_path
33
+ promptDisplay.config_path = @config.config_path
34
+ promptDisplay.prompt_presets = @config.prompt_presets
35
+ promptDisplay.prompt_overwrite = @config.prompt_overwrite
36
+ promptDisplay.advanced = @advanced
62
37
 
63
- loader.data['prompts'].each do |prompt|
64
- presetData = nil
65
- if (preset != nil)
66
- preset.each do |preset|
67
- if (!preset.key?('key') || !preset.key?('value'))
68
- next
69
- end
70
- if (preset['key'] == prompt['key'])
71
- presetData = preset['value']
72
- break
73
- end
74
- end
75
- end
76
-
77
- output = nil
78
- if (presetData != nil)
79
- key = prompt['key']
80
- output = presetData
81
- else
82
- parser = PromptParser.new(prompt)
83
- parser.advanced = @advanced
84
- parser.prompt()
85
- key = parser.key
86
- output = parser.output
87
- end
88
-
89
- keyParts = key.split('|');
90
- keyName = keyParts[-1];
91
- currentHash = outputData
92
- keyParts[0..-2].each do |keyPart|
93
- if !currentHash.key?(keyPart)
94
- currentHash[keyPart] = Hash.new
95
- end
96
- currentHash = currentHash[keyPart]
97
- end
98
- currentHash[keyName] = output
99
- end
100
-
101
- def merge_recursively(a, b)
102
- a.merge!(b) do |key, a_item, b_item|
103
- if a_item.is_a?(Hash)
104
- merge_recursively(a_item, b_item)
105
- else
106
- b_item
107
- end
108
- end
109
- end
110
-
111
- outputData = merge_recursively(defaultData, outputData)
112
-
113
- outputYaml = outputData.to_yaml
114
- canOverwrite = true
115
- if File.exist?(@config.output_path)
116
- if @config.prompt_overwrite == true
117
- confirmation = TTY::Prompt.new
118
- canOverwrite = confirmation.yes?("Overwrite your existing configuration?")
119
- else
120
- canOverwrite = true
121
- end
122
- end
123
- if canOverwrite == true
124
- File.open(@config.output_path, "w") do |file|
125
- file.write outputYaml
126
- end
127
- end
128
- 0
38
+ promptDisplay.display
129
39
  end
130
40
  end
131
41
  end
@@ -2,29 +2,29 @@ require 'vagrant'
2
2
 
3
3
  module VagrantWizard
4
4
  class Config < Vagrant.plugin('2', :config)
5
- attr_accessor :config_path
5
+ attr_accessor :wizard_path
6
6
  attr_accessor :defaults_path
7
- attr_accessor :output_path
7
+ attr_accessor :config_path
8
8
  attr_accessor :prompt_presets
9
9
  attr_accessor :presets_dir_path
10
10
  attr_accessor :prompt_overwrite
11
11
 
12
12
  def initialize
13
- @config_path = UNSET_VALUE
13
+ @wizard_path = UNSET_VALUE
14
14
  @defaults_path = UNSET_VALUE
15
- @output_path = UNSET_VALUE
15
+ @config_path = UNSET_VALUE
16
16
  @prompt_presets = UNSET_VALUE
17
17
  @presets_dir_path = UNSET_VALUE
18
- @propmt_overwrite = UNSET_VALUE
18
+ @prompt_overwrite = UNSET_VALUE
19
19
  end
20
20
 
21
21
  def finalize!
22
- @config_path = './vagrant-wizard.yml' if @config_path == UNSET_VALUE
23
- @defaults_path = './vagrant-wizard.default.yml' if @defaults_path == UNSET_VALUE
24
- @output_path = './vagrant-config.yml' if @output_path == UNSET_VALUE
25
- @prompt_presets = true if @prompt_presets == UNSET_VALUE
26
- @presets_dir_path = './wizard-presets' if @presets_dir_path == UNSET_VALUE
27
- @prompt_overwrite = true if @prompt_overwrite == UNSET_VALUE
22
+ @wizard_path = './config.wizard.yml' if @wizard_path == UNSET_VALUE
23
+ @defaults_path = './config.defaults.yml' if @defaults_path == UNSET_VALUE
24
+ @config_path = './config.yml' if @config_path == UNSET_VALUE
25
+ @prompt_presets = true if @prompt_presets == UNSET_VALUE
26
+ @presets_dir_path = './wizard-presets' if @presets_dir_path == UNSET_VALUE
27
+ @prompt_overwrite = true if @prompt_overwrite == UNSET_VALUE
28
28
  end
29
29
  end
30
30
  end
@@ -1,3 +1,5 @@
1
+ require_relative "input"
2
+
1
3
  require "tty-prompt"
2
4
 
3
5
  class VagrantWizard::Confirm < VagrantWizard::Input
@@ -1,3 +1,5 @@
1
+ require_relative "input"
2
+
1
3
  require "tty-prompt"
2
4
 
3
5
  class VagrantWizard::Password < VagrantWizard::Input
@@ -1,3 +1,5 @@
1
+ require_relative "input"
2
+
1
3
  require "tty-prompt"
2
4
 
3
5
  class VagrantWizard::Prompt < VagrantWizard::Input
@@ -1,3 +1,5 @@
1
+ require_relative "input"
2
+
1
3
  require "tty-prompt"
2
4
 
3
5
  class VagrantWizard::Select < VagrantWizard::Input
@@ -1,6 +1,5 @@
1
1
  require 'vagrant'
2
2
  require 'vagrant-wizard'
3
- require 'vagrant-wizard/version'
4
3
 
5
4
  require 'yaml'
6
5
 
@@ -0,0 +1,225 @@
1
+ require 'tty-prompt'
2
+ require 'yaml'
3
+
4
+ require 'vagrant-wizard'
5
+ require 'vagrant-wizard/prompt-parser'
6
+
7
+ module VagrantWizard
8
+
9
+ class PromptDisplay
10
+ attr_accessor :defaults_path
11
+ attr_accessor :wizard_path
12
+ attr_accessor :config_path
13
+ attr_accessor :prompt_presets
14
+ attr_accessor :presets_dir_path
15
+ attr_accessor :prompt_overwrite
16
+ attr_accessor :advanced
17
+
18
+ def initialize
19
+ @defaults_path = nil
20
+ @wizard_path = nil
21
+ @config_path = nil
22
+ @prompt_presets = true
23
+ @presets_dir_path = nil
24
+ @prompt_overwrite = true
25
+ @advanced = false
26
+ end
27
+
28
+ def display
29
+ config = load_config_file
30
+ if config == nil
31
+ puts "Error: Wizard configuration file does not exist at `#{@wizard_path}`"
32
+ return
33
+ end
34
+ preset = nil
35
+ if @prompt_presets
36
+ preset = show_presets_prompt
37
+ end
38
+ results = Hash.new
39
+ config['prompts'].each do |prompt|
40
+ result = display_prompt(prompt, preset)
41
+ results = insert_prompt_output(result, results)
42
+ end
43
+ defaults = load_default_config
44
+ if defaults != nil
45
+ results = merge_recursively(defaults, results)
46
+ end
47
+
48
+ output_results(results)
49
+ end
50
+
51
+ private
52
+
53
+ # Loads the wizard configuration file and returns a hash of its data.
54
+ #
55
+ # If file does not exist, nil is returned.
56
+ def load_config_file
57
+ if File.exist?(@wizard_path)
58
+ return YAML.load_file(@wizard_path)
59
+ end
60
+ return nil
61
+ end
62
+
63
+ # Loads the default configuration file and returns a hash of its data.
64
+ #
65
+ # If file does not exist, nil is returned.
66
+ def load_default_config
67
+ if (File.exist?(@defaults_path))
68
+ return YAML.load_file(@defaults_path)
69
+ end
70
+ return nil
71
+ end
72
+
73
+ # Displays the presets prompt
74
+ #
75
+ # If the specified presets path does not exist, no prompt is shown and nil
76
+ # is returned.
77
+ #
78
+ # If the user declines to select a preset, nil is returned.
79
+ def show_presets_prompt
80
+ # Short-circuit if presets path is not specified or does not exist
81
+ if @presets_dir_path == nil || !Dir.exist?(@presets_dir_path)
82
+ return nil
83
+ end
84
+
85
+ # Ask user if they want to select a preset
86
+ confirmationString = "Select a configuration preset?"
87
+ confirmationPrompt = TTY::Prompt.new
88
+
89
+ if confirmationPrompt.yes?(confirmationString)
90
+ presets = get_presets(true)
91
+ presetSelectionString = "Select a preset"
92
+ presetSelectionPrompt = TTY::Prompt.new
93
+ return presetSelectionPrompt.select(presetSelectionString, presets)
94
+ end
95
+
96
+ return nil
97
+ end
98
+
99
+ # Gets a hash of available presets.
100
+ #
101
+ # Optionally includes a '(None)' option.
102
+ def get_presets(includeNone = false)
103
+ presets = Hash.new
104
+
105
+ # Add '(None)' entry if requested.
106
+ if includeNone == true
107
+ presets['(None)'] = {}
108
+ end
109
+
110
+ # Short-circuit if presets path is not specified or does not exist.
111
+ if @presets_dir_path == nil || !Dir.exist?(@presets_dir_path)
112
+ return presets
113
+ end
114
+
115
+ # Get all *.preset.yml and *.preset.yaml files in presets dir
116
+ presetFilesYml = Dir["#{@presets_dir_path}/*.preset.yml"]
117
+ presetFilesYaml = Dir["#{@presets_dir_path}/*.preset.yaml"]
118
+ presetFiles = presetFilesYml + presetFilesYaml
119
+
120
+ # Iterate each preset file
121
+ presetFiles.each do |presetFile|
122
+ presetData = YAML.load_file(presetFile)
123
+ # Skip this preset if YAML load failed or if data is missing.
124
+ if (presetData == false || !presetData.key?('meta'))
125
+ next
126
+ end
127
+ if (!presetData['meta'].key?('name') || !presetData.key?('config'))
128
+ next
129
+ end
130
+ # Add this preset
131
+ presets[presetData['meta']['name']] = presetData['config']
132
+ end
133
+
134
+ return presets
135
+ end
136
+
137
+ # Displays a single prompt and returns the result.
138
+ def display_prompt(prompt, preset = nil)
139
+ presetData = nil
140
+ if (preset != nil)
141
+ # Fetch preset data if it exists.
142
+ preset.each do |preset|
143
+ if (preset_has_key(preset, prompt['key']))
144
+ presetData = preset['value']
145
+ break
146
+ end
147
+ end
148
+ end
149
+
150
+ # Return preset data if it exists.
151
+ if (presetData != nil)
152
+ return { 'key' => prompt['key'], 'value' => presetData }
153
+ end
154
+
155
+ promptParser = PromptParser.new(prompt)
156
+ promptParser.advanced = @advanced
157
+ promptParser.prompt()
158
+
159
+ return { 'key' => promptParser.key, 'value' => promptParser.output }
160
+ end
161
+
162
+ # Determines if the given preset has the given key
163
+ def preset_has_key(preset, key)
164
+ if (!preset.key?('key'))
165
+ return false
166
+ end
167
+ return preset['key'] == key
168
+ end
169
+
170
+ # Inserts prompt result into a hash of output and returns the result.
171
+ def insert_prompt_output(new_output, existing_output)
172
+ key = new_output['key']
173
+ keyParts = key.split('|')
174
+ keyName = keyParts[-1]
175
+ currentHash = existing_output
176
+
177
+ keyParts[0..-2].each do |keyPart|
178
+ # Create new key if it does not exist.
179
+ if !currentHash.key?(keyPart)
180
+ currentHash[keyPart] = Hash.new
181
+ end
182
+ # Reset current hash
183
+ currentHash = currentHash[keyPart]
184
+ end
185
+ currentHash[keyName] = new_output['value']
186
+
187
+ return existing_output
188
+ end
189
+
190
+ # Merges two hashes recursively, with B taking precedence over A.
191
+ def merge_recursively(a, b)
192
+ a.merge!(b) do |key, a_item, b_item|
193
+ if a_item.is_a?(Hash)
194
+ merge_recursively(a_item, b_item)
195
+ else
196
+ b_item
197
+ end
198
+ end
199
+ end
200
+
201
+ # Output results
202
+ def output_results(results)
203
+ shouldWrite = true
204
+ if File.exist?(@config_path)
205
+ if @prompt_overwrite == true
206
+ confirmation = TTY::Prompt.new
207
+ confirmationString = 'Overwrite existing configuration file?'
208
+ shouldWrite = confirmation.yes?(confirmationString)
209
+ end
210
+ end
211
+
212
+ if shouldWrite == true
213
+ File.open(@config_path, 'w') do |file|
214
+ file.write results.to_yaml
215
+ puts "Output configuration to `#{@config_path}`"
216
+ return
217
+ end
218
+ end
219
+
220
+ puts "Output discarded"
221
+ end
222
+
223
+ end
224
+
225
+ end
@@ -15,7 +15,7 @@ class VagrantWizard::PromptParser
15
15
  promptQuestion = @prompt['prompt']
16
16
 
17
17
  begin
18
- require_relative "inputs/#{promptType}"
18
+ require "vagrant-wizard/inputs/#{promptType}"
19
19
  rescue LoadError
20
20
  puts "Unable to process input type '#{promptType}'"
21
21
  if @prompt.key?('default')
@@ -1,3 +1,5 @@
1
+ require "yaml"
2
+
1
3
  module VagrantWizard
2
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
3
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-wizard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe D'Amore
@@ -78,6 +78,7 @@ files:
78
78
  - lib/vagrant-wizard/inputs/select.rb
79
79
  - lib/vagrant-wizard/loader.rb
80
80
  - lib/vagrant-wizard/plugin.rb
81
+ - lib/vagrant-wizard/prompt-display.rb
81
82
  - lib/vagrant-wizard/prompt-parser.rb
82
83
  - lib/vagrant-wizard/version.rb
83
84
  - vagrant-wizard.gemspec