morpheus-cli 2.10.0 → 2.10.1

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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/bin/morpheus +27 -32
  3. data/lib/morpheus/api/accounts_interface.rb +36 -47
  4. data/lib/morpheus/api/api_client.rb +141 -110
  5. data/lib/morpheus/api/app_templates_interface.rb +56 -72
  6. data/lib/morpheus/api/apps_interface.rb +111 -132
  7. data/lib/morpheus/api/auth_interface.rb +30 -0
  8. data/lib/morpheus/api/clouds_interface.rb +71 -76
  9. data/lib/morpheus/api/custom_instance_types_interface.rb +21 -46
  10. data/lib/morpheus/api/dashboard_interface.rb +10 -17
  11. data/lib/morpheus/api/deploy_interface.rb +60 -72
  12. data/lib/morpheus/api/deployments_interface.rb +53 -71
  13. data/lib/morpheus/api/groups_interface.rb +55 -45
  14. data/lib/morpheus/api/instance_types_interface.rb +19 -23
  15. data/lib/morpheus/api/instances_interface.rb +179 -177
  16. data/lib/morpheus/api/key_pairs_interface.rb +11 -17
  17. data/lib/morpheus/api/license_interface.rb +18 -23
  18. data/lib/morpheus/api/load_balancers_interface.rb +54 -69
  19. data/lib/morpheus/api/logs_interface.rb +25 -29
  20. data/lib/morpheus/api/options_interface.rb +13 -17
  21. data/lib/morpheus/api/provision_types_interface.rb +19 -22
  22. data/lib/morpheus/api/roles_interface.rb +75 -94
  23. data/lib/morpheus/api/security_group_rules_interface.rb +28 -37
  24. data/lib/morpheus/api/security_groups_interface.rb +39 -51
  25. data/lib/morpheus/api/servers_interface.rb +113 -115
  26. data/lib/morpheus/api/setup_interface.rb +31 -0
  27. data/lib/morpheus/api/task_sets_interface.rb +36 -38
  28. data/lib/morpheus/api/tasks_interface.rb +56 -69
  29. data/lib/morpheus/api/users_interface.rb +67 -76
  30. data/lib/morpheus/api/virtual_images_interface.rb +61 -61
  31. data/lib/morpheus/api/whoami_interface.rb +12 -15
  32. data/lib/morpheus/cli.rb +71 -60
  33. data/lib/morpheus/cli/accounts.rb +254 -315
  34. data/lib/morpheus/cli/alias_command.rb +219 -0
  35. data/lib/morpheus/cli/app_templates.rb +264 -272
  36. data/lib/morpheus/cli/apps.rb +608 -671
  37. data/lib/morpheus/cli/cli_command.rb +259 -21
  38. data/lib/morpheus/cli/cli_registry.rb +99 -14
  39. data/lib/morpheus/cli/clouds.rb +599 -372
  40. data/lib/morpheus/cli/config_file.rb +126 -0
  41. data/lib/morpheus/cli/credentials.rb +141 -117
  42. data/lib/morpheus/cli/dashboard_command.rb +48 -56
  43. data/lib/morpheus/cli/deployments.rb +254 -268
  44. data/lib/morpheus/cli/deploys.rb +150 -142
  45. data/lib/morpheus/cli/error_handler.rb +38 -0
  46. data/lib/morpheus/cli/groups.rb +551 -179
  47. data/lib/morpheus/cli/hosts.rb +862 -617
  48. data/lib/morpheus/cli/instance_types.rb +103 -95
  49. data/lib/morpheus/cli/instances.rb +1335 -1009
  50. data/lib/morpheus/cli/key_pairs.rb +82 -90
  51. data/lib/morpheus/cli/library.rb +498 -499
  52. data/lib/morpheus/cli/license.rb +83 -101
  53. data/lib/morpheus/cli/load_balancers.rb +314 -300
  54. data/lib/morpheus/cli/login.rb +66 -44
  55. data/lib/morpheus/cli/logout.rb +47 -46
  56. data/lib/morpheus/cli/mixins/accounts_helper.rb +69 -31
  57. data/lib/morpheus/cli/mixins/infrastructure_helper.rb +106 -0
  58. data/lib/morpheus/cli/mixins/print_helper.rb +181 -17
  59. data/lib/morpheus/cli/mixins/provisioning_helper.rb +535 -458
  60. data/lib/morpheus/cli/mixins/whoami_helper.rb +2 -2
  61. data/lib/morpheus/cli/option_parser.rb +35 -0
  62. data/lib/morpheus/cli/option_types.rb +232 -192
  63. data/lib/morpheus/cli/recent_activity_command.rb +61 -65
  64. data/lib/morpheus/cli/remote.rb +446 -199
  65. data/lib/morpheus/cli/roles.rb +884 -906
  66. data/lib/morpheus/cli/security_group_rules.rb +213 -203
  67. data/lib/morpheus/cli/security_groups.rb +237 -192
  68. data/lib/morpheus/cli/shell.rb +338 -231
  69. data/lib/morpheus/cli/tasks.rb +326 -308
  70. data/lib/morpheus/cli/users.rb +457 -462
  71. data/lib/morpheus/cli/version.rb +1 -1
  72. data/lib/morpheus/cli/version_command.rb +16 -18
  73. data/lib/morpheus/cli/virtual_images.rb +526 -345
  74. data/lib/morpheus/cli/whoami.rb +125 -111
  75. data/lib/morpheus/cli/workflows.rb +338 -185
  76. data/lib/morpheus/formatters.rb +8 -1
  77. data/lib/morpheus/logging.rb +1 -1
  78. data/lib/morpheus/rest_client.rb +17 -8
  79. metadata +9 -3
  80. data/lib/morpheus/api/custom_instance_types.rb +0 -55
