markdown_exec 3.0.8 → 3.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd2355b28f935804fb135a650cc4260276be2bed20a8ed33cf9d188e01734466
4
- data.tar.gz: 9e001b6252ebc4f012408e8a43373ab49b474d72982fc9bbc653c93e6d39c497
3
+ metadata.gz: db0df1de92fc6f0f9e015825c75de74529867c8e128ea1fa8042aeed6ce7a632
4
+ data.tar.gz: 2c3d84281cb92393d86b3920e365e5567823022cbbb8b0fc9121780160decc46
5
5
  SHA512:
6
- metadata.gz: a17c1e662569ae1b0f34ecbb63571120c3d56bc2efdde29651240ec6d6d07e0f24e361ae9c95d34725f5c9f6a1c2d6f18fc9aad9971bdba3e2b2f850f14418d5
7
- data.tar.gz: 95184776dfde2e6579aa18e0893a9f54180c2b641d65263f0d47f5533512611f3b92c9012959bb18c0c263ca3f50dccc42e4f69651f46a4af878d02784ce40ba
6
+ metadata.gz: dc269ea3ef8706322f031617df8b47fcaa9e14cbffc586bdf834e69c4d277120e0f9b7922257e7c68f332aa3ab188c9a79cd70f42fa8e1619d2d5beffac6cf8c
7
+ data.tar.gz: 042c2709076ce1eb8c201029f5404fab11933dea6f3d068616e2082bffed08a3baf6550fa5f6e9feaa7e3248797720df239a8e33e02a2e16385af4611d0d7a71
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_exec (3.0.8)
4
+ markdown_exec (3.0.9)
5
5
  clipboard (~> 1.3.6)
6
6
  open3 (~> 0.1.1)
7
7
  optparse (~> 0.1.1)
data/bats/cli.bats CHANGED
@@ -36,6 +36,18 @@ load 'test_helper'
36
36
  ' ARG1: 37'
37
37
  }
38
38
 
39
+ @test 'vars in link block are appended to inherited lines - local link' {
40
+ spec_mde_xansi_dname_doc_blocks_expect docs/dev/requiring-blocks.md \
41
+ '[link-local-block-with-vars]' \
42
+ '* Exit_# [link-local-block-with-vars]_ARG1="37"_block: echo-ARG1_ file: docs/dev/linked-file.md_ vars:_ ARG1: arg1-from-link-file_block: output_arguments_ vars:_ ARG1: 37_block: missing_ARG1=37_output_arguments'
43
+ }
44
+
45
+ @test 'vars in link block are appended to inherited lines - external file' {
46
+ spec_mde_xansi_dname_doc_blocks_expect docs/dev/requiring-blocks.md \
47
+ '[link-file-block-with-vars]' \
48
+ '* Exit_# [link-file-block-with-vars]_ARG1="arg1-from-link-file"_echo-ARG1'
49
+ }
50
+
39
51
  # the last block is a link block, so menu is displayed
