markdown_exec 3.0.5 → 3.0.6

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.
@@ -44,6 +44,7 @@ require_relative 'string_util'
44
44
  require_relative 'table_extractor'
45
45
  require_relative 'text_analyzer'
46
46
  require_relative 'value_or_exception'
47
+ require_relative 'env_interface'
47
48
 
48
49
  $pd = false unless defined?($pd)
49
50
  $table_cell_truncate = true
@@ -96,10 +97,6 @@ module HashDelegatorSelf
96
97
  blocks.select { |item| item.send(msg) == value }
97
98
  end
98
99
 
99
- def code_merge(*bodies)
100
- merge_lists(*bodies)
101
- end
102
-
103
100
  def count_matches_in_lines(lines, regex)
104
101
  lines.count { |line| line.to_s.match(regex) }
105
102
  end
@@ -157,6 +154,14 @@ module HashDelegatorSelf
157
154
  )
158
155
  end
159
156
 
157
+ # Takes multiple arrays as arguments, flattens them into a single array, and removes nil values.
158
+ # @param args [Array<Array>] Variable number of arrays to be processed
159
+ # @return [Array] A single flattened array with nil values removed, or an empty array if the result is empty
160
+ def flatten_and_compact_arrays(*args)
161
+ merged = args.compact.flatten
162
+ merged.empty? ? [] : merged
163
+ end
164
+
160
165
  # Indents all lines in a given string with a specified indentation string.
161
166
  # @param body [String] A multi-line string to be indented.
162
167
  # @param indent [String] The string used for indentation
@@ -177,13 +182,6 @@ module HashDelegatorSelf
177
182
  ((lines || []) + ['']).join("\n")
178
183
  end
179
184
 
180
- def merge_lists(*args)
181
- # Filters out nil values, flattens the arrays, and ensures an
182
- # empty list is returned if no valid lists are provided.
183
- merged = args.compact.flatten
184
- merged.empty? ? [] : merged
185
- end
186
-
187
185
  def next_link_state(
188
186
  block_name_from_cli:, was_using_cli:, block_state:, block_name: nil
189
187
  )
@@ -501,10 +499,6 @@ class BashCommentFormatter
501
499
  end
502
500
  formatted.join("\n")
503
501
  end
504
- # # fit oname in single bash comment
505
- # def oname_for_bash_comment(oname)
506
- # oname.gsub("\n", ' ~ ').gsub(/ +/, ' ')
507
- # end
508
502
  end
509
503
 
510
504
  class StringWrapper
@@ -1177,28 +1171,15 @@ module MarkdownExec
1177
1171
  transform_export_value(name_force[:text], export)
1178
1172
  else
1179
1173
  name_force[:text]
1174
+
1180
1175
  end
1181
- ENV[name_force[:name]] = transformed
1176
+ EnvInterface.set(name_force[:name], transformed)
1177
+
1182
1178
  code_line_safe_assign(
1183
1179
  name_force[:name], transformed, force: name_force[:force]
1184
1180
  )
1185
1181
  end
1186
1182
  required_lines.concat(command_result_w_e_t_nl.new_lines)
1187
-
1188
- if SelectResponse.continue?(command_result_w_e_t_nl.stdout)
1189
- if command_result_w_e_t_nl.transformable
1190
- command_result_w_e_t_nl.stdout = transform_export_value(
1191
- command_result_w_e_t_nl.stdout, export
1192
- )
1193
- end
1194
-
1195
- if command_result_w_e_t_nl.exportable
1196
- ENV[export.name] = command_result_w_e_t_nl.stdout.to_s
1197
- required_lines.push code_line_safe_assign(
1198
- export.name, command_result_w_e_t_nl.stdout, force: force
1199
- )
1200
- end
1201
- end
1202
1183
  ret_command_result = command_result_w_e_t_nl
1203
1184
  else
1204
1185
  raise "Invalid data type: #{data.inspect}"
@@ -1208,13 +1189,17 @@ module MarkdownExec
1208
1189
  ret_command_result || CommandResult.new(stdout: required_lines)
1209
1190
  end
1210
1191
 
1192
+ def env_set(name, value)
1193
+ EnvInterface.set(name, value)
1194
+ end
1195
+
1211
1196
  # sets ENV
