Class: ElementCmd

Inherits:
Object
  • Object
show all
Includes:
MrMurano::Verbose
Defined in:
lib/MrMurano/commands/element.rb

Overview

NOTE: For details on the BizAPI Exchange Element API, see:

https://docs.google.com/document/d/1VlFmkiNcBK9AX6BpgV-E_5EDGgt0K_L5exJcgv6gEDQ/edit#heading=h.l6fiheqnpa08

Constant Summary collapse

NOT_A_BAD_ORDER_ELEMENT_KEYS =

*** element-show command

i[
  bizid
  elementId
  name
  tags
  type
  contact
  source
  specs
  description
  markdown
  image
  attachment

  approval
  active
  managed
  pinned
  access
  tiers
].freeze
EXCHANGE_ELEMENT_FIELD_DESC =

*** element-edit command

{
  # Not editable: bizid
  # Not editable: elementId
  name: ['elem-name', 'Element name'],
  # MAYBE/2018-04-26: (lb): Web UI does not reveal tags. Should the CLI?
  tags: ['', 'Element tags'], # ["...",...]
  contact: ['', 'Element contact information'],
  specs: [
    '',
    (
      "Included Capabilities\n\n" \
      'List exchange element compatibilities, ' \
      'versions, and or other technically relevant aspects'
    ),
  ],
  description: ['', 'Short description'],
  markdown: ['', 'Fill item description'],
  # Dynamic options (use -e ...):
  #   source.{from|name|url}
  # Uneditable strings:
  #   type = [download|service|product|application|contactSales}
  #   tiers = [free|developer|professional|enterprise]
  #   access = [public|...]
  #   approval = [approved|...]
  # Uneditable booleans:
  #   active
  #   pinned
  #   managed
  #   publishToBusinessNetwork
  # Not yet/Not going to be supported options:
  #   image.detail.{color|filename|type|url}
  #   image.thumbnail.{color|filename|type|url}
}.freeze
EXCHANGE_ELEMENT_NOT_ALLOWED =
i[
  tiers
  approval
].freeze

Constants included from MrMurano::Verbose

MrMurano::Verbose::TABULARIZE_DATA_FORMAT_ERROR

Instance Method Summary collapse

Methods included from MrMurano::Verbose

ask_yes_no, #ask_yes_no, #assert, assert, cmd_confirm_delete!, #cmd_confirm_delete!, debug, #debug, dump_file_json, dump_file_plain, dump_file_yaml, #dump_output_file, #error, error, #error_file_format!, #fancy_ticks, fancy_ticks, #load_file_json, #load_file_plain, #load_file_yaml, #load_input_file, outf, #outf, pluralize?, #pluralize?, #prepare_hash_csv, #tabularize, tabularize, verbose, #verbose, warning, #warning, whirly_interject, #whirly_interject, #whirly_linger, whirly_linger, whirly_msg, #whirly_msg, #whirly_pause, whirly_pause, whirly_start, #whirly_start, #whirly_stop, whirly_stop, #whirly_unpause, whirly_unpause

Constructor Details

#initializeElementCmd

Returns a new instance of ElementCmd.



30
31
32
# File 'lib/MrMurano/commands/element.rb', line 30

def initialize
  reset_state
end

Instance Method Details

#cmd_edit_execute(cmd, args, options) ⇒ Object



306
307
308
309
310
311
312
313
314
315
# File 'lib/MrMurano/commands/element.rb', line 306

def cmd_edit_execute(cmd, args, options)
  verify_args_id_or_name!(cmd, args, options, max_args: 2)
  file_must_find_maybe(args[1])
  options_must_specify_edits!
  edit_fields_load_input_files
  sole_elem = elems_must_find_one!(args, options)
  update_elem_fields(sole_elem)
  xchg = MrMurano::Exchange.new
  xchg.put(sole_elem.elementId, @updated_obj)
end

#cmd_options_add_exchange_element_fields(cmd) ⇒ Object



317
318
319
320
# File 'lib/MrMurano/commands/element.rb', line 317

def cmd_options_add_exchange_element_fields(cmd)
  cmd_options_add_fields_static(cmd)
  cmd_options_add_fields_dynamic(cmd)
end