40
52
  @test 'link block setting an environment variable requires a bash block' {
41
53
  BATS_OUTPUT_FILTER=A
@@ -1,3 +1,6 @@
1
1
  ```bash :echo-ARG1
2
2
  echo "ARG1: $ARG1"
3
+ ```
4
+ ```opts :(document_opts)
5
+ menu_with_inherited_lines: true
3
6
  ```
@@ -21,4 +21,5 @@ echo "ARG1: $ARG1"
21
21
  @import bats-document-configuration.md
22
22
  ```opts :(document_opts)
23
23
  menu_with_exit: true
24
+ menu_with_inherited_lines: true
24
25
  ```
@@ -45,7 +45,6 @@ def evaluate_shell_expressions(initial_code, expressions, shell: '/bin/bash',
45
45
  end
46
46
 
47
47
  result_hash
48
-
49
48
  rescue StandardError
50
49
  ww $@, $!, caller.deref
51
50
  ww initial_code, expressions
data/lib/fcb.rb CHANGED
@@ -23,6 +23,7 @@ def parse_yaml_of_ux_block(
23
23
  default: export['default'],
24
24
  echo: export['echo'],
25
25
  exec: export['exec'],
26
+ force: export['force'],
26
27
  init: export['init'],
27
28
  menu_format: export['format'] || export['menu_format'] || menu_format,
28
29
  name: name,
@@ -156,20 +157,26 @@ module MarkdownExec
156
157
  @attrs[:id] = id
157
158
 
158
159
  if @attrs[:type] == BlockType::UX
159
- case data = YAML.load(@attrs[:body].join("\n"))
160
- when Hash
161
- export = parse_yaml_of_ux_block(
162
- data,
163
- menu_format: menu_format,
164
- prompt: prompt
165
- )
166
-
167
- @attrs[:center] = table_center
168
- oname = @attrs[:oname] = format(export.menu_format, export.to_h)
169
- @attrs[:readonly] = export.readonly
170
- else
171
- # triggered by an empty or non-YAML block
172
- return NullResult.new(message: 'Invalid YAML', data: data)
160
+ begin
161
+ case data = YAML.load(@attrs[:body].join("\n"))
162
+ when Hash
163
+ export = parse_yaml_of_ux_block(
164
+ data,
165
+ menu_format: menu_format,
166
+ prompt: prompt
167
+ )
168
+
169
+ @attrs[:center] = table_center
170
+ oname = @attrs[:oname] = format(export.menu_format, export.to_h)
171
+ @attrs[:readonly] = export.readonly
172
+ else
173
+ # triggered by an empty or non-YAML block
174
+ return NullResult.new(message: 'Invalid YAML', data: data)
175
+ end
176
+ rescue StandardError
177
+ ww $@, $!, caller.deref
178
+ ww @attrs[:body], data, export
179
+ raise StandardError, $!
173
180
  end
174
181
  end
175
182
 
@@ -954,7 +954,7 @@ module MarkdownExec
954
954
  blocks << fcb unless result.failure?
955
955
  end
956
956
  rescue StandardError
957
- # ww $@, $!
957
+ ww $@, $!, caller.deref
958
958
  HashDelegator.error_handler('blocks_from_nested_files',
959
959
  { abort: true })
960
960
  end
@@ -978,7 +978,7 @@ module MarkdownExec
978
978
  end
979
979
  OpenStruct.new(blocks: blocks, results: results)
980
980
  rescue StandardError
981
- # ww $@, $!
981
+ ww $@, $!, caller.deref
982
982
  HashDelegator.error_handler('blocks_from_nested_files')
983
983
  end
984
984
 
@@ -994,9 +994,6 @@ module MarkdownExec
994
994
  initial_code_required: false,
995
995
  occurrence_expressions: nil
996
996
  )
997
- ww commands
998
- ww link_state
999
- # binding.irb####
1000
997
  evaluate_shell_expressions(
1001
998
  (link_state&.inherited_lines_block || ''),
1002
999
  commands,
@@ -1113,11 +1110,9 @@ ww link_state
1113
1110
  selected, mdoc, inherited_code: nil, force: true, only_default: false,
1114
1111
  silent:
1115
1112
  )
1116
- ww selected
1117
1113
  ret_command_result = nil
1118
1114
  exit_prompt = @delegate_object[:prompt_filespec_back]
1119
1115
 
1120
- ww \
1121
1116
  required = mdoc.collect_recursively_required_code(
1122
1117
  anyname: selected.pub_name,
1123
1118
  label_format_above: @delegate_object[:shell_code_label_format_above],
@@ -1171,19 +1166,8 @@ ww \
1171
1166
  return command_result_w_e_t_nl if command_result_w_e_t_nl.failure?
1172
1167
 
1173
1168
  command_result_w_e_t_nl.new_lines =
1174
- command_result_w_e_t_nl.new_lines.map do |name_force|
1175
- transformed = if command_result_w_e_t_nl.transformable
1176
- transform_export_value(name_force[:text], export)
1177
- else
1178
- name_force[:text]
1179
-
1180
- end
1181
- EnvInterface.set(name_force[:name], transformed)
1182
-
1183
- code_line_safe_assign(
1184
- name_force[:name], transformed, force: name_force[:force]
1185
- )
1186
- end
1169
+ process_command_result_lines(command_result_w_e_t_nl, export,
1170
+ required_lines)
1187
1171
  required_lines.concat(command_result_w_e_t_nl.new_lines)
1188
1172
  ret_command_result = command_result_w_e_t_nl
1189
1173
  else
@@ -1193,22 +1177,19 @@ ww \
1193
1177
 
1194
1178
  ret_command_result || CommandResult.new(stdout: required_lines)
1195
1179
  rescue StandardError
1196
- ww $@, $!
1180
+ ww $@, $!, caller.deref
1197
1181
  HashDelegator.error_handler('code_from_ux_block_to_set_environment_variables')
1198
1182
  end
1199
1183
 
1200
- def env_set(name, value)
1201
- EnvInterface.set(name, value)
1202
- end
1203
-
1204
1184
  # sets ENV
1205
1185
  def code_from_vars_block_to_set_environment_variables(selected)
1206
1186
  code_lines = []
1187
+ # code_lines << '# code_from_vars_block_to_set_environment_variables'
1207
1188
  case data = YAML.load(selected.body.join("\n"))
1208
1189
  when Hash
1209
1190
  data.each do |key, value|
1210
1191
  EnvInterface.set(key, value.to_s)
1211
- code_lines.push "#{key}=#{Shellwords.escape(value)}"
1192
+ code_lines << assign_key_value_in_bash(key, value)
1212
1193
 
1213
1194
  next unless @delegate_object[:menu_vars_set_format].present?
1214
1195
 
@@ -1706,10 +1687,6 @@ ww \
1706
1687
  @prior_execution_block = nil
1707
1688
  end
1708
1689
 
1709
- def selected_shell(shell_name)
1710
- shell_name.empty? ? shell : shell_name
1711
- end
1712
-
1713
1690
  # Determines the state of a selected block in the menu based
1714
1691
  # on the selected option.
1715
1692
  # It categorizes the selected option into either EXIT, BACK,
@@ -1932,6 +1909,10 @@ ww \
1932
1909
  result_text
1933
1910
  end
1934
1911
 
1912
+ def env_set(name, value)
1913
+ EnvInterface.set(name, value)
1914
+ end
1915
+
1935
1916
  # Execute a code block after approval and provide user interaction options.
1936
1917
  #
1937
1918
  # This method displays required code blocks, asks for user approval, and
@@ -2176,10 +2157,10 @@ ww \
2176
2157
  # load key and values from link block into current environment
2177
2158
  #
2178
2159
  if link_block_data[LinkKeys::VARS]
2179
- code_lines.push BashCommentFormatter.format_comment(selected.pub_name)
2180
- (link_block_data[LinkKeys::VARS] || []).each do |(key, value)|
2160
+ code_lines << BashCommentFormatter.format_comment(selected.pub_name)
2161
+ link_block_data[LinkKeys::VARS].each do |key, value|
2162
+ code_lines << assign_key_value_in_bash(key, value)
2181
2163
  EnvInterface.set(key, value.to_s)
2182
- code_lines.push(assign_key_value_in_bash(key, value))
2183
2164
  end
2184
2165
  end
2185
2166
 
@@ -2202,7 +2183,7 @@ ww \
2202
2183
  if link_block_data.fetch(LinkKeys::EVAL,
2203
2184
  false) || link_block_data.fetch(LinkKeys::EXEC,
2204
2185
  false)
2205
- code_lines = link_block_data_eval(
2186
+ code_lines += link_block_data_eval(
2206
2187
  link_state, code_lines, selected, link_block_data,
2207
2188
  block_source: block_source,
2208
2189
  shell: @delegate_object[:block_type_default]
@@ -2540,7 +2521,6 @@ ww \
2540
2521
  end
2541
2522
 
2542
2523
  def expand_references!(fcb, link_state)
2543
- ww fcb, link_state, caller.deref
2544
2524
  expand_variable_references!(
2545
2525
  blocks: [fcb],
2546
2526
  echo_formatter: method(:format_echo_command),
@@ -2583,22 +2563,15 @@ ww fcb, link_state, caller.deref
2583
2563
  link_state:,
2584
2564
  pattern:
2585
2565
  )
2586
- ww blocks####
2587
- ww link_state
2588
- # binding.irb
2589
2566
  variable_counts, occurrence_expressions = count_named_group_occurrences(
2590
2567
  blocks, pattern, group_name: group_name
2591
2568
  )
2592
2569
  return if variable_counts.nil? || variable_counts == {}
2593
- ww [variable_counts, occurrence_expressions]
2594
2570
 
2595
- ww \
2596
2571
  echo_commands = generate_echo_commands(
2597
2572
  variable_counts, formatter: echo_formatter
2598
2573
  )
2599
2574
 
2600
- ww link_state
2601
- ww \
2602
2575
  replacements = build_replacement_dictionary(
2603
2576
  echo_commands, link_state,
2604
2577
  initial_code_required: initial_code_required,
@@ -2608,11 +2581,9 @@ ww \
2608
2581
  return if replacements.nil?
2609
2582
  if replacements == EvaluateShellExpression::StatusFail
2610
2583
  # happens on first processing of blocks before requirements are met
2611
- ww "EvaluateShellExpression::StatusFail", echo_commands, link_state
2612
2584
  return
2613
2585
  end
2614
2586
 
2615
- ww \
2616
2587
  expand_blocks_with_replacements(blocks, replacements)
2617
2588
  # no return
2618
2589
  end
@@ -3015,7 +2986,11 @@ ww \
3015
2986
  # convert single items to arrays
3016
2987
  def join_array_of_arrays(*args)
3017
2988
  args.map do |item|
3018
- item.nil? ? nil : (item.is_a?(Array) ? item : [item])
2989
+ if item.nil?
2990
+ nil
2991
+ else
2992
+ (item.is_a?(Array) ? item : [item])
2993
+ end
3019
2994
  end.compact.flatten(1)
3020
2995
  end
3021
2996
 
@@ -3639,13 +3614,14 @@ ww \
3639
3614
 
3640
3615
  exportable = export ? export.exportable : false
3641
3616
  new_lines = []
3617
+ # new_lines << { comment: 'output_from_adhoc_bash_script_file' }
3642
3618
  if export
3643
3619
  new_lines << "#{export.name}="
3644
3620
  export_value = output
3645
3621
  ### transform?
3646
3622
 
3647
3623
  command_result, exportable, new_lines = export_echo_with_code(
3648
- ["#{export.name}=#{Shellwords.escape(export_value)}"],
3624
+ [assign_key_value_in_bash(export.name, export_value)],
3649
3625
  export,
3650
3626
  force: force,
3651
3627
  silent: silent,
@@ -3811,6 +3787,35 @@ ww \
3811
3787
 
3812
3788
  # private
3813
3789
 
3790
+ def process_command_result_lines(command_result_w_e_t_nl, export,
3791
+ required_lines)
3792
+ command_result_w_e_t_nl.new_lines.map do |name_force|
3793
+ comment = name_force.fetch(:comment, '')
3794
+ name = name_force.fetch(:name, '')
3795
+ if !name.empty?
3796
+ transformed = if command_result_w_e_t_nl.transformable
3797
+ transform_export_value(name_force[:text], export)
3798
+ else
3799
+ name_force[:text]
3800
+ end
3801
+
3802
+ # store the transformed value in ENV
3803
+ EnvInterface.set(name, transformed)
3804
+
3805
+ set = code_line_safe_assign(
3806
+ name, transformed, force: name_force[:force]
3807
+ )
3808
+
3809
+ comment.empty? ? set : "#{set} # #{comment}"
3810
+ else
3811
+ "# #{comment}" if comment.empty?
3812
+ end
3813
+ end
3814
+ rescue StandardError
3815
+ ww $@, $!, caller.deref
3816
+ raise StandardError, $!
3817
+ end
3818
+
3814
3819
  def process_string_array(arr, begin_pattern: nil, end_pattern: nil, scan1: nil,
3815
3820
  format1: nil, name: '')
3816
3821
  in_block = !begin_pattern.present?
@@ -4440,6 +4445,10 @@ ww \
4440
4445
  selected
4441
4446
  end
4442
4447
 
4448
+ def selected_shell(shell_name)
4449
+ shell_name.empty? ? shell : shell_name
4450
+ end
4451
+
4443
4452
  def shell
4444
4453
  @delegate_object[:shell]
4445
4454
  end
@@ -4679,7 +4688,7 @@ ww \
4679
4688
  )
4680
4689
  command_result = nil
4681
4690
  exportable = true
4682
- force = true
4691
+ force = export.force.nil? ? true : export.force
4683
4692
  new_lines = []
4684
4693
  silent = false
4685
4694
  transformable = true
@@ -4729,7 +4738,7 @@ ww \
4729
4738
  else
4730
4739
  export_init = menu_from_list_with_back(export.allow)
4731
4740
  command_result, exportable, new_lines = export_echo_with_code(
4732
- ["#{export.name}=#{Shellwords.escape(export_init)}"],
4741
+ [assign_key_value_in_bash(export.name, export_init)],
4733
4742
  export,
4734
4743
  force: force,
4735
4744
  silent: silent,
@@ -4764,7 +4773,12 @@ ww \
4764
4773
  transformable = false
4765
4774
  end
4766
4775
 
4767
- command_result = CommandResult.new(stdout: output)
4776
+ if exportable
4777
+ EnvInterface.set(export.name, output)
4778
+ new_lines << { name: export.name, force: force,
4779
+ text: output }
4780
+ command_result = CommandResult.new(stdout: output)
4781
+ end
4768
4782
 
4769
4783
  when :exec, UxActSource::EXEC
4770
4784
  command_result, exportable, new_lines = output_from_adhoc_bash_script_file(
@@ -4794,7 +4808,7 @@ ww \
4794
4808
  )
4795
4809
  command_result = nil
4796
4810
  exportable = true
4797
- force = false
4811
+ force = export.force.nil? ? false : export.force
4798
4812
  new_lines = []
4799
4813
  silent = true
4800
4814
  transformable = true
@@ -4819,7 +4833,7 @@ ww \
4819
4833
  )
4820
4834
  export_init = cr_echo.stdout.split("\n").first
4821
4835
  command_result, exportable, new_lines = export_echo_with_code(
4822
- ["#{export.name}=#{Shellwords.escape(export_init)}"],
4836
+ [assign_key_value_in_bash(export.name, export_init)],
4823
4837
  export,
4824
4838
  force: force,
4825
4839
  silent: silent,
@@ -4835,7 +4849,7 @@ ww \
4835
4849
  unless command_result.failure?
4836
4850
  export_init = command_result.stdout.split("\n").first
4837
4851
  command_result, exportable, new_lines = export_echo_with_code(
4838
- ["#{export.name}=#{Shellwords.escape(export_init)}"],
4852
+ [assign_key_value_in_bash(export.name, export_init)],
4839
4853
  export,
4840
4854
  force: force,
4841
4855
  silent: silent,
@@ -4847,7 +4861,7 @@ ww \
4847
4861
  # first item from 'allow' list
4848
4862
  export_init = export.allow.first
4849
4863
  command_result, exportable, new_lines = export_echo_with_code(
4850
- ["#{export.name}=#{Shellwords.escape(export_init)}"],
4864
+ [assign_key_value_in_bash(export.name, export_init)],
4851
4865
  export,
4852
4866
  force: force,
4853
4867
  silent: silent,
@@ -4880,7 +4894,7 @@ ww \
4880
4894
  else
4881
4895
  export_init = export.init.to_s
4882
4896
  command_result, exportable, new_lines = export_echo_with_code(
4883
- ["#{export.name}=#{Shellwords.escape(export_init)}"],
4897
+ [assign_key_value_in_bash(export.name, export_init)],
4884
4898
  export,
4885
4899
  force: force,
4886
4900
  silent: silent,
@@ -5337,7 +5351,6 @@ ww \
5337
5351
  mdoc_menu_and_blocks_from_nested_files(
5338
5352
  @dml_link_state, source_id: source_id
5339
5353
  )
5340
- ww @dml_link_state####
5341
5354
  dump_delobj(@dml_blocks_in_file, @dml_menu_blocks, @dml_link_state)
5342
5355
  end
5343
5356
 
@@ -5884,7 +5897,7 @@ module MarkdownExec
5884
5897
  mdoc: @mdoc, selected: @selected, block_source: {}
5885
5898
  )
5886
5899
 
5887
- assert_equal ['code line', 'key=value'], result
5900
+ assert_equal ['code line', 'key="value"'], result
5888
5901
  end
5889
5902
  end
5890
5903
 
@@ -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.8'
10
+ VERSION = '3.0.9'
11
11
  end
data/lib/mdoc.rb CHANGED
@@ -178,11 +178,12 @@ module MarkdownExec
178
178
  collect_block_code_stdout(fcb)
179
179
  elsif [BlockType::OPTS].include? fcb.type
180
180
  fcb.body # entire body is returned to requesing block
181
+
181
182
  elsif [BlockType::LINK,
182
183
  BlockType::LOAD,
183
184
  BlockType::UX,
184
185
  BlockType::VARS].include? fcb.type
185
- nil
186
+ nil # Vars for all types are collected later
186
187
  elsif fcb[:chrome] # for Link blocks like History
187
188
  nil
188
189
  elsif fcb.type == BlockType::PORT
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdown_exec
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.8
4
+ version: 3.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fareed Stevenson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-06-11 00:00:00.000000000 Z
11
+ date: 2025-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard