Class: Morpheus::Cli::PriceSetsCommand

Inherits:
Object
  • Object
show all
Includes:
AccountsHelper, CliCommand, ProvisioningHelper, WhoamiHelper
Defined in:
lib/morpheus/cli/commands/price_sets_command.rb

Instance Attribute Summary

Attributes included from CliCommand

#no_prompt

Instance Method Summary collapse

Methods included from WhoamiHelper

#current_account, #current_user, #current_user_permissions, included, #is_master_account, #load_whoami

Methods included from ProvisioningHelper

#accounts_interface, #add_perms_options, #api_client, #apps_interface, #cloud_datastores_interface, #clouds_interface, #datastores_interface, #find_app_by_id, #find_app_by_name, #find_app_by_name_or_id, #find_cloud_by_id_for_provisioning, #find_cloud_by_name_for_provisioning, #find_cloud_by_name_or_id_for_provisioning, #find_cloud_resource_pool_by_name_or_id, #find_group_by_id_for_provisioning, #find_group_by_name_for_provisioning, #find_group_by_name_or_id_for_provisioning, #find_host_by_id, #find_host_by_name, #find_host_by_name_or_id, #find_instance_by_id, #find_instance_by_name, #find_instance_by_name_or_id, #find_instance_type_by_code, #find_instance_type_by_id, #find_instance_type_by_name, #find_instance_type_by_name_or_id, #find_instance_type_layout_by_id, #find_server_by_id, #find_server_by_name, #find_server_by_name_or_id, #find_workflow_by_id, #find_workflow_by_name, #find_workflow_by_name_or_id, #format_app_status, #format_blueprint_type, #format_container_connection_string, #format_container_status, #format_instance_connection_string, #format_instance_container_display_name, #format_instance_status, #format_metadata, #format_snapshot_status, #get_available_accounts, #get_available_clouds, #get_available_environments, #get_available_groups, #get_available_plans, #get_provision_type_for_zone_type, #get_static_environments, included, #instance_type_layouts_interface, #instance_types_interface, #instances_interface, #load_balance_protocols_dropdown, #options_interface, #parse_blueprint_type, #parse_host_id_list, #parse_instance_id_list, #parse_metadata, #parse_resource_id_list, #parse_server_id_list, #print_permissions, #prompt_evars, #prompt_exposed_ports, #prompt_instance_load_balancer, #prompt_metadata, #prompt_network_interfaces, #prompt_new_instance, #prompt_permissions, #prompt_permissions_v2, #prompt_resize_volumes, #prompt_security_groups, #prompt_service_plan_options, #prompt_volumes, #provision_types_interface, #reject_service_plan_option_types, #servers_interface

Methods included from AccountsHelper

#account_column_definitions, #account_users_interface, #accounts_interface, #find_account_by_id, #find_account_by_name, #find_account_by_name_or_id, #find_account_from_options, #find_all_user_ids, #find_role_by_id, #find_role_by_name, #find_role_by_name_or_id, #find_user_by_id, #find_user_by_username, #find_user_by_username_or_id, #find_user_group_by_id, #find_user_group_by_name, #find_user_group_by_name_or_id, #format_access_string, #format_role_type, #format_user_role_names, #format_user_status, #get_access_color, #get_access_string, included, #list_account_column_definitions, #list_user_column_definitions, #list_user_group_column_definitions, #role_column_definitions, #roles_interface, #subtenant_role_column_definitions, #user_column_definitions, #user_group_column_definitions, #user_groups_interface

Methods included from CliCommand

#add_query_parameter, #apply_options, #build_common_options, #build_get_options, #build_list_options, #build_option_type_options, #build_standard_add_many_options, #build_standard_add_options, #build_standard_api_options, #build_standard_delete_options, #build_standard_get_options, #build_standard_list_options, #build_standard_post_options, #build_standard_put_options, #build_standard_remove_options, #build_standard_update_options, #command_description, #command_name, #confirm, #confirm!, #default_refresh_interval, #default_sigdig, #default_subcommand, #establish_remote_appliance_connection, #execute_api, #execute_api_payload, #execute_api_request, #find_all, #find_all_json, #find_by_id, #find_by_name, #find_by_name_or_id, #find_record, #find_record_json, #full_command_usage, #get_interface, #get_list_key, #get_object_key, #get_subcommand_description, #handle_each_payload, #handle_subcommand, included, #interactive?, #my_help_command, #my_terminal, #my_terminal=, #parse_array, #parse_bytes_param, #parse_get_options!, #parse_id_list, #parse_labels, #parse_list_options, #parse_list_options!, #parse_list_subtitles, #parse_options, #parse_parameter_as_resource_id!, #parse_passed_options, #parse_payload, #parse_query_options, #print, #print_error, #println, #prog_name, #puts, #puts_error, #raise_args_error, #raise_command_error, #render_response, #run_command_for_each_arg, #subcommand_aliases, #subcommand_description, #subcommand_usage, #subcommands, #usage, #validate_outfile, #verify_args!, #visible_subcommands

Instance Method Details

#_get(price_set_id, options = {}) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/morpheus/cli/commands/price_sets_command.rb', line 104

def _get(price_set_id, options = {})
  params = {}
  begin
    @price_sets_interface.setopts(options)

    if !(price_set_id.to_s =~ /\A\d{1,}\Z/)
      price_set = find_price_set(price_set_id)

      if !price_set
        print_red_alert "Price set #{price_set_id} not found"
        exit 1
      end
      price_set_id = price_set['id']
    end

    if options[:dry_run]
      print_dry_run @price_sets_interface.dry.get(price_set_id)
      return
    end
    json_response = @price_sets_interface.get(price_set_id)

    render_result = render_with_format(json_response, options, 'priceSet')
    return 0 if render_result

    title = "Morpheus Price Set"
    subtitles = []
    subtitles += parse_list_subtitles(options)
    print_h1 title, subtitles

    price_set = json_response['priceSet']
    print cyan
    description_cols = {
        "ID" => lambda {|it| it['id']},
        "Name" => lambda {|it| it['name']},
        "Code" => lambda {|it| it['code']},
        "Region Code" => lambda {|it| it['regionCode']},
        "Price Unit" => lambda {|it| (it['priceUnit'] || 'month').capitalize},
        "Type" => lambda {|it| price_set_type_label(it['type'])},
        "Cloud" => lambda {|it| it['zone'].nil? ? 'All' : it['zone']['name']},
        "Resource Pool" => lambda {|it| it['zonePool'].nil? ? nil : it['zonePool']['name']}
    }

    print_description_list(description_cols, price_set)

    print_h2 "Prices"
    prices = price_set['prices']

    if prices && !prices.empty?
      rows = prices.collect do |it|
        {
            id: it['id'],
            name: it['name'],
            pricing: (it['priceType'] == 'platform' ? '+' : '') + currency_sym(it['currency']) + (it['price'] || 0.0).to_s + (it['additionalPriceUnit'].nil? ? '' : '/' + it['additionalPriceUnit']) + '/' + (it['priceUnit'] || 'month').capitalize
        }
      end
      print as_pretty_table(rows, [:id, :name, :pricing], options)
    else
      print cyan,"No prices.",reset,"\n"
    end
    print reset,"\n"
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#add(args) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/morpheus/cli/commands/price_sets_command.rb', line 171