1212
1197
  def code_from_vars_block_to_set_environment_variables(selected)
1213
1198
  code_lines = []
1214
1199
  case data = YAML.load(selected.body.join("\n"))
1215
1200
  when Hash
1216
1201
  data.each do |key, value|
1217
- ENV[key] = value.to_s
1202
+ EnvInterface.set(key, value.to_s)
1218
1203
  code_lines.push "#{key}=#{Shellwords.escape(value)}"
1219
1204
 
1220
1205
  next unless @delegate_object[:menu_vars_set_format].present?
@@ -1908,7 +1893,7 @@ module MarkdownExec
1908
1893
  before_mtime = temp_file.mtime
1909
1894
 
1910
1895
  # Open the temporary file in the default editor
1911
- system("#{ENV['EDITOR'] || 'vi'} #{temp_file.path}")
1896
+ system("#{EnvInterface.get('EDITOR', default: 'vi')} #{temp_file.path}")
1912
1897
 
1913
1898
  # Capture the exit status of the editor
1914
1899
  editor_exit_status = $?.exitstatus
@@ -2051,13 +2036,16 @@ module MarkdownExec
2051
2036
  next_state_append_code(
2052
2037
  selected,
2053
2038
  link_state,
2054
- command_result_w_e_t_nl.failure? ? [] : command_result_w_e_t_nl.stdout
2039
+ command_result_w_e_t_nl.failure? ? [] : command_result_w_e_t_nl.new_lines
2055
2040
  )
2056
2041
 
2057
2042
  elsif selected.type == BlockType::VARS
2058
2043
  debounce_reset
2059
- next_state_append_code(selected, link_state,
2060
- code_from_vars_block_to_set_environment_variables(selected))
2044
+ next_state_append_code(
2045
+ selected,
2046
+ link_state,
2047
+ code_from_vars_block_to_set_environment_variables(selected)
2048
+ )
2061
2049
 
2062
2050
  elsif COLLAPSIBLE_TYPES.include?(selected.type)
2063
2051
  debounce_reset
@@ -2182,7 +2170,7 @@ module MarkdownExec
2182
2170
  if link_block_data[LinkKeys::VARS]
2183
2171
  code_lines.push BashCommentFormatter.format_comment(selected.pub_name)
2184
2172
  (link_block_data[LinkKeys::VARS] || []).each do |(key, value)|
2185
- ENV[key] = value.to_s
2173
+ EnvInterface.set(key, value.to_s)
2186
2174
  code_lines.push(assign_key_value_in_bash(key, value))
2187
2175
  end
2188
2176
  end
@@ -2237,7 +2225,7 @@ module MarkdownExec
2237
2225
  ((link_state&.inherited_block_names || []) + block_names).sort.uniq,
2238
2226
  inherited_dependencies:
2239
2227
  (link_state&.inherited_dependencies || {}).merge(dependencies || {}), ### merge, not replace, key data
2240
- inherited_lines: HashDelegator.code_merge(
2228
+ inherited_lines: HashDelegator.flatten_and_compact_arrays(
2241
2229
  link_state&.inherited_lines, code_lines
2242
2230
  ),
2243
2231
  keep_code: link_state&.keep_code,
@@ -2345,15 +2333,15 @@ module MarkdownExec
2345
2333
 
2346
2334
  if selected[:type] == BlockType::OPTS
2347
2335
  # body of blocks is returned as a list of lines to be read an YAML
2348
- HashDelegator.code_merge(required[:blocks].map(&:body).flatten(1))
2336
+ HashDelegator.flatten_and_compact_arrays(required[:blocks].map(&:body).flatten(1))
2349
2337
  else
2350
2338
  code_lines = if selected.type == BlockType::VARS
2351
2339
  code_from_vars_block_to_set_environment_variables(selected)
2352
2340
  else
2353
2341
  []
2354
2342
  end
2355
- HashDelegator.code_merge(link_state&.inherited_lines,
2356
- required[:code] + code_lines)
2343
+ HashDelegator.flatten_and_compact_arrays(link_state&.inherited_lines,
2344
+ required[:code] + code_lines)
2357
2345
  end
2358
2346
  end
2359
2347
 
@@ -2575,6 +2563,7 @@ module MarkdownExec
2575
2563
  link_state: link_state,
2576
2564
  pattern: options_command_substitution_regexp
2577
2565
  )