@@ -1,7 +1,7 @@
1
1
  require 'table_print'
2
2
  require 'morpheus/cli/mixins/print_helper'
3
3
 
4
- # Mixin for Morpheus::Cli command classes
4
+ # Mixin for Morpheus::Cli command classes
5
5
  # Provides common methods for fetching and printing accounts, roles, and users.
6
6
  # The including class must establish @accounts_interface, @roles_interface, @users_interface
7
7
  module Morpheus::Cli::WhoamiHelper
@@ -14,7 +14,7 @@ module Morpheus::Cli::WhoamiHelper
14
14
  whoami_interface = @whoami_interface || @api_client.whoami
15
15
  whoami_response = whoami_interface.get()
16
16
  # whoami_response = @whoami_interface.get()
17
- @current_user = whoami_response["user"]
17
+ @current_user = whoami_response["user"]
18
18
  if @current_user.empty?
19
19
  print_red_alert "Unauthenticated. Please login."
20
20
  exit 1
@@ -0,0 +1,35 @@
1
+ require 'optparse'
2
+
3
+ module Morpheus
4
+ module Cli
5
+
6
+ # an enhanced OptionParser
7
+ # not used yet, maybe ever =o
8
+ class Morpheus::Cli::OptionParser < OptionParser
9
+
10
+ attr_reader :footer
11
+
12
+ def footer=(msg)
13
+ @footer = msg
14
+ end
15
+
16
+ alias :original_to_s :to_s
17
+
18
+ def to_s
19
+ full_help_message
20
+ end
21
+
22
+ def full_help_message
23
+ out = ""
24
+ out << original_to_s
25
+ if footer
26
+ out << footer.to_s.strip
27
+ out << "\n"
28
+ end
29
+ out
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -3,20 +3,28 @@ require 'readline'
3
3
  module Morpheus
4
4
  module Cli
5
5
  module OptionTypes
6
- include Term::ANSIColor
6
+ include Term::ANSIColor
7
7
 
8
8
 
9
- def self.confirm(message,options={})
10
- if options[:yes] == true
11
- return true
12
- end
13
- value_found = false
14
- while value_found == false do
15
- print "#{message} (yes/no): "
9
+ def self.confirm(message,options={})
10
+ if options[:yes] == true
11
+ return true
12
+ end
13
+ default_value = options[:default]
14
+ value_found = false
15
+ while value_found == false do
16
+ if default_value.nil?
17
+ print "#{message} (yes/no): "
18
+ else
19
+ print "#{message} (yes/no) [#{!!default_value ? 'yes' : 'no'}]: "
20
+ end
16
21
  input = $stdin.gets.chomp!