def add(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    opts.on("--name NAME", String, "Price set name") do |val|
      params['name'] = val.to_s
    end
    opts.on("--code CODE", String, "Price set code, unique identifier") do |val|
      params['code'] = val.to_s
    end
    opts.on("--region-code CODE", String, "Price set region code") do |val|
      params['regionCode'] = val.to_s
    end
    opts.on("--cloud [CLOUD]", String, "Cloud ID or name") do |val|
      options[:cloud] = val
    end
    opts.on("--resource-pool [POOL]", String, "Resource pool ID or name") do |val|
      options[:resourcePool] = val
    end
    opts.on("--price-unit [UNIT]", String, "Price unit") do |val|
      if price_units.include?(val)
        params['priceUnit'] = val
      else
        raise_command_error "Unrecognized price unit '#{val}'\n- Available price units -\n#{price_units.join("\n")}"
      end
    end
    opts.on('-t', "--type [TYPE]", String, "Price set type") do |val|
      if ['fixed', 'compute_plus_storage', 'component','load_balancer','snapshot','virtual_image','software_or_service'].include?(val)
        params['type'] = val
      else
        raise_command_error "Unrecognized price set type #{val}"
      end
    end
    opts.on('--prices [LIST]', Array, 'Price(s), comma separated list of price IDs') do |list|
      params['prices'] = list.collect {|it| it.to_s.strip.empty? || !it.to_i ? nil : it.to_s.strip}.compact.uniq.collect {|it| {'id' => it.to_i}}
    end
    build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote, :quiet])
    opts.footer = "Create price set.\n" +
      "Name, code, type and price unit are required."
  end
  optparse.parse!(args)
  connect(options)
  if args.count != 0
    raise_command_error "wrong number of arguments, expected 0 and got (#{args.count}) #{args}\n#{optparse}"
    return 1
  end

  begin
    payload = parse_payload(options)

    if !payload
      # name
      params['name'] ||= Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'name', 'type' => 'text', 'fieldLabel' => 'Price Set Name', 'required' => true, 'description' => 'Price Set Name.'}],options[:options],@api_client,{}, options[:no_prompt])['name']

      # code
      params['code'] ||= Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'code', 'type' => 'text', 'fieldLabel' => 'Price Set Code', 'required' => true, 'defaultValue' => params['name'].gsub(/[^0-9a-z ]/i, '').gsub(' ', '.').downcase, 'description' => 'Price Set Code.'}],options[:options],@api_client,{}, options[:no_prompt])['code']

      # region code
      params['regionCode'] ||= Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'regionCode', 'type' => 'text', 'fieldLabel' => 'Price Set Region Code', 'required' => false, 'description' => 'Price Set Region Code.'}],options[:options],@api_client,{}, options[:no_prompt])['regionCode']

      # cloud
      if options[:cloud]
        cloud = find_cloud(options[:cloud])

        if cloud.nil?
          print_red_alert "Cloud #{options[:cloud]} not found"
          exit 1
        end
        params['zone'] = {'id' => cloud['id']}
      else
        cloud_id = Morpheus::Cli::OptionTypes.prompt(['fieldName' => 'zone', 'type' => 'select', 'fieldLabel' => 'Cloud', 'required' => false, 'description' => 'Select cloud for price set', 'selectOptions' => @clouds_interface.list['zones'].collect {|it| {'name' => it['name'], 'value' => it['id']}}], options[:options], @api_client, {}, options[:no_prompt], true)['zone']

        if cloud_id
          params['zone'] = {'id' => cloud_id}
        end
      end

      # resource pool
      if options[:resourcePool]
        resource_pool = find_resource_pool(params['zone'].nil? ? nil : params['zone']['id'], options[:resourcePool])

        if resource_pool.nil?
          print_red_alert "Resource pool #{options[:resourcePool]} not found"
          exit 1
        end
        params['zonePool'] = {'id' => resource_pool['id']}
      else
        resource_pool_id = Morpheus::Cli::OptionTypes.prompt(['fieldName' => 'zonePool', 'type' => 'select', 'fieldLabel' => 'Resource Pool', 'required' => false, 'description' => 'Select resource pool for price set', 'selectOptions' => @cloud_resource_pools_interface.list(params['zone'] ? params['zone']['id'] : nil)['resourcePools'].collect {|it| {'name' => it['name'], 'value' => it['id']}}], options[:options], @api_client, {}, options[:no_prompt], true)['zonePool']

        if resource_pool_id
          params['zonePool'] = {'id' => resource_pool_id}
        end
      end

      # price unit
      params['priceUnit'] ||= Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'priceUnit', 'type' => 'select', 'fieldLabel' => 'Price Unit', 'selectOptions' => price_units.collect {|it| {'name' => it.split(' ').collect {|it| it.capitalize}.join(' '), 'value' => it}}, 'required' => true, 'description' => 'Price Unit.', 'defaultValue' => 'month'}],options[:options],@api_client,{}, options[:no_prompt])['priceUnit']
      if params['priceUnit'].nil?
        print_red_alert "Price unit is required"
        exit 1
      end

      # type
      price_set_type_options = price_set_types.collect {|k,v| {'name' => v[:label], 'value' => k} }
      params['type'] ||= Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'type', 'type' => 'select', 'fieldLabel' => 'Price Set Type', 'selectOptions' => price_set_type_options, 'required' => true, 'description' => 'Price Set Type.'}],options[:options],@api_client,{}, options[:no_prompt])['type']
      
      if params['type'].nil?
        print_red_alert "Type is required"
        exit 1
      end

      # required prices
      price_set_type = price_set_types[params['type']]
      prices = params['prices'] ? @prices_interface.list({'ids' => params['prices'].collect {|it| it['id']}})['prices'] : []
      required = price_set_type[:requires].reject {|it| prices.find {|price| price['priceType'] == it}}

      if !options[:no_prompt]
        params['prices'] ||= []
        while required.count > 0 do
          price_type = required.pop
          avail_prices = @prices_interface.list({'priceType' => price_type, 'priceUnit' => params['priceUnit'], 'max' => 10000})['prices'].reject {|it| params['prices'].find {|price| price['id'] == it['id']}}.collect {|it| {'name' => it['name'], 'value' => it['id']}}

          if avail_prices.count > 0
            price_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'price', 'type' => 'select', 'fieldLabel' => "Add #{price_type_label(price_type)} Price", 'selectOptions' => avail_prices, 'required' => true, 'description' => "'#{price_set_type[:label]}' price sets require 1 or more '#{price_type_label(price_type)}' price types"}],options[:options],@api_client,{}, options[:no_prompt], true)['price']
            params['prices'] << {'id' => price_id}
          else
            print_red_alert "'#{price_set_type[:label]}' price sets require 1 or more '#{price_type_label(price_type)}' price types, however there are none available for the #{params['priceUnit']} price unit."
            exit 1
          end
        end

        # additional prices
        avail_price_types = (price_set_type[:requires] + price_set_type[:allows]).collect {|it| {'name' => price_type_label(it), 'value' => it}}
        price_type = nil
        while Morpheus::Cli::OptionTypes.confirm("Add additional prices?", {default:false}) do
          price_type = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'priceType', 'type' => 'select', 'fieldLabel' => "Price Type", 'selectOptions' => avail_price_types, 'required' => true, 'defaultValue' => price_type, 'description' => "Select Price Type"}],options[:options],@api_client,{}, options[:no_prompt], true)['priceType']
          avail_prices = @prices_interface.list({'priceType' => price_type, 'priceUnit' => params['priceUnit'], 'max' => 10000})['prices'].reject {|it| params['prices'].find {|price| price['id'] == it['id']}}.collect {|it| {'name' => it['name'], 'value' => it['id']}}

          if avail_prices.count > 0
            price_id = Morpheus::Cli::OptionTypes.prompt([{'fieldName' => 'price', 'type' => 'select', 'fieldLabel' => "Add #{price_type_label(price_type)} Price", 'selectOptions' => avail_prices, 'required' => true, 'description' => "Add #{price_type_label(price_type)} Price"}],options[:options],@api_client,{}, options[:no_prompt], true)['price']
            params['prices'] << {'id' => price_id}
          else
            print_red_alert "No available prices for '#{price_type}'"
          end
        end
      end
      payload = {'priceSet' => params}
    end

    @price_sets_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @price_sets_interface.dry.create(payload)
      return
    end
    json_response = @price_sets_interface.create(payload)

    if options[:json]
      puts as_json(json_response, options)
    elsif !options[:quiet]
      if json_response['success']
        print_green_success  "Price set created"
        _get(json_response['id'], options)
      else
        print_red_alert "Error creating price set: #{json_response['msg'] || json_response['errors']}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#connect(opts) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/morpheus/cli/commands/price_sets_command.rb', line 15