2566
+ # no return
2578
2567
  end
2579
2568
 
2580
2569
  def expand_variable_references!(
@@ -2604,31 +2593,37 @@ module MarkdownExec
2604
2593
  return if replacements == EvaluateShellExpression::StatusFail
2605
2594
 
2606
2595
  expand_blocks_with_replacements(blocks, replacements)
2596
+ # no return
2607
2597
  end
2608
2598
 
2609
2599
  def export_echo_with_code(
2610
- bash_script_lines, export, force:, silent:
2600
+ bash_script_lines, export, force:, silent:, string: nil
2611
2601
  )
2612
2602
  exportable = true
2613
2603
  command_result = nil
2614
2604
  new_lines = []
2615
- case export.echo
2605
+ export_string = string || export.echo
2606
+ case export_string
2616
2607
  when String, Integer, Float, TrueClass, FalseClass
2617
- command_result = output_from_adhoc_bash_script_file(
2608
+ command_result, = output_from_adhoc_bash_script_file(
2618
2609
  join_array_of_arrays(
2619
2610
  bash_script_lines,
2620
- %(printf '%s' "#{export.echo}")
2611
+ %(printf '%s' "#{export_string}")
2621
2612
  )
2622
2613
  )
2623
2614
  if command_result.exit_status == EXIT_STATUS_REQUIRED_EMPTY
2624
2615
  exportable = false
2625
2616
  command_result.warning = warning_required_empty(export) unless silent
2617
+ else
2618
+ EnvInterface.set(export.name, command_result.stdout.to_s)
2619
+ new_lines << { name: export.name, force: force,
2620
+ text: command_result.stdout }
2626
2621
  end
2627
2622
 
2628
2623
  when Hash
2629
2624
  # each item in the hash is a variable name and value
2630
- export.echo.each do |name, expression|
2631
- command_result = output_from_adhoc_bash_script_file(
2625
+ export_string.each do |name, expression|
2626
+ command_result, = output_from_adhoc_bash_script_file(
2632
2627
  join_array_of_arrays(
2633
2628
  bash_script_lines,
2634
2629
  %(printf '%s' "#{expression}")
@@ -2637,14 +2632,11 @@ module MarkdownExec
2637
2632
  if command_result.exit_status == EXIT_STATUS_REQUIRED_EMPTY
2638
2633
  command_result.warning = warning_required_empty(export) unless silent
2639
2634
  else
2640
- ENV[name] = command_result.stdout.to_s
2635
+ EnvInterface.set(name, command_result.stdout.to_s)
2641
2636
  new_lines << { name: name, force: force,
2642
2637
  text: command_result.stdout }
2643
2638
  end
2644
2639
  end
2645
-
2646
- # individual items have been exported, none remain
2647
- exportable = false
2648
2640
  end
2649
2641
 
2650
2642
  [command_result, exportable, new_lines]
@@ -2755,7 +2747,7 @@ module MarkdownExec
2755
2747
  # Format expression using environment variables and run state
2756
2748
  def format_expression(expr)
2757
2749
  data = link_load_format_data
2758
- ENV.each { |key, value| data[key.to_sym] = value }
2750
+ EnvInterface.each { |key, value| data[key.to_sym] = value }
2759
2751
  format(expr, data)
2760
2752
  end
2761
2753
 
@@ -3008,8 +3000,8 @@ module MarkdownExec
3008
3000
 
3009
3001
  def link_block_data_eval(link_state, code_lines, selected, link_block_data,
3010
3002
  block_source:, shell:)
3011
- all_code = HashDelegator.code_merge(link_state&.inherited_lines,
3012
- code_lines)
3003
+ all_code = HashDelegator.flatten_and_compact_arrays(link_state&.inherited_lines,
3004
+ code_lines)
3013
3005
  output_lines = []
3014
3006
 
3015
3007
  Tempfile.open do |file|
@@ -3304,8 +3296,11 @@ module MarkdownExec
3304
3296
  [block_name_from_cli, now_using_cli]
3305
3297
  end
3306
3298
 
3307
- def mdoc_and_blocks_from_nested_files(source_id: nil)
3308
- blocks_results = blocks_from_nested_files(source_id: source_id)
3299
+ def mdoc_and_blocks_from_nested_files(source_id: nil, link_state: nil)
3300
+ blocks_results = blocks_from_nested_files(
3301
+ link_state: link_state,
3302
+ source_id: source_id
3303
+ )
3309
3304
 
3310
3305
  blocks_results.results.select do |_id, result|
3311
3306
  result.failure?
@@ -3328,7 +3323,10 @@ module MarkdownExec
3328
3323
  #
3329
3324
  reload_blocks = false
3330
3325
 
3331
- all_blocks, mdoc = mdoc_and_blocks_from_nested_files(source_id: source_id)
3326
+ all_blocks, mdoc = mdoc_and_blocks_from_nested_files(
3327
+ link_state: link_state,
3328
+ source_id: source_id
3329
+ )
3332
3330
  if load_auto_opts_block(all_blocks, mdoc: mdoc)
3333
3331
  reload_blocks = true
3334
3332
  end
@@ -3344,8 +3342,8 @@ module MarkdownExec
3344
3342
  # load document ux block
3345
3343
  #
3346
3344
  if (code_lines = code_from_automatic_ux_blocks(all_blocks, mdoc))
3347
- new_code = HashDelegator.code_merge(link_state.inherited_lines,
3348
- code_lines)
3345
+ new_code = HashDelegator.flatten_and_compact_arrays(link_state.inherited_lines,
3346
+ code_lines)
3349
3347
  next_state_set_code(nil, link_state, new_code)
3350
3348
  link_state.inherited_lines = new_code
3351
3349
  reload_blocks = true
@@ -3354,15 +3352,18 @@ module MarkdownExec
3354
3352
  # load document vars block
3355
3353
  #
3356
3354
  if (code_lines = load_auto_vars_block(all_blocks))
3357
- new_code = HashDelegator.code_merge(link_state.inherited_lines,
3358
- code_lines)
3355
+ new_code = HashDelegator.flatten_and_compact_arrays(link_state.inherited_lines,
3356
+ code_lines)
3359
3357
  next_state_set_code(nil, link_state, new_code)
3360
3358
  link_state.inherited_lines = new_code
3361
3359
  reload_blocks = true
3362
3360
  end
3363
3361
 
3364
3362
  if reload_blocks
3365
- all_blocks, mdoc = mdoc_and_blocks_from_nested_files(source_id: source_id)
3363
+ all_blocks, mdoc = mdoc_and_blocks_from_nested_files(
3364
+ link_state: link_state,
3365
+ source_id: source_id
3366
+ )
3366
3367
  end
3367
3368
 
3368
3369
  # filter by name, collapsed
@@ -3531,7 +3532,7 @@ module MarkdownExec
3531
3532
  next_state_set_code(
3532
3533
  selected,
3533
3534
  link_state,
3534
- HashDelegator.code_merge(
3535
+ HashDelegator.flatten_and_compact_arrays(
3535
3536
  link_state&.inherited_lines,
3536
3537
  code_lines.is_a?(Array) ? code_lines : [] # no code for :ux_exec_prohibited
3537
3538
  )
@@ -3548,7 +3549,7 @@ module MarkdownExec
3548
3549
  ((link_state&.inherited_block_names || []) + block_names).sort.uniq,
3549
3550
  inherited_dependencies:
3550
3551
  (link_state&.inherited_dependencies || {}).merge(dependencies || {}), ### merge, not replace, key data
3551
- inherited_lines: HashDelegator.code_merge(code_lines),
3552
+ inherited_lines: HashDelegator.flatten_and_compact_arrays(code_lines),
3552
3553
  keep_code: link_state&.keep_code,
3553
3554
  next_block_name: '',
3554
3555
  next_document_filename: @delegate_object[:filename],
@@ -3592,7 +3593,10 @@ module MarkdownExec
3592
3593
  }
3593
3594
  end
3594
3595
 
3595
- def output_from_adhoc_bash_script_file(bash_script_lines)
3596
+ def output_from_adhoc_bash_script_file(
3597
+ bash_script_lines,
3598
+ export = nil
3599
+ )
3596
3600
  Tempfile.create('script_exec') do |temp_file|
3597
3601
  temp_file.write(
3598
3602
  HashDelegator.join_code_lines(
@@ -3612,7 +3616,32 @@ module MarkdownExec
3612
3616
 
3613
3617
  output = `#{shell} #{temp_file.path}`
3614
3618
 
3615
- CommandResult.new(stdout: output, exit_status: $?.exitstatus)
3619
+ exportable = export ? export.exportable : false
3620
+ new_lines = []
3621
+ if export
3622
+ new_lines << "#{export.name}="
3623
+ export_value = output
3624
+ ### transform?
3625
+
3626
+ command_result, exportable, new_lines = export_echo_with_code(
3627
+ ["#{export.name}=#{Shellwords.escape(export_value)}"],
3628
+ export,
3629
+ force: force,
3630
+ silent: silent,
3631
+ string: export_value
3632
+ )
3633
+ else
3634
+ command_result = CommandResult.new(
3635
+ stdout: output,
3636
+ exit_status: $?.exitstatus
3637
+ )
3638
+ end
3639
+
3640
+ [
3641
+ command_result,
3642
+ exportable,
3643
+ new_lines
3644
+ ]
3616
3645
  end
3617
3646
  rescue StandardError => err
3618
3647
  warn "Error executing script: #{err.message}"
@@ -3653,7 +3682,8 @@ module MarkdownExec
3653
3682
  inherited_dependencies:
3654
3683
  dependencies.merge(pop.inherited_dependencies || {}), ### merge, not replace, key data
3655
3684
  inherited_lines:
3656
- HashDelegator.code_merge(pop.inherited_lines, code_lines)
3685
+ HashDelegator.flatten_and_compact_arrays(pop.inherited_lines,
3686
+ code_lines)
3657
3687
  )
3658
3688
  @link_history.push(next_state)
3659
3689
 
@@ -3670,7 +3700,9 @@ module MarkdownExec
3670
3700
  inherited_dependencies:
3671
3701
  (link_state&.inherited_dependencies || {}).merge(dependencies || {}), ### merge, not replace, key data
3672
3702
  inherited_lines:
3673
- HashDelegator.code_merge(link_state&.inherited_lines, code_lines),
3703
+ HashDelegator.flatten_and_compact_arrays(
3704
+ link_state&.inherited_lines, code_lines
3705
+ ),
3674
3706
  keep_code: link_state&.keep_code,
3675
3707
  next_block_name: next_block_name,
3676
3708
  next_document_filename: @delegate_object[:filename], # not next_document_filename
@@ -4624,16 +4656,21 @@ module MarkdownExec
4624
4656
  def ux_block_export_activated(
4625
4657
  bash_script_lines, export, exit_prompt
4626
4658
  )
4659
+ command_result = nil
4627
4660
  exportable = true
4628
- transformable = true
4661
+ force = true
4629
4662
  new_lines = []
4630
- command_result = nil
4663
+ silent = false
4664
+ transformable = true
4631
4665
 
4632
4666
  case FCB.act_source(export)
4633
4667
  when false, UxActSource::FALSE
4634
- raise 'Should not be reached.'
4668
+ # read-only
4669
+ command_result = CommandResult.new
4670
+ exportable = false
4671
+ transformable = false
4635
4672
 
4636
- when ':allow', UxActSource::ALLOW
4673
+ when :allow, UxActSource::ALLOW
4637
4674
  raise unless export.allow.present?
4638
4675
 
4639
4676
  case export.allow
@@ -4641,9 +4678,10 @@ module MarkdownExec
4641
4678
  command_result, exportable, new_lines = export_echo_with_code(
4642
4679
  bash_script_lines,
4643
4680
  export,
4644
- force: true,
4645
- silent: false
4681
+ force: force,
4682
+ silent: silent
4646
4683
  )
4684
+
4647
4685
  if command_result.failure?
4648
4686
  command_result
4649
4687
  else
@@ -4652,8 +4690,8 @@ module MarkdownExec
4652
4690
  )
4653
4691
  end
4654
4692
 
4655
- when ':exec', UxActSource::EXEC
4656
- command_result = output_from_adhoc_bash_script_file(
4693
+ when :exec, UxActSource::EXEC
4694
+ command_result, = output_from_adhoc_bash_script_file(
4657
4695
  join_array_of_arrays(bash_script_lines, export.exec)
4658
4696
  )
4659
4697
 
@@ -4668,22 +4706,26 @@ module MarkdownExec
4668
4706
  end
4669
4707
 
4670
4708
  else
4671
- command_result = CommandResult.new(
4672
- stdout: menu_from_list_with_back(export.allow)
4709
+ export_init = menu_from_list_with_back(export.allow)
4710
+ command_result, exportable, new_lines = export_echo_with_code(
4711
+ ["#{export.name}=#{Shellwords.escape(export_init)}"],
4712
+ export,
4713
+ force: force,
4714
+ silent: silent,
4715
+ string: export_init
4673
4716
  )
4717
+
4674
4718
  end
4675
4719
 
4676
- when ':echo', UxActSource::ECHO
4720
+ when :echo, UxActSource::ECHO
4677
4721
  command_result, exportable, new_lines = export_echo_with_code(
4678
4722
  bash_script_lines,
4679
4723
  export,
4680
- force: true,
4681
- silent: false
4724
+ force: force,
4725
+ silent: silent
4682
4726
  )
4683
4727
 
4684
- command_result
4685
-
4686
- when ':edit', UxActSource::EDIT
4728
+ when :edit, UxActSource::EDIT
4687
4729
  output = nil
4688
4730
  begin
4689
4731
  loop do
@@ -4703,13 +4745,11 @@ module MarkdownExec
4703
4745
 
4704
4746
  command_result = CommandResult.new(stdout: output)
4705
4747
 
4706
- when ':exec', UxActSource::EXEC
4707
- command_result = output_from_adhoc_bash_script_file(
4748
+ when :exec, UxActSource::EXEC
4749
+ command_result, = output_from_adhoc_bash_script_file(
4708
4750
  join_array_of_arrays(bash_script_lines, export.exec)
4709
4751
  )
4710
4752
 
4711
- command_result
4712
-
4713
4753
  else
4714
4754
  transformable = false
4715
4755
  command_result = CommandResult.new(stdout: export.default.to_s)
@@ -4718,7 +4758,7 @@ module MarkdownExec
4718
4758
  # add message for required variables
4719
4759
  if command_result.exit_status == EXIT_STATUS_REQUIRED_EMPTY
4720
4760
  command_result.warning = warning_required_empty(export)
4721
- # warn command_result.warning
4761
+ warn command_result.warning unless silent
4722
4762
  end
4723
4763
 
4724
4764
  command_result.exportable = exportable
@@ -4727,12 +4767,15 @@ module MarkdownExec
4727
4767
  command_result
4728
4768
  end
4729
4769
 
4730
- def ux_block_export_automatic(bash_script_lines, export)
4731
- transformable = true
4770
+ def ux_block_export_automatic(
4771
+ bash_script_lines, export
4772
+ )
4773
+ command_result = nil
4732
4774
  exportable = true
4775
+ force = false
4733
4776
  new_lines = []
4734
- command_result = nil
4735
4777
  silent = true
4778
+ transformable = true
4736
4779
 
4737
4780
  case FCB.init_source(export)
4738
4781
  when false, UxActSource::FALSE
@@ -4740,57 +4783,85 @@ module MarkdownExec
4740
4783
  transformable = false
4741
4784
  command_result = CommandResult.new
4742
4785
 
4743
- when ':allow', UxActSource::ALLOW
4786
+ when :allow, UxActSource::ALLOW
4744
4787
  raise unless export.allow.present?
4745
4788
 
4746
4789
  case export.allow
4747
4790
  when :echo, ExportValueSource::ECHO
4791
+ cr_echo, = output_from_adhoc_bash_script_file(
4792
+ join_array_of_arrays(
4793
+ bash_script_lines,
4794
+ %(printf '%s' "#{export.echo}")
4795
+ )
4796
+ )
4797
+ export_init = cr_echo.stdout.split("\n").first
4748
4798
  command_result, exportable, new_lines = export_echo_with_code(
4749
- bash_script_lines,
4799
+ ["#{export.name}=#{Shellwords.escape(export_init)}"],
4750
4800
  export,
4751
- force: false,
4752
- silent: silent
4801
+ force: force,
4802
+ silent: silent,
4803
+ string: export_init
4753
4804
  )
4754
- unless command_result.failure?
4755
- command_result.stdout = (exportable && command_result.stdout.split("\n").first) || ''
4756
- end
4757
4805
 
4758
4806
  when :exec, ExportValueSource::EXEC
4759
- command_result = output_from_adhoc_bash_script_file(
4807
+ # extract first line from 'exec' output
4808
+ command_result, = output_from_adhoc_bash_script_file(
4760
4809
  join_array_of_arrays(bash_script_lines, export.exec)
4761
4810
  )
4762
4811
  unless command_result.failure?
4763
- command_result.stdout = command_result.stdout.split("\n").first
4812
+ export_init = command_result.stdout.split("\n").first
4813
+ command_result, exportable, new_lines = export_echo_with_code(
4814
+ ["#{export.name}=#{Shellwords.escape(export_init)}"],
4815
+ export,
4816
+ force: force,
4817
+ silent: silent,
4818
+ string: export_init
4819
+ )
4764
4820
  end
4765
4821
 
4766
4822
  else
4767
- # must be a list
4768
- command_result = CommandResult.new(stdout: export.allow.first)
4823
+ # first item from 'allow' list
4824
+ export_init = export.allow.first
4825
+ command_result, exportable, new_lines = export_echo_with_code(
4826
+ ["#{export.name}=#{Shellwords.escape(export_init)}"],
4827
+ export,
4828
+ force: force,
4829
+ silent: silent,
4830
+ string: export_init
4831
+ )
4832
+
4769
4833
  end
4770
4834
 
4771
- when ':default', UxActSource::DEFAULT
4835
+ when :default, UxActSource::DEFAULT
4772
4836
  transformable = false
4773
4837
  command_result = CommandResult.new(stdout: export.default.to_s)
4774
4838
 
4775
- when ':echo', UxActSource::ECHO
4839
+ when :echo, UxActSource::ECHO
4776
4840
  raise unless export.echo.present?
4777
4841
 
4778
4842
  command_result, exportable, new_lines = export_echo_with_code(
4779
4843
  bash_script_lines,
4780
4844
  export,
4781
- force: false,
4845
+ force: force,
4782
4846
  silent: silent
4783
4847
  )
4784
-
4785
- when ':exec', UxActSource::EXEC
4848
+ when :exec, UxActSource::EXEC
4786
4849
  raise unless export.exec.present?
4787
4850
 
4788
- command_result = output_from_adhoc_bash_script_file(
4789
- join_array_of_arrays(bash_script_lines, export.exec)
4851
+ command_result, exportable, new_lines = output_from_adhoc_bash_script_file(
4852
+ join_array_of_arrays(bash_script_lines, export.exec),
4853
+ export
4790
4854
  )
4791
4855
 
4792
4856
  else
4793
- command_result = CommandResult.new(stdout: export.init.to_s)
4857
+ export_init = export.init.to_s
4858
+ command_result, exportable, new_lines = export_echo_with_code(
4859
+ ["#{export.name}=#{Shellwords.escape(export_init)}"],
4860
+ export,
4861
+ force: force,
4862
+ silent: silent,
4863
+ string: export_init
4864
+ )
4794
4865
  # raise "Unknown FCB.init_source(export) #{FCB.init_source(export)}"
4795
4866
  end
4796
4867
 
@@ -5206,9 +5277,6 @@ module MarkdownExec
5206
5277
  )
5207
5278
  end
5208
5279
  # rubocop:enable Style/GuardClause
5209
-
5210
- # # reflect new menu items
5211
- # @dml_mdoc = MDoc.new(@dml_menu_blocks)
5212
5280
  end
5213
5281
 
5214
5282
  def vux_navigate_back_for_ls
@@ -5245,7 +5313,6 @@ module MarkdownExec
5245
5313
  mdoc_menu_and_blocks_from_nested_files(
5246
5314
  @dml_link_state, source_id: source_id
5247
5315
  )
5248
-
5249
5316
  dump_delobj(@dml_blocks_in_file, @dml_menu_blocks, @dml_link_state)
5250
5317
  end
5251
5318
 
@@ -7,5 +7,5 @@ module MarkdownExec
7
7
  BIN_NAME = 'mde'
8
8
  GEM_NAME = 'markdown_exec'
9
9
  TAP_DEBUG = 'MDE_DEBUG'
10
- VERSION = '3.0.5'
10
+ VERSION = '3.0.6'
11
11
  end