17
- if input.downcase == 'yes'
22
+ if input.empty? && !default_value.nil?
23
+ return !!default_value
24
+ end
25
+ if input.downcase == 'yes' || input.downcase == 'y'
18
26
  return true
19
- elsif input.downcase == 'no'
27
+ elsif input.downcase == 'no' || input.downcase == 'n'
20
28
  return false
21
29
  else
22
30
  puts "Invalid Option... Please try again."
@@ -62,7 +70,7 @@ module Morpheus
62
70
  value_found = true
63
71
  end
64
72
  if !value_found
65
- # select type is special because it supports skipSingleOption
73
+ # select type is special because it supports skipSingleOption
66
74
  # and prints the available options on error
67
75
  if option_type['type'] == 'select'
68
76
  value = select_prompt(option_type, api_client, api_params, true)
@@ -86,7 +94,7 @@ module Morpheus
86
94
  if option_type['type'] == 'number'
87
95
  value = number_prompt(option_type)
88
96
  elsif option_type['type'] == 'password'
89
- value = password_prompt(option_type)
97
+ value = password_prompt(option_type)
90
98
  elsif option_type['type'] == 'checkbox'
91
99
  value = checkbox_prompt(option_type)
92
100
  elsif option_type['type'] == 'radio'
@@ -94,16 +102,17 @@ module Morpheus
94
102
  elsif option_type['type'] == 'textarea'
95
103
  value = multiline_prompt(option_type)
96
104
  elsif option_type['type'] == 'code-editor'
97
- value = multiline_prompt(option_type)
105
+ value = multiline_prompt(option_type)
98
106
  elsif option_type['type'] == 'select'
99
107
  value = select_prompt(option_type,api_client, api_params)
100
108
  elsif option_type['type'] == 'hidden'
101
109
  value = option_type['defaultValue']
102
110
  input = value
111
+ elsif option_type['type'] == 'file'
112
+ value = file_prompt(option_type)
103
113
  else
104
114
  value = generic_prompt(option_type)
105
115
  end
106
-
107
116
  end
108
117
  context_map[option_type['fieldName']] = value
109
118
  end
@@ -113,218 +122,249 @@ module Morpheus
113
122
 
114
123
 
115
124
  def self.radio_prompt(option_type)
116
- value_found = false
117
- value = nil
118
- options = []
119
- if option_type['config'] and option_type['config']['radioOptions']
120
- option_type['config']['radioOptions'].each do |radio_option|
121
- options << {key: radio_option['key'], checked: radio_option['checked']}
122
- end
123
- end
124
- optionString = options.collect{ |b| b[:checked] ? "(#{b[:key]})" : b[:key]}.join(', ')
125
- while !value_found do
126
- print "#{option_type['fieldLabel']}#{option_type['fieldAddOn'] ? ('(' + option_type['fieldAddOn'] + ') ') : '' }[#{optionString}]: "
127
- input = $stdin.gets.chomp!
128
- if input == '?'
129
- help_prompt(option_type)
130
- else
131
- if input.nil? || input.empty?
132
- selectedOption = options.find{|o| o[:checked] == true}
133
- else
134
- selectedOption = options.find{|o| o[:key].downcase == input.downcase}
135
- end
136
-
137
- if selectedOption
138
- value = selectedOption[:key]
139
- else
140
- puts "Invalid Option. Please select from #{optionString}."
141
- end
142
- if !value.nil? || option_type['required'] != true
143
- value_found = true
144
- end
145
- end
146
- end
147
- return value
148
- end
149
-
150
- def self.number_prompt(option_type)
151
- value_found = false
152
- value = nil
153
- while !value_found do
154
- print "#{option_type['fieldLabel']}#{option_type['fieldAddOn'] ? ('(' + option_type['fieldAddOn'] + ') ') : '' }#{!option_type['required'] ? ' (optional)' : ''}#{option_type['defaultValue'] ? ' ['+option_type['defaultValue'].to_s+']' : ''}: "
155
- input = $stdin.gets.chomp!
156
- value = input.empty? ? option_type['defaultValue'] : input.to_i
157
- if input == '?'
158
- help_prompt(option_type)
159
- elsif !value.nil? || option_type['required'] != true
160
- value_found = true
161
- end
162
- end
163
- return value
164
- end
165
-
166
- def self.select_prompt(option_type,api_client, api_params={}, no_prompt=false)
167
125
  value_found = false