def connect(opts)
  @api_client = establish_remote_appliance_connection(opts)
  @options_interface = @api_client.options
  @accounts_interface = @api_client.accounts
  @price_sets_interface = @api_client.price_sets
  @prices_interface = @api_client.prices
  @clouds_interface = @api_client.clouds
  @cloud_resource_pools_interface = @api_client.cloud_resource_pools
end

#deactivate(args) ⇒ Object



412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
# File 'lib/morpheus/cli/commands/price_sets_command.rb', line 412

def deactivate(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage( "[price-set]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = "Deactivate price set.\n" +
        "[price-set] is required. Price set ID, name or code"
  end
  optparse.parse!(args)
  connect(options)
  if args.count != 1
    raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args}\n#{optparse}"
    return 1
  end

  begin
    price_set = find_price_set(args[0])

    if !price_set
      print_red_alert "Price set #{args[0]} not found"
      exit 1
    end

    if price_set['active'] == false
      print_green_success "Price set #{price_set['name']} already deactived."
      return 0
    end

    unless options[:yes] || ::Morpheus::Cli::OptionTypes::confirm("Are you sure you would like to deactivate the price set '#{price_set['name']}'?", options)
      return 9, "aborted command"
    end

    @price_sets_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @price_sets_interface.dry.deactivate(price_set['id'], params)
      return
    end

    json_response = @price_sets_interface.deactivate(price_set['id'], params)

    if options[:json]
      print JSON.pretty_generate(json_response)
      print "\n"
    elsif !options[:quiet]
      print_green_success "Price set #{price_set['name']} deactivate"
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end

#get(args) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/morpheus/cli/commands/price_sets_command.rb', line 88

def get(args)
  options = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[price-set]")
    build_common_options(opts, options, [:json, :dry_run, :remote])
    opts.footer = "Get details about a price set.\n" +
        "[price-set] is required. Price set ID, name or code"
  end
  optparse.parse!(args)
  if args.count != 1
    raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args}\n#{optparse}"
  end
  connect(options)
  return _get(args[0], options)