#cmd_options_add_fields_dynamic(cmd) ⇒ Object



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/MrMurano/commands/element.rb', line 341

def cmd_options_add_fields_dynamic(cmd)
  cmd.option(
    '-e', '--edit [KEY[=VALUE]]', %(Set the Element field named KEY to VALUE)
  ) do |param|
    if param.nil?
      # param.nil? means user did not supply key[=val].
      @open_fields.push('')
    else
      # Otherwise: a=b :> ['a', 'b'] / a=  :> ['a', ''] / a   :> ['a', nil]
      key, value = param.split('=', 2)
      if value.nil?
        if param =~ /(?<!-)-$/
          @drop_fields.push(key.chomp('-'))
        else
          @open_fields.push(key)
        end
      else
        @edit_fields[key] = value
      end
    end
  end
end

#cmd_options_add_fields_static(cmd) ⇒ Object



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/MrMurano/commands/element.rb', line 322

def cmd_options_add_fields_static(cmd)
  # Add --options from EXCHANGE_ELEMENT_FIELD_DESC but sort them.
  NOT_A_BAD_ORDER_ELEMENT_KEYS.each do |field|
    field_desc = EXCHANGE_ELEMENT_FIELD_DESC[field]
    next if field_desc.nil?
    switch = !field_desc[0].empty? && field_desc[0] || field.to_s
    detail = !field_desc[1].empty? && field_desc[1] || field.to_s
    cmd.option(
      "--#{switch} [VALUE]", detail
    ) do |param|
      if param.nil?
        @open_fields.push(key)
      else
        @edit_fields[field.to_s] = param
      end
    end
  end
end

#cmd_options_add_outformat_plain(cmd) ⇒ Object



364
365
366
367
368
369
370
371
# File 'lib/MrMurano/commands/element.rb', line 364

def cmd_options_add_outformat_plain(cmd)
  cmd.option(
    '--plain',
    'Do not decode input file(s) (e.g., if named specs.yaml, import as plaintext)'
  ) do
    $cfg['tool.outformat'] = 'text'
  end
end

#cmd_options_pretty_format_option(cmd) ⇒ Object



153
154
155
# File 'lib/MrMurano/commands/element.rb', line 153

def cmd_options_pretty_format_option(cmd)
  cmd.option('-p', '--pretty', %(Whether to pretty-print --json))
end

#command_element_edit(cmd) ⇒ Object



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
# File 'lib/MrMurano/commands/element.rb', line 265

