Method: Morpheus::Cli::LibraryFormsCommand#update

Defined in:
lib/morpheus/cli/commands/library_forms_command.rb

#update(args) ⇒ Object



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/morpheus/cli/commands/library_forms_command.rb', line 195

def update(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[form] [options]")
    build_option_type_options(opts, options, update_option_type_form_option_types())
    build_standard_update_options(opts, options)
    opts.footer = "Update a form.\n[form] is required. This is the name or id of a form.\n"
  end
  optparse.parse!(args)
  verify_args!(args:args, optparse:optparse, count:1)
  connect(options)
  form = find_option_type_form_by_name_or_id(args[0])
  return 1, "Form not found" if form.nil?
  parse_payload(options, rest_object_key) do |payload|
    option_types = update_option_type_form_option_types()
    v_prompt = no_prompt(option_types, options)
    #v_prompt.deep_compact!.booleanize! # remove empty values and convert checkbox "on" and "off" to true and false
    payload.deep_merge!({rest_object_key => v_prompt})
    if payload[rest_object_key].empty? # || options[:no_prompt]
      raise_command_error "Specify at least one option to update.\n#{optparse}"
    end
  end
  execute_api(@option_type_forms_interface, :update, [form['id']], options, 'backup') do |json_response|
    form = json_response[rest_object_key]
    print_green_success "Updated form #{form['name']}"
    _get(form['id'], options.merge(params:{}))
  end
end