end

#handle(args) ⇒ Object



25
26
27
# File 'lib/morpheus/cli/commands/price_sets_command.rb', line 25

def handle(args)
  handle_subcommand(args)
end

#list(args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/morpheus/cli/commands/price_sets_command.rb', line 29

def list(args)
  options = {}
  params = {'includeZones': true}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage()
    opts.on('-t', '--type TYPE', String, "Filter by type") do |val|
      add_query_parameter(params, 'type', parse_array(val).collect {|it| get_price_set_type_code(it) })
    end
    opts.on('-i', '--include-inactive [on|off]', String, "Can be used to enable / disable inactive filter. Default is on") do |val|
      params['includeInactive'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
    end
    build_common_options(opts, options, [:list, :query, :json, :yaml, :csv, :fields, :dry_run, :remote])
    opts.footer = "List price sets."
  end
  optparse.parse!(args)
  connect(options)
  params.merge!(parse_list_options(options))
  params['phrase'] = args.join(' ') if args.count > 0 && params['phrase'].nil? # pass args as phrase, every list command should do this
  @price_sets_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @price_sets_interface.dry.list(params)
    return
  end
  json_response = @price_sets_interface.list(params)
  price_sets = json_response['priceSets']
  render_response(json_response, options, 'priceSets') do
    title = "Morpheus Price Sets"
    subtitles = []
    subtitles += parse_list_subtitles(options)
    print_h1 title, subtitles
    if price_sets.empty?
      print cyan,"No price sets found.",reset,"\n"
    else
      rows = price_sets.collect do |it|
        {
            id: (it['active'] ? cyan : yellow) + it['id'].to_s,
            name: it['name'],
            active: format_boolean(it['active']),
            priceUnit: it['priceUnit'],
            type: price_set_type_label(it['type']),
            price_count: it['prices'].count.to_s + cyan
        }
      end
      columns = [
          :id, :name, :active, :priceUnit, :type, '# OF PRICES' => :price_count
      ]
      columns.delete(:active) if !params['includeInactive']
      print as_pretty_table(rows, columns, options)
      print_results_pagination(json_response)
    end
    print reset,"\n"
  end
  if price_sets.empty?
    return 1,  "0 price sets found"
  else
    return 0, nil
  end
end

#update(args) ⇒ Object



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/morpheus/cli/commands/price_sets_command.rb', line 344

def update(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do |opts|
    opts.banner = subcommand_usage("[price-set]")
    opts.on("--name NAME", String, "Price set name") do |val|
      params['name'] = val.to_s
    end
    opts.on('--restart-usage [on|off]', String, "Apply price changes to usage. Default is on") do |val|
      params['restartUsage'] = val.to_s == 'on' || val.to_s == 'true' || val.to_s == '1' || val.to_s == ''
    end
    opts.on('--prices [LIST]', Array, 'Price(s), comma separated list of price IDs') do |list|
      params['prices'] = list.collect {|it| it.to_s.strip.empty? || !it.to_i ? nil : it.to_s.strip}.compact.uniq.collect {|it| {'id' => it.to_i}}
    end
    build_common_options(opts, options, [:options, :payload, :json, :dry_run, :remote, :quiet])
    opts.footer = "Update price set.\n" +
        "[price-set] is required. Price set ID, name or code"
  end
  optparse.parse!(args)
  connect(options)
  if args.count != 1
    raise_command_error "wrong number of arguments, expected 1 and got (#{args.count}) #{args}\n#{optparse}"
    return 1
  end

  begin
    price_set = find_price_set(args[0])

    if price_set.nil?
      print_red_alert "Price set #{args[0]} not found"
      exit 1
    end

    payload = parse_payload(options)

    if payload.nil?
      payload = {'priceSet' => params}
    end

    if payload['priceSet'].empty?
      print_green_success "Nothing to update"
      return
    end

    @price_sets_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @price_sets_interface.dry.update(price_set['id'], payload)
      return
    end
    json_response = @price_sets_interface.update(price_set['id'], payload)

    if options[:json]
      puts as_json(json_response, options)
    elsif !options[:quiet]
      if json_response['success']
        print_green_success  "Price set updated"
        _get(price_set['id'], options)
      else
        print_red_alert "Error updating price set: #{json_response['msg'] || json_response['errors']}"
      end
    end
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end