def command_element_edit(cmd)
  cmd.syntax = %(murano element edit [--options] <name-or-ID> [file])
  cmd.summary = %(Edit details about an IoT Marketplace Exchange Element)
  cmd.description = %(
    Edit details about an IoT Marketplace Exchange Element.
  ).strip
  # We don't need to be in a project directory; we just need the Biz ID.
  cmd.project_not_required = true

  # Add --id and --name options.
  cmd_options_add_id_and_name(cmd)

  cmd_options_add_exchange_element_fields(cmd)

  cmd_options_add_outformat_plain(cmd)

  cmd.example %(Upload Exchange Element record from JSON stored in local file
), %(murano element edit 'remote condition monitoring' rcm.json)

  cmd.example %(Edit single field of Exchange Element record
), %(murano element edit 'my element' -e image.thumbnail.color=#5C5D60)

  cmd.example %(Edit single sub dictionary of Exchange Element record using Yaml file
), %(murano element edit -e source -- 'my element' element-source.yaml)

  cmd.example %(Edit single sub dictionary of Exchange Element record using JSON file
), %(murano element edit -e [email protected] 'my element')

  cmd.example %(Edit Exchange Element fields using your ${EDITOR}
), %(murano element edit -e -- <Element_ID_or_Name>)

  cmd.action do |args, options|
    begin
      cmd_edit_execute(cmd, args, options)
    ensure
      # This is for RSpec, so the command instance resets itself between runs.
      reset_state
    end
  end
end

#command_element_help(cmd) ⇒ Object

*** element-help command



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/MrMurano/commands/element.rb', line 45

def command_element_help(cmd)
  cmd.syntax = %(murano element)
  cmd.summary = %(IoT Marketplace Exchange Element commands)
  cmd.description = %(
    Commands for working with IoT Marketplace Exchange Elements.
  ).strip
  cmd.project_not_required = true
  cmd.subcmdgrouphelp = true

  cmd.action do |_args, _options|
    ::Commander::UI.enable_paging unless $cfg['tool.no-page']
    say MrMurano::SubCmdGroupHelp.new(cmd).get_help
    reset_state
  end
end

#command_element_show(cmd) ⇒ Object



103
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
# File 'lib/MrMurano/commands/element.rb', line 103

def command_element_show(cmd)
  cmd.syntax = %(murano element show [--options] <name-or-ID>)
  cmd.summary = %(Show details about an IoT Marketplace Exchange Element)
  cmd.description = %(
    Show details about an IoT Marketplace Exchange Element.
  ).strip
  # We don't need to be in a project directory; we just need the Biz ID.
  cmd.project_not_required = true

  # Not too DRY: See also cmd_table_output_add_options(cmd), which also
  # adds --idonly and --[no-]brief.
  cmd.option '-o', '--output FILE', 'Download to file instead of STDOUT'

  cmd.option '--[no-]truncate', 'Truncate longs lines...'
  cmd.option '--[no-]wrap', 'Wrap long lines...'

  cmd.example %(Show table of Exchange Element fields, wrapped nicely to fit terminal
), %(murano element show abcdef1234567890abcdef1234567890abcdef12 --wrap)

  cmd.example %(Store Exchange Element record as JSON in local file
), %(murano element show 'remote condition monitoring' --json > rcm.json)

  # Add --id and --name options.
  cmd_options_add_id_and_name(cmd)

  cmd_options_pretty_format_option(cmd)

  cmd.action do |args, options|
    verify_args_id_or_name!(cmd, args, options)
    sole_elem = elems_must_find_one!(args, options)

    orig_elem, flatkeys, val_lkup = objectify_elem(sole_elem, options)

    io = File.open(options.output, 'w') if options.output
    outf(orig_elem, io, pretty: options.pretty) do |elem, ios|
      if $cfg['tool.outformat'] =~ /csv/i
        headers, row_lkup = prepare_hash_csv(elem)
      else
        # Outformat is table. Make tall, not wide.
        headers = %w[key value]
        # Sort by top-level keys first, i.e., group objects, at least.
        flatkeys = sort_key_hier(flatkeys, elem.keys)
        row_lkup = Hash[flatkeys.collect { |key| [key, val_lkup[key]] }]
      end
      tabularize({ headers: headers, rows: row_lkup }, ios)
    end
    reset_state
  end
end

#consume_edited_tmp_file(tmpf, fmt) ⇒ Object



502
503
504
505
506
507
# File 'lib/MrMurano/commands/element.rb', line 502

def consume_edited_tmp_file(tmpf, fmt)
  tmpf.open
  edit_val = load_input_file(tmpf, fmt)
  tmpf.unlink
  edit_val
end

#edit_fields_load_input_filesObject



418
419
420
421
# File 'lib/MrMurano/commands/element.rb', line 418

def edit_fields_load_input_files
  set_fields_from_files_from_options
  set_field_from_file_from_positional
end

#elems_must_find_one!(args, options) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/MrMurano/commands/element.rb', line 66

def elems_must_find_one!(args, options)
  xchg = MrMurano::Exchange.new
  xchg.must_business_id!

  exchange_cmd = ExchangeCmd.new

  elems, _available, _purchased = exchange_cmd.find_elements(
    xchg, options, args[0], skip_purchased: true,
  )

  exchange_cmd.elems_must_found_one!(elems, xchg)
end

#file_must_find_maybe(path) ⇒ Object



373
374
375
376
377
378
379
# File 'lib/MrMurano/commands/element.rb', line 373

def file_must_find_maybe(path)
  return if path.nil?
  @input_path = Pathname.new(path) unless path.is_a?(Pathname)
  return if @input_path.exist?
  error %(Input file not found: #{@input_path})
  exit 1
end

#load_input_maybe(field_value) ⇒ Object



588
589
590
591
592
593
594
# File 'lib/MrMurano/commands/element.rb', line 588

def load_input_maybe(field_value)
  return field_value.gsub(/^@@/, '@') unless value_specifies_file_input?(field_value)
  # If the -e field=value starts with '@', e.g., [email protected],
  # try to load the field value from the file.
  path = Pathname.new(field_value.slice(1..-1))
  read_hashf!(path)
end

#obj_must_be_hash!(obj) ⇒ Object



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'lib/MrMurano/commands/element.rb', line 537

def obj_must_be_hash!(obj)
  if obj.is_a? Hash
    obj
  elsif obj.empty?
    {}
  else
    begin
      parsed = JSON.parse(obj)
    rescue JSON::ParserError => err
      error %(The document object is not a Hash: #{obj})
      error err.to_s
      exit 2
    end
    return parsed if parsed.is_a? Hash
  end
end

#objectify_elem(elem, options) ⇒ Object



157
158
159
160
161
162
163
# File 'lib/MrMurano/commands/element.rb', line 157

def objectify_elem(elem, options)
  lkup = objectify_elem_lkup(elem)
  flatkeys = objectify_elem_flat(lkup)
  width_avail = objectify_elem_width(flatkeys, options)
  val_lkup = objectify_elem_values(flatkeys, lkup, width_avail, options)
  [lkup, flatkeys, val_lkup]
end

#objectify_elem_flat(lkup) ⇒ Object



174
175
176
177
# File 'lib/MrMurano/commands/element.rb', line 174

def objectify_elem_flat(lkup)
  flatkeys = Hash.flat_hash(lkup).keys.map { |hier| hier.join('.') }
  flatkeys.sort
end

#objectify_elem_lkup(elem) ⇒ Object



165
166
167
168
169
170
171
172
# File 'lib/MrMurano/commands/element.rb', line 165

def objectify_elem_lkup(elem)
  lkup = HashDiggable.new(elem.meta)
  lkup.default_proc = proc do |hash, key|
    warning %(Not a symbol!: #{key}) unless key.is_a? Symbol
    hash[key] = Hash.new(&hash.default_proc)
  end
  lkup
end

#objectify_elem_values(flatkeys, lkup, width_avail, options) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/MrMurano/commands/element.rb', line 197

def objectify_elem_values(flatkeys, lkup, width_avail, options)
  val_lkup = {}
  flatkeys.each do |key|
    layers = key.split('.').map(&:to_sym)
    val = lkup.dig(*layers).to_s
    if width_avail > 0
      if options.truncate
        val.slice!(width_avail..-1)
      elsif options.wrap
        val = MrMurano::Pretties.split_text_on_whitespace(val, width_avail)
      end
    end
    # Store the flattened key-value if a flat lookup, for the table maker.
    val_lkup[key] = val
  end
  val_lkup
end

#objectify_elem_width(flatkeys, options) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/MrMurano/commands/element.rb', line 179

def objectify_elem_width(flatkeys, options)
  # This is similar to Pretties.width_last_column
  width_avail = -1
  if options.truncate || options.wrap
    width_taken = 0
    # Account for the left and right borders.
    # rubocop:disable Performance/FixedSize
    width_taken += 2 * ('| '.length)
    # And account for the middle column split.
    width_taken += ' | '.length
    width_taken += flatkeys.max_by(&:length).length
    term_width = MrMurano::Pretties::TERM_WIDTH
    term_width = 80 unless term_width != 0
    width_avail = term_width - width_taken
  end
  width_avail
end

#options_edits_count(n_kvals) ⇒ Object



387
388
389
390
391
392
# File 'lib/MrMurano/commands/element.rb', line 387

def options_edits_count(n_kvals)
  @edit_fields.each do |_key, val|
    n_kvals[:n_keys] += 1
    n_kvals[:n_vals] += 1 unless val.nil?
  end
end

#options_edits_verify!(n_kvals) ⇒ Object



394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/MrMurano/commands/element.rb', line 394

def options_edits_verify!(n_kvals)
  if @input_path.nil?
    # See if all values are specified, or if we should bring up the EDITOR.
    if n_kvals[:n_keys] > 1
      if (n_kvals[:n_keys] + 1) < n_kvals[:n_vals]
        # EDITOR path, i.e., one key specified without a value.
        error %(
          Please specify at most one field without a value.
        ).strip
        exit 2
      end
    elsif n_kvals[:n_keys] == 0 && @open_fields.empty?
      error('Please specify one or more -e/--edit options, or an input file.')
      exit 2
    end
  elsif n_kvals[:n_keys] > 1
    error('Please specify at most a single field when specifing an input file.')
    exit 2
  elsif n_kvals[:n_vals] > 0
    error('Please do not specify a value when specifing an input file.')
    exit 2
  end
end

#options_must_specify_edits!Object



381
382
383
384
385
# File 'lib/MrMurano/commands/element.rb', line 381

def options_must_specify_edits!
  n_kvals = { n_keys: 0, n_vals: 0 }
  options_edits_count(n_kvals)
  options_edits_verify!(n_kvals)
end

#outformat_engine(fext, hash_val = nil) ⇒ Object



488
489
490
491
492
493
494
495
496
# File 'lib/MrMurano/commands/element.rb', line 488

def outformat_engine(fext, hash_val=nil)
  if !fext.nil?
    super(fext)
  elsif hash_val.is_a? Hash
    super($cfg['tool.outformat'])
  else
    :plain
  end
end

#prepare_field_keys_and_valueObject



468
469
470
471
472
473
474
475
476
477
478
# File 'lib/MrMurano/commands/element.rb', line 468

def prepare_field_keys_and_value
  field = @open_fields[0]
  keys = []
  keys = field.split('.').map(&:to_sym) unless field.to_s.empty?
  if !keys.nil? && !keys.empty?
    hash_val = @updated_obj.dig_safe(*keys)
  else
    hash_val = @updated_obj
  end
  [keys, hash_val]
end

#read_hashf!(path, fmt = nil) ⇒ Object



596
597
598
599
# File 'lib/MrMurano/commands/element.rb', line 596

def read_hashf!(path, fmt=nil)
  fmt = :plain if fmt.nil? && ($cfg['tool.outformat'] == 'text')
  @input_data = super(path, fmt)
end

#reset_stateObject



34
35
36
37
38
39
40
41
# File 'lib/MrMurano/commands/element.rb', line 34

def reset_state
  @drop_fields = []
  @edit_fields = {}
  @open_fields = []
  @updated_obj = {}
  @input_path = nil
  @input_data = nil
end

#set_field_from_file_from_positionalObject



430
431
432
433
434
# File 'lib/MrMurano/commands/element.rb', line 430

def set_field_from_file_from_positional
  return if @input_path.nil?
  @input_data = read_hashf!(@input_path)
  @input_data.deep_symbolize_keys! if @input_data.is_a? Hash
end

#set_fields_from_files_from_optionsObject



423
424
425
426
427
428
# File 'lib/MrMurano/commands/element.rb', line 423

def set_fields_from_files_from_options
  @edit_fields.update(@edit_fields) do |_key, value, _other|
    next value unless value_specifies_file_input?(value)
    load_input_maybe(value)
  end
end

#sort_key_hier(flattened_keys, top_level_keys) ⇒ Object



215
216
217
218
219
220
221
222
# File 'lib/MrMurano/commands/element.rb', line 215

def sort_key_hier(flattened_keys, top_level_keys)
  sort_order = (NOT_A_BAD_ORDER_ELEMENT_KEYS + top_level_keys.sort).map(&:to_s).uniq
  flattened_keys.sort_by do |key|
    sort_order.index do |top|
      key.downcase.start_with?(top.downcase)
    end
  end
end

#update_elem_fields(elem) ⇒ Object



436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/MrMurano/commands/element.rb', line 436

def update_elem_fields(elem)
  @updated_obj = HashDiggable.new(elem.meta)
  n_edits = 0
  # When @edit_fields == { '' => '' }, BizAPI replies:
  #   Request Failed: 400: [400] child "type" fails because ["type" is required]
  if !@open_fields.empty?
    if (@open_fields.length > 1) && $cfg['tool.developer']
      warning %(Unexpected: more than one open field specified)
    end
    n_edits += update_elem_fields_from_editor
  else
    # Verify that at least one option value differs from what's currently set.
    n_edits += update_elem_fields_from_options
    n_edits += update_elem_fields_from_input_f
  end
  n_edits += update_elem_fields_drop_fields
  if n_edits.zero?
    warning('No new field values specified to update.')
    exit 0
  end
  @updated_obj.reject! { |key, _val| EXCHANGE_ELEMENT_NOT_ALLOWED.include?(key) }
end

#update_elem_fields_drop_fieldsObject



574
575
576
577
578
579
580
581
582
# File 'lib/MrMurano/commands/element.rb', line 574

def update_elem_fields_drop_fields
  n_edits = 0
  @drop_fields.each do |field|
    keys = field.split('.').map(&:to_sym)
    @updated_obj.deep_delete(*keys)
    n_edits += 1
  end
  n_edits
end

#update_elem_fields_from_editorObject



459
460
461
462
463
464
465
466
# File 'lib/MrMurano/commands/element.rb', line 459

def update_elem_fields_from_editor
  keys, hash_val = prepare_field_keys_and_value
  tmpf, fmt = write_editable_tmp_file(hash_val)
  user_editor_interact(tmpf)
  edit_val = consume_edited_tmp_file(tmpf, fmt)
  edit_val.deep_symbolize_keys! if edit_val.is_a? Hash
  update_field_maybe!(keys, edit_val, hash_val)
end

#update_elem_fields_from_input_fObject



554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
# File 'lib/MrMurano/commands/element.rb', line 554

def update_elem_fields_from_input_f
  n_edits = 0
  return n_edits if @input_path.nil?
  if (@open_fields.length > 1) && $cfg['tool.developer']
    warning %(Unexpected: more than one open field specified)
  end
  keys = @open_fields[0].split('.').map(&:to_sym) unless @open_fields.empty?
  if !keys.nil? && !keys.empty?
    old_val = @updated_obj.dig_safe(*keys)
    if old_val != @input_data
      @updated_obj.fill_safe(@input_data, *keys)
      n_edits += 1
    end
  elsif @updated_obj != @input_data
    @updated_obj = @input_data
    n_edits += 1
  end
  n_edits
end

#update_elem_fields_from_optionsObject



522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/MrMurano/commands/element.rb', line 522

def update_elem_fields_from_options
  n_edits = 0
  @edit_fields.each_pair do |key, value|
    next if value.nil?
    keys = key.split('.').map(&:to_sym) unless key.nil?
    if !keys.nil? && !keys.empty?
      old_val = @updated_obj.dig_safe(*keys)
    else
      old_val = @updated_obj
    end
    n_edits += update_field_maybe!(keys, value, old_val)
  end
  n_edits
end

#update_field_maybe!(keys, edit_val, hash_val) ⇒ Object



509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/MrMurano/commands/element.rb', line 509

def update_field_maybe!(keys, edit_val, hash_val)
  n_edits = 0
  if edit_val != hash_val
    if !keys.nil? && !keys.empty?
      @updated_obj.fill_safe(edit_val, *keys)
    else
      @updated_obj = obj_must_be_hash!(edit_val)
    end
    n_edits += 1
  end
  n_edits
end

#user_editor_interact(tmpf) ⇒ Object



498
499
500
# File 'lib/MrMurano/commands/element.rb', line 498

def user_editor_interact(tmpf)
  TTY::Editor.open(tmpf.path)
end

#value_specifies_file_input?(field_value) ⇒ Boolean

Returns:

  • (Boolean)


584
585
586
# File 'lib/MrMurano/commands/element.rb', line 584

def value_specifies_file_input?(field_value)
  field_value =~ /^@(?!@)/
end

#verify_args_id_or_name!(cmd, args, options, max_args: 1) ⇒ Object



61
62
63
64
# File 'lib/MrMurano/commands/element.rb', line 61

def verify_args_id_or_name!(cmd, args, options, max_args: 1)
  cmd.verify_arg_count!(args, max_args, ['Missing Element name or ID'])
  cmd_defaults_id_and_name(options)
end

#write_editable_tmp_file(hash_val) ⇒ Object



480
481
482
483
484
485
486
# File 'lib/MrMurano/commands/element.rb', line 480

def write_editable_tmp_file(hash_val)
  fmt = outformat_engine(nil, hash_val)
  tmpf = Tempfile.new(["murcli_#{@updated_obj[:elementId]}-", ".#{fmt}"])
  dump_output_file(hash_val, tmpf, fmt, pretty: true)
  tmpf.close
  [tmpf, fmt]
end