markdown_exec 3.0.7 → 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: dbc7513dd9f277050aee99dd0c2eb7d047a43d75ae763510131b150a678648f9
4
- data.tar.gz: 1f8805e038d7a355bf3f68b47e066e30b4f1f75a269b907bfe8e55f83a9b9989
3
+ metadata.gz: db0df1de92fc6f0f9e015825c75de74529867c8e128ea1fa8042aeed6ce7a632
4
+ data.tar.gz: 2c3d84281cb92393d86b3920e365e5567823022cbbb8b0fc9121780160decc46
5
5
  SHA512:
6
- metadata.gz: edb200a3b6c6edcb4ab1bb942cfe7f27f3fb5604d7a2ffa449f2b2bb3492f0ee0864226e1202a2269fbc731e09f5fc29da001ab22229edc81e8754d51ae486cd
7
- data.tar.gz: 19bb30ed25a401d3ee94826ae82c9f02836f7b51493ab88b3197a6a5c2826d7d5f0580653a0f15a07ac43a97501be8387ec86e37f4aafb87b9d7530a89514a70
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.7)
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,6 +45,10 @@ def evaluate_shell_expressions(initial_code, expressions, shell: '/bin/bash',
45
45
  end
46
46
 
47
47
  result_hash
48
+ rescue StandardError
49
+ ww $@, $!, caller.deref
50
+ ww initial_code, expressions
51
+ raise StandardError, $!
48
52
  end
49
53
 
50
54
  return if $PROGRAM_NAME != __FILE__
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
 
@@ -1166,19 +1166,8 @@ module MarkdownExec
1166
1166
  return command_result_w_e_t_nl if command_result_w_e_t_nl.failure?
1167
1167
 
1168
1168
  command_result_w_e_t_nl.new_lines =
1169
- command_result_w_e_t_nl.new_lines.map do |name_force|
1170
- transformed = if command_result_w_e_t_nl.transformable
1171
- transform_export_value(name_force[:text], export)
1172
- else
1173
- name_force[:text]
1174
-
1175
- end
1176
- EnvInterface.set(name_force[:name], transformed)
1177
-
1178
- code_line_safe_assign(
1179
- name_force[:name], transformed, force: name_force[:force]
1180
- )
1181
- end
1169
+ process_command_result_lines(command_result_w_e_t_nl, export,
1170
+ required_lines)
1182
1171
  required_lines.concat(command_result_w_e_t_nl.new_lines)
1183
1172
  ret_command_result = command_result_w_e_t_nl
1184
1173
  else
@@ -1188,22 +1177,19 @@ module MarkdownExec
1188
1177
 
1189
1178
  ret_command_result || CommandResult.new(stdout: required_lines)
1190
1179
  rescue StandardError
1191
- ww $@, $!
1180
+ ww $@, $!, caller.deref
1192
1181
  HashDelegator.error_handler('code_from_ux_block_to_set_environment_variables')
1193
1182
  end
1194
1183
 
1195
- def env_set(name, value)
1196
- EnvInterface.set(name, value)
1197
- end
1198
-
1199
1184
  # sets ENV
1200
1185
  def code_from_vars_block_to_set_environment_variables(selected)
1201
1186
  code_lines = []
1187
+ # code_lines << '# code_from_vars_block_to_set_environment_variables'
1202
1188
  case data = YAML.load(selected.body.join("\n"))
1203
1189
  when Hash
1204
1190
  data.each do |key, value|
1205
1191
  EnvInterface.set(key, value.to_s)
1206
- code_lines.push "#{key}=#{Shellwords.escape(value)}"
1192
+ code_lines << assign_key_value_in_bash(key, value)
1207
1193
 
1208
1194
  next unless @delegate_object[:menu_vars_set_format].present?
1209
1195
 
@@ -1701,10 +1687,6 @@ module MarkdownExec
1701
1687
  @prior_execution_block = nil
1702
1688
  end
1703
1689
 
1704
- def selected_shell(shell_name)
1705
- shell_name.empty? ? shell : shell_name
1706
- end
1707
-
1708
1690
  # Determines the state of a selected block in the menu based
1709
1691
  # on the selected option.
1710
1692
  # It categorizes the selected option into either EXIT, BACK,
@@ -1927,6 +1909,10 @@ module MarkdownExec
1927
1909
  result_text
1928
1910
  end
1929
1911
 
1912
+ def env_set(name, value)
1913
+ EnvInterface.set(name, value)
1914
+ end
1915
+
1930
1916
  # Execute a code block after approval and provide user interaction options.
1931
1917
  #
1932
1918
  # This method displays required code blocks, asks for user approval, and
@@ -2171,10 +2157,10 @@ module MarkdownExec
2171
2157
  # load key and values from link block into current environment
2172
2158
  #
2173
2159
  if link_block_data[LinkKeys::VARS]
2174
- code_lines.push BashCommentFormatter.format_comment(selected.pub_name)
2175
- (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)
2176
2163
  EnvInterface.set(key, value.to_s)
2177
- code_lines.push(assign_key_value_in_bash(key, value))
2178
2164
  end
2179
2165
  end
2180
2166
 
@@ -2197,7 +2183,7 @@ module MarkdownExec
2197
2183
  if link_block_data.fetch(LinkKeys::EVAL,
2198
2184
  false) || link_block_data.fetch(LinkKeys::EXEC,
2199
2185
  false)
2200
- code_lines = link_block_data_eval(
2186
+ code_lines += link_block_data_eval(
2201
2187
  link_state, code_lines, selected, link_block_data,
2202
2188
  block_source: block_source,
2203
2189
  shell: @delegate_object[:block_type_default]
@@ -2593,7 +2579,10 @@ module MarkdownExec
2593
2579
  )
2594
2580
 
2595
2581
  return if replacements.nil?
2596
- return if replacements == EvaluateShellExpression::StatusFail
2582
+ if replacements == EvaluateShellExpression::StatusFail
2583
+ # happens on first processing of blocks before requirements are met
2584
+ return
2585
+ end
2597
2586
 
2598
2587
  expand_blocks_with_replacements(blocks, replacements)
2599
2588
  # no return
@@ -2608,7 +2597,7 @@ module MarkdownExec
2608
2597
  export_string = string.nil? ? export.echo : string
2609
2598
  case export_string
2610
2599
  when String, Integer, Float, TrueClass, FalseClass
2611
- command_result, = output_from_adhoc_bash_script_file(
2600
+ command_result, exportable, new_lines = output_from_adhoc_bash_script_file(
2612
2601
  join_array_of_arrays(
2613
2602
  bash_script_lines,
2614
2603
  %(printf '%s' "#{export_string}")
@@ -2997,7 +2986,11 @@ module MarkdownExec
2997
2986
  # convert single items to arrays
2998
2987
  def join_array_of_arrays(*args)
2999
2988
  args.map do |item|
3000
- 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
3001
2994
  end.compact.flatten(1)
3002
2995
  end
3003
2996
 
@@ -3621,13 +3614,14 @@ module MarkdownExec
3621
3614
 
3622
3615
  exportable = export ? export.exportable : false
3623
3616
  new_lines = []
3617
+ # new_lines << { comment: 'output_from_adhoc_bash_script_file' }
3624
3618
  if export
3625
3619
  new_lines << "#{export.name}="
3626
3620
  export_value = output
3627
3621
  ### transform?
3628
3622
 
3629
3623
  command_result, exportable, new_lines = export_echo_with_code(
3630
- ["#{export.name}=#{Shellwords.escape(export_value)}"],
3624
+ [assign_key_value_in_bash(export.name, export_value)],
3631
3625
  export,
3632
3626
  force: force,
3633
3627
  silent: silent,
@@ -3793,6 +3787,35 @@ module MarkdownExec
3793
3787
 
3794
3788
  # private
3795
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
+
3796
3819
  def process_string_array(arr, begin_pattern: nil, end_pattern: nil, scan1: nil,
3797
3820
  format1: nil, name: '')
3798
3821
  in_block = !begin_pattern.present?
@@ -4422,6 +4445,10 @@ module MarkdownExec
4422
4445
  selected
4423
4446
  end
4424
4447
 
4448
+ def selected_shell(shell_name)
4449
+ shell_name.empty? ? shell : shell_name
4450
+ end
4451
+
4425
4452
  def shell
4426
4453
  @delegate_object[:shell]
4427
4454
  end
@@ -4661,7 +4688,7 @@ module MarkdownExec
4661
4688
  )
4662
4689
  command_result = nil
4663
4690
  exportable = true
4664
- force = true
4691
+ force = export.force.nil? ? true : export.force
4665
4692
  new_lines = []
4666
4693
  silent = false
4667
4694
  transformable = true
@@ -4711,7 +4738,7 @@ module MarkdownExec
4711
4738
  else
4712
4739
  export_init = menu_from_list_with_back(export.allow)
4713
4740
  command_result, exportable, new_lines = export_echo_with_code(
4714
- ["#{export.name}=#{Shellwords.escape(export_init)}"],
4741
+ [assign_key_value_in_bash(export.name, export_init)],
4715
4742
  export,
4716
4743
  force: force,
4717
4744
  silent: silent,
@@ -4746,11 +4773,17 @@ module MarkdownExec
4746
4773
  transformable = false
4747
4774
  end
4748
4775
 
4749
- 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
4750
4782
 
4751
4783
  when :exec, UxActSource::EXEC
4752
- command_result, = output_from_adhoc_bash_script_file(
4753
- join_array_of_arrays(bash_script_lines, export.exec)
4784
+ command_result, exportable, new_lines = output_from_adhoc_bash_script_file(
4785
+ join_array_of_arrays(bash_script_lines, export.exec),
4786
+ export
4754
4787
  )
4755
4788
 
4756
4789
  else
@@ -4775,7 +4808,7 @@ module MarkdownExec
4775
4808
  )
4776
4809
  command_result = nil
4777
4810
  exportable = true
4778
- force = false
4811
+ force = export.force.nil? ? false : export.force
4779
4812
  new_lines = []
4780
4813
  silent = true
4781
4814
  transformable = true
@@ -4795,11 +4828,12 @@ module MarkdownExec
4795
4828
  join_array_of_arrays(
4796
4829
  bash_script_lines,
4797
4830
  %(printf '%s' "#{export.echo}")
4798
- )
4831
+ ),
4832
+ export
4799
4833
  )
4800
4834
  export_init = cr_echo.stdout.split("\n").first
4801
4835
  command_result, exportable, new_lines = export_echo_with_code(
4802
- ["#{export.name}=#{Shellwords.escape(export_init)}"],
4836
+ [assign_key_value_in_bash(export.name, export_init)],
4803
4837
  export,
4804
4838
  force: force,
4805
4839
  silent: silent,
@@ -4808,13 +4842,14 @@ module MarkdownExec
4808
4842
 
4809
4843
  when :exec, ExportValueSource::EXEC
4810
4844
  # extract first line from 'exec' output
4811
- command_result, = output_from_adhoc_bash_script_file(
4812
- join_array_of_arrays(bash_script_lines, export.exec)
4845
+ command_result, exportable, new_lines = output_from_adhoc_bash_script_file(
4846
+ join_array_of_arrays(bash_script_lines, export.exec),
4847
+ export
4813
4848
  )
4814
4849
  unless command_result.failure?
4815
4850
  export_init = command_result.stdout.split("\n").first
4816
4851
  command_result, exportable, new_lines = export_echo_with_code(
4817
- ["#{export.name}=#{Shellwords.escape(export_init)}"],
4852
+ [assign_key_value_in_bash(export.name, export_init)],
4818
4853
  export,
4819
4854
  force: force,
4820
4855
  silent: silent,
@@ -4826,7 +4861,7 @@ module MarkdownExec
4826
4861
  # first item from 'allow' list
4827
4862
  export_init = export.allow.first
4828
4863
  command_result, exportable, new_lines = export_echo_with_code(
4829
- ["#{export.name}=#{Shellwords.escape(export_init)}"],
4864
+ [assign_key_value_in_bash(export.name, export_init)],
4830
4865
  export,
4831
4866
  force: force,
4832
4867
  silent: silent,
@@ -4859,7 +4894,7 @@ module MarkdownExec
4859
4894
  else
4860
4895
  export_init = export.init.to_s
4861
4896
  command_result, exportable, new_lines = export_echo_with_code(
4862
- ["#{export.name}=#{Shellwords.escape(export_init)}"],
4897
+ [assign_key_value_in_bash(export.name, export_init)],
4863
4898
  export,
4864
4899
  force: force,
4865
4900
  silent: silent,
@@ -5862,7 +5897,7 @@ module MarkdownExec
5862
5897
  mdoc: @mdoc, selected: @selected, block_source: {}
5863
5898
  )
5864
5899
 
5865
- assert_equal ['code line', 'key=value'], result
5900
+ assert_equal ['code line', 'key="value"'], result
5866
5901
  end
5867
5902
  end
5868
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.7'
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.7
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-10 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