168
126
  value = nil
169
- if option_type['selectOptions']
170
- select_options = option_type['selectOptions']
171
- elsif option_type['optionSource']
172
- select_options = load_source_options(option_type['optionSource'],api_client,api_params)
173
- else
174
- raise "select_prompt() requires selectOptions or optionSource!"
175
- end
176
- if !select_options.nil? && select_options.count == 1 && option_type['skipSingleOption'] == true
177
- value_found = true
178
- value = select_options[0]['value']
179
- end
180
- if no_prompt
181
- if !value_found
182
- if option_type['required']
183
- print Term::ANSIColor.red, "\nMissing Required Option\n\n"
184
- print Term::ANSIColor.red, " * #{option_type['fieldLabel']} [-O #{option_type['fieldContext'] ? (option_type['fieldContext']+'.') : ''}#{option_type['fieldName']}=] - ", Term::ANSIColor.reset , "#{option_type['description']}\n"
185
- display_select_options(select_options)
186
- print "\n"
187
- exit 1
188
- else
189
- return nil
190
- end
127
+ options = []
128
+ if option_type['config'] and option_type['config']['radioOptions']
129
+ option_type['config']['radioOptions'].each do |radio_option|
130
+ options << {key: radio_option['key'], checked: radio_option['checked']}
191
131
  end
192
132
  end
133
+ optionString = options.collect{ |b| b[:checked] ? "(#{b[:key]})" : b[:key]}.join(', ')
193
134
  while !value_found do
194
- Readline.completion_append_character = ""
195
- Readline.basic_word_break_characters = ''
196
- Readline.completion_proc = proc {|s| select_options.clone.collect{|opt| opt['name']}.grep(/^#{Regexp.escape(s)}/)}
197
- input = Readline.readline("#{option_type['fieldLabel']}#{option_type['fieldAddOn'] ? ('(' + option_type['fieldAddOn'] + ') ') : '' }#{!option_type['required'] ? ' (optional)' : ''}#{option_type['defaultValue'] ? ' ['+option_type['defaultValue'].to_s+']' : ''} ['?' for options]: ", false).to_s
198
- input = input.chomp.strip
199
- if input.empty?
200
- value = option_type['defaultValue']
135
+ print "#{option_type['fieldLabel']}#{option_type['fieldAddOn'] ? ('(' + option_type['fieldAddOn'] + ') ') : '' }[#{optionString}]: "
136
+ input = $stdin.gets.chomp!
137
+ if input == '?'
138
+ help_prompt(option_type)
201
139
  else
202
- select_option = select_options.find{|b| b['name'] == input || (!b['value'].nil? && b['value'].to_s == input) || (b['value'].nil? && input.empty?)}
203
- if select_option
204
- value = select_option['value']
205
- elsif !input.nil? && !input.empty?
206
- input = '?'
140
+ if input.nil? || input.empty?
141
+ selectedOption = options.find{|o| o[:checked] == true}
142
+ else
143
+ selectedOption = options.find{|o| o[:key].downcase == input.downcase}
207
144
  end
208
- end
209
-
210
- if input == '?'
211
- help_prompt(option_type)
212
- display_select_options(select_options)
213
- elsif !value.nil? || option_type['required'] != true
214
- value_found = true
215
- end
216
- end
217
- return value
218
- end
219
-
220
- def self.checkbox_prompt(option_type)
221
- value_found = false
222
- value = nil
223
- while !value_found do
224
- print "#{option_type['fieldLabel']} (yes/no) [#{option_type['defaultValue'] == 'on' ? 'yes' : 'no'}]: "
225
- input = $stdin.gets.chomp!
226
- if input.downcase == 'yes'
227
- value = 'on'
228
- elsif input.downcase == 'no'
229
- value = 'off'
145
+ if selectedOption
146
+ value = selectedOption[:key]
230
147
  else
231
- value = option_type['defaultValue']
148
+ puts "Invalid Option. Please select from #{optionString}."
232
149
  end
233
- if input == '?'
234
- help_prompt(option_type)
235
- elsif !value.nil? || option_type['required'] != true
150
+ if !value.nil? || option_type['required'] != true
236
151
  value_found = true
237
152
  end
153
+ end
238
154
  end
239
155
  return value
240
- end
156
+ end
241
157
 
242
- def self.generic_prompt(option_type)
158
+ def self.number_prompt(option_type)
243
159
  value_found = false
244
160
  value = nil
245
161
  while !value_found do
246
162
  print "#{option_type['fieldLabel']}#{option_type['fieldAddOn'] ? ('(' + option_type['fieldAddOn'] + ') ') : '' }#{!option_type['required'] ? ' (optional)' : ''}#{option_type['defaultValue'] ? ' ['+option_type['defaultValue'].to_s+']' : ''}: "
247
163
  input = $stdin.gets.chomp!
248
- value = input.empty? ? option_type['defaultValue'] : input
164
+ value = input.empty? ? option_type['defaultValue'] : input.to_i
249
165
  if input == '?'
250
- help_prompt(option_type)
166
+ help_prompt(option_type)
251
167
  elsif !value.nil? || option_type['required'] != true
252
168
  value_found = true
253
169
  end
170
+ end
171
+ return value
254
172
  end
255
- return value
256
- end
257
173
 
258
- def self.multiline_prompt(option_type)
259
- value_found = false
260
- value = nil
261
- while !value_found do
262
- if value.nil?
263
- print "#{option_type['fieldLabel']}#{option_type['fieldAddOn'] ? ('(' + option_type['fieldAddOn'] + ') ') : '' }#{!option_type['required'] ? ' (optional)' : ''} [Type 'EOF' to stop input]: \n"
174
+ def self.select_prompt(option_type,api_client, api_params={}, no_prompt=false)
175
+ value_found = false
176
+ value = nil
177
+ if option_type['selectOptions']
178
+ select_options = option_type['selectOptions']
179
+ elsif option_type['optionSource']
180
+ select_options = load_source_options(option_type['optionSource'],api_client,api_params)
181
+ else
182
+ raise "select_prompt() requires selectOptions or optionSource!"
183
+ end
184
+ if !select_options.nil? && select_options.count == 1 && option_type['skipSingleOption'] == true
185
+ value_found = true
186
+ value = select_options[0]['value']
187
+ end
188
+ if no_prompt
189
+ if !value_found
190
+ if option_type['required']
191
+ print Term::ANSIColor.red, "\nMissing Required Option\n\n"
192
+ print Term::ANSIColor.red, " * #{option_type['fieldLabel']} [-O #{option_type['fieldContext'] ? (option_type['fieldContext']+'.') : ''}#{option_type['fieldName']}=] - ", Term::ANSIColor.reset , "#{option_type['description']}\n"
193
+ display_select_options(select_options)
194
+ print "\n"
195
+ exit 1
196
+ else
197
+ return nil
198
+ end
264
199
  end
265
- input = $stdin.gets.chomp!
266
- # value = input.empty? ? option_type['defaultValue'] : input
267
- if input == '?' && value.nil?
200
+ end
201
+ while !value_found do
202
+ Readline.completion_append_character = ""
203
+ Readline.basic_word_break_characters = ''
204
+ Readline.completion_proc = proc {|s| select_options.clone.collect{|opt| opt['name']}.grep(/^#{Regexp.escape(s)}/)}
205
+ input = Readline.readline("#{option_type['fieldLabel']}#{option_type['fieldAddOn'] ? ('(' + option_type['fieldAddOn'] + ') ') : '' }#{!option_type['required'] ? ' (optional)' : ''}#{option_type['defaultValue'] ? ' ['+option_type['defaultValue'].to_s+']' : ''} ['?' for options]: ", false).to_s
206
+ input = input.chomp.strip
207
+ if input.empty?
208
+ value = option_type['defaultValue']
209
+ else
210
+ select_option = select_options.find{|b| b['name'] == input || (!b['value'].nil? && b['value'].to_s == input) || (b['value'].nil? && input.empty?)}
211
+ if select_option
212
+ value = select_option['value']
213
+ elsif !input.nil? && !input.empty?
214
+ input = '?'
215
+ end
216
+ end
217
+ if input == '?'
268
218
  help_prompt(option_type)
269
- elsif (!value.nil? || option_type['required'] != true) && input.chomp == 'EOF'
270
- value_found = true
271
- else
272
- if value.nil?
273
- value = ''
219
+ display_select_options(select_options)
220
+ elsif !value.nil? || option_type['required'] != true
221
+ value_found = true
274
222
  end
275
- value << input + "\n"
276
223
  end
277
- end
278
- return value
279
- end
224
+ return value
225
+ end
280
226
 
281
- def self.password_prompt(option_type)
282
- value_found = false
283
- while !value_found do
284
- print "#{option_type['fieldLabel']}#{option_type['fieldAddOn'] ? ('(' + option_type['fieldAddOn'] + ') ') : '' }#{!option_type['required'] ? ' (optional)' : ''}: "
285
- input = STDIN.noecho(&:gets).chomp!
286
- value = input
287
- print "\n"
288
- if input == '?'
289
- help_prompt(option_type)
290
- elsif !value.empty? || option_type['required'] != true
291
- value_found = true
227
+ def self.checkbox_prompt(option_type)
228
+ value_found = false
229
+ value = nil
230
+ while !value_found do
231
+ print "#{option_type['fieldLabel']} (yes/no) [#{option_type['defaultValue'] == 'on' ? 'yes' : 'no'}]: "
232
+ input = $stdin.gets.chomp!
233
+ if input.downcase == 'yes'
234
+ value = 'on'
235
+ elsif input.downcase == 'no'
236
+ value = 'off'
237
+ else
238
+ value = option_type['defaultValue']
239
+ end
240
+ if input == '?'
241
+ help_prompt(option_type)
242
+ elsif !value.nil? || option_type['required'] != true
243
+ value_found = true
244
+ end
245
+ end
246
+ return value
292
247
  end
293
- end
294
- return value
295
- end
296
248
 
297
- def self.help_prompt(option_type)
298
- print Term::ANSIColor.green," * #{option_type['fieldLabel']} [-O #{option_type['fieldContext'] ? (option_type['fieldContext']+'.') : ''}#{option_type['fieldName']}=] - ", Term::ANSIColor.reset , "#{option_type['description']}\n"
299
- end
249
+ def self.generic_prompt(option_type)
250
+ value_found = false
251
+ value = nil
252
+ while !value_found do
253
+ print "#{option_type['fieldLabel']}#{option_type['fieldAddOn'] ? ('(' + option_type['fieldAddOn'] + ') ') : '' }#{!option_type['required'] ? ' (optional)' : ''}#{option_type['defaultValue'] ? ' ['+option_type['defaultValue'].to_s+']' : ''}: "
254
+ input = $stdin.gets.chomp!
255
+ value = input.empty? ? option_type['defaultValue'] : input
256
+ if input == '?'
257
+ help_prompt(option_type)
258
+ elsif !value.nil? || option_type['required'] != true
259
+ value_found = true
260
+ end
261
+ end
262
+ return value
263
+ end
300
264
 
265
+ def self.multiline_prompt(option_type)
266
+ value_found = false
267
+ value = nil
268
+ while !value_found do
269
+ if value.nil?
270
+ print "#{option_type['fieldLabel']}#{option_type['fieldAddOn'] ? ('(' + option_type['fieldAddOn'] + ') ') : '' }#{!option_type['required'] ? ' (optional)' : ''} [Type 'EOF' to stop input]: \n"
271
+ end
272
+ input = $stdin.gets.chomp!
273
+ # value = input.empty? ? option_type['defaultValue'] : input
274
+ if input == '?' && value.nil?
275
+ help_prompt(option_type)
276
+ elsif (!value.nil? || option_type['required'] != true) && input.chomp == 'EOF'
277
+ value_found = true
278
+ else
279
+ if value.nil?
280
+ value = ''
281
+ end
282
+ value << input + "\n"
283
+ end
284
+ end
285
+ return value
286
+ end
301
287
 
302
- def self.load_source_options(source,api_client,params)
303
- api_client.options.options_for_source(source,params)['data']
304
- end
288
+ def self.password_prompt(option_type)
289
+ value_found = false
290
+ while !value_found do
291
+ print "#{option_type['fieldLabel']}#{option_type['fieldAddOn'] ? ('(' + option_type['fieldAddOn'] + ') ') : '' }#{!option_type['required'] ? ' (optional)' : ''}: "
292
+ input = $stdin.noecho(&:gets).chomp!
293
+ value = input
294
+ print "\n"
295
+ if input == '?'
296
+ help_prompt(option_type)
297
+ elsif !value.empty? || option_type['required'] != true
298
+ value_found = true
299
+ end
300
+ end
301
+ return value
302
+ end
305
303
 
306
- def self.display_select_options(select_options = [])
307
- puts "\nOptions"
308
- puts "==============="
309
- select_options.each do |option|
310
- puts " * #{option['name']} [#{option['value']}]"
311
- end
312
- puts "\n\n"
313
- end
304
+ def self.file_prompt(option_type)
305
+ value_found = false
306
+ value = nil
307
+ while !value_found do
308
+ print "#{option_type['fieldLabel']}#{option_type['fieldAddOn'] ? ('(' + option_type['fieldAddOn'] + ') ') : '' }#{!option_type['required'] ? ' (optional)' : ''}#{option_type['defaultValue'] ? ' ['+option_type['defaultValue'].to_s+']' : ''}: "
309
+ Readline.completion_append_character = ""
310
+ Readline.basic_word_break_characters = ''
311
+ Readline.completion_proc = proc {|s| Readline::FILENAME_COMPLETION_PROC.call(s) }
312
+ input = Readline.readline("#{option_type['fieldLabel']}#{option_type['fieldAddOn'] ? ('(' + option_type['fieldAddOn'] + ') ') : '' }#{!option_type['required'] ? ' (optional)' : ''}#{option_type['defaultValue'] ? ' ['+option_type['defaultValue'].to_s+']' : ''} ['?' for options]: ", false).to_s
313
+ input = input.chomp.strip
314
+ #input = $stdin.gets.chomp!
315
+ value = input.empty? ? option_type['defaultValue'] : input.to_s
316
+ if input == '?'
317
+ help_prompt(option_type)
318
+ elsif value.empty? && option_type['required'] != true
319
+ value = nil
320
+ value_found = true
321
+ elsif value
322
+ filename = File.expand_path(value)
323
+ if !File.exists?(filename)
324
+ # print_red_alert "File not found: #{filename}"
325
+ # exit 1
326
+ print Term::ANSIColor.red," File not found: #{filename}",Term::ANSIColor.reset, "\n"
327
+ elsif !File.file?(filename)
328
+ print Term::ANSIColor.red," Argument is not a file: #{filename}",Term::ANSIColor.reset, "\n"
329
+ else
330
+ value = filename
331
+ value_found = true
332
+ end
333
+ end
334
+ end
335
+ return value
336
+ end
314
337
 
315
- def self.format_option_types_help(option_types)
316
- if option_types.empty?
317
- "Available Options:\nNone\n\n"
318
- else
319
- option_lines = option_types.collect {|it| " -O #{it['fieldName']}=\"value\"" }.join("\n")
320
- "Available Options:\n#{option_lines}\n\n"
321
- end
322
- end
323
-
324
- def self.display_option_types_help(option_types)
325
- puts self.format_option_types_help(option_types)
326
- end
338
+ def self.help_prompt(option_type)
339
+ print Term::ANSIColor.green," * #{option_type['fieldLabel']} [-O #{option_type['fieldContext'] ? (option_type['fieldContext']+'.') : ''}#{option_type['fieldName']}=] - ", Term::ANSIColor.reset , "#{option_type['description']}\n"
340
+ end
341
+
342
+
343
+ def self.load_source_options(source,api_client,params)
344
+ api_client.options.options_for_source(source,params)['data']
345
+ end
346
+
347
+ def self.display_select_options(select_options = [])
348
+ puts "\nOptions"
349
+ puts "==============="
350
+ select_options.each do |option|
351
+ puts " * #{option['name']} [#{option['value']}]"
352
+ end
353
+ puts "\n\n"
354
+ end
327
355
 
328
- end
329
- end
330
- end
356
+ def self.format_option_types_help(option_types)
357
+ if option_types.empty?
358
+ "Available Options:\nNone\n\n"
359
+ else
360
+ option_lines = option_types.collect {|it| " -O #{it['fieldName']}=\"value\"" }.join("\n")
361
+ "Available Options:\n#{option_lines}\n\n"
362
+ end
363
+ end
364
+ def self.display_option_types_help(option_types)
365
+ puts self.format_option_types_help(option_types)
366
+ end
367
+
368
+ end
369
+ end
370
+ end