markdown_exec 2.0.8.2 → 2.0.8.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 39b3a2b14b7efe82967efab04742281a8233a24daebf7c68f11fec661c8cd80e
4
- data.tar.gz: 16586313129a6c66cced3e45b6c94c758eba0fa0ea7fccce47a848366435ff11
3
+ metadata.gz: 858c301950e3ca7d43bc8c8c9a87f1c340b75710c28743a02ed0811a649b46ba
4
+ data.tar.gz: 4c7445f2d0e05e974cadd163894772b865bd7f94717f6f070fda6b2db2a0ef8c
5
5
  SHA512:
6
- metadata.gz: b7bcb0cb4ffdf2979ccc749a9abe1aaf86314b7a4ecd8fa34f9d6bfac7ae7d8a62f1981dcbdf7f0e7dd211e193392f009865b2adcd5eb5aa9d15610cd60559bb
7
- data.tar.gz: 5ab77246617cec9bb918a44e51d40ba1ef4d1215c57de9541538f2f10aa60e61144fad31e7bd7901d7985b95064863783258ddec35dea48fe1a86faf4dbd15f2
6
+ metadata.gz: c157d1ec261a140205eabe4d2ec8a30839e8b8f1c716c2d24710d3630c587e03282b11a5f27e269e02b8e1a568fbca7bf2e37537cc04d4b9d4cfce9ef1ab4803
7
+ data.tar.gz: d991a308e029da9078adb996d8735951e3100eb117bc5a1f196db040513d4e20c715c6a4a805dcd528a93bd98d1a7b125eb2d88c4d9fea7449af1ad04add67be
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_exec (2.0.8.2)
4
+ markdown_exec (2.0.8.4)
5
5
  clipboard (~> 1.3.6)
6
6
  open3 (~> 0.1.1)
7
7
  optparse (~> 0.1.1)
@@ -13,7 +13,7 @@ __filedirs_all()
13
13
  }
14
14
 
15
15
  _mde_echo_version() {
16
- echo "2.0.8.2"
16
+ echo "2.0.8.4"
17
17
  }
18
18
 
19
19
  _mde() {
@@ -178,4 +178,4 @@ _mde() {
178
178
 
179
179
  complete -o filenames -o nospace -F _mde mde
180
180
  # _mde_echo_version
181
- # echo "Updated: 2024-06-07 23:43:21 UTC"
181
+ # echo "Updated: 2024-06-24 04:53:41 UTC"
data/examples/linked.md CHANGED
@@ -1,6 +1,7 @@
1
1
  Demonstrate setting variable values interactively for use in generated scripts.
2
2
 
3
3
  ```opts :(document_options)
4
+ menu_with_inherited_lines: true
4
5
  pause_after_script_execution: false
5
6
  user_must_approve: false
6
7
  ```
@@ -40,7 +41,7 @@ vars:
40
41
  ::: Set variable ALPHA in a Vars block
41
42
  For each environment variable named in block,
42
43
  append an inherited line that assigns the variable the specified value.
43
- ```vars :set_ALPHA_to_1_via_vars_block
44
+ ```vars :[set_ALPHA_to_1_via_vars_block]
44
45
  ALPHA: 1
45
46
  ```
46
47
 
@@ -48,7 +49,7 @@ ALPHA: 1
48
49
  For each environment variable in `vars`,
49
50
  append an inherited line that assigns the variable the specified value.
50
51
  Subsequently, run the `display_variable_ALPHA` block.
51
- ```link :set_ALPHA_to_2_via_link_block_and_display
52
+ ```link :[set_ALPHA_to_2_via_link_block_and_display]
52
53
  block: display_variable_ALPHA
53
54
  vars:
54
55
  ALPHA: 2
@@ -59,14 +60,14 @@ Subsequently, run the `display_variable_ALPHA` block.
59
60
  ```bash :(bash_set_to_3)
60
61
  ALPHA=3
61
62
  ```
62
- ```link :set_ALPHA_to_3_via_required_block_and_display +(bash_set_to_3)
63
+ ```link :[set_ALPHA_to_3_via_required_block_and_display] +(bash_set_to_3)
63
64
  block: display_variable_ALPHA
64
65
  ```
65
66
 
66
67
  Evaluate the code in the required block `(bash_eval_set_to_4)` and
67
68
  save (transformed) output into inherited lines.
68
69
  Subsequently, run the `display_variable_ALPHA` block.
69
- ```link :set_ALPHA_to_4_via_evaluated_required_block_and_display +(bash_eval_set_to_4)
70
+ ```link :[set_ALPHA_to_4_via_evaluated_required_block_and_display] +(bash_eval_set_to_4)
70
71
  eval: true
71
72
  next_block: display_variable_ALPHA
72
73
  ```
@@ -793,7 +793,7 @@ module MarkdownExec
793
793
  end
794
794
 
795
795
  def command_execute(command, args: [])
796
- @run_state.files = Hash.new([])
796
+ run_state_reset_stream_logs
797
797
  @run_state.options = @delegate_object
798
798
  @run_state.started_at = Time.now.utc
799
799
 
@@ -807,7 +807,6 @@ module MarkdownExec
807
807
  command_execute_in_own_window_format_arguments(rest: args ? args.join(' ') : '')
808
808
  )
809
809
  )
810
-
811
810
  else
812
811
  @run_state.in_own_window = false
813
812
  execute_command_with_streams(
@@ -1097,7 +1096,6 @@ module MarkdownExec
1097
1096
  block_name: @delegate_object[:block_name],
1098
1097
  document_filename: @delegate_object[:filename]
1099
1098
  )
1100
- # @dml_link_state_block_name_from_cli = @dml_link_state.block_name.present? ###
1101
1099
  @run_state.block_name_from_cli = @dml_link_state.block_name.present?
1102
1100
  @cli_block_name = @dml_link_state.block_name
1103
1101
  @dml_now_using_cli = @run_state.block_name_from_cli
@@ -1620,11 +1618,6 @@ module MarkdownExec
1620
1618
  bm = extract_named_captures_from_option(titlexcall,
1621
1619
  @delegate_object[:block_name_match])
1622
1620
 
1623
- fcb.stdin = extract_named_captures_from_option(titlexcall,
1624
- @delegate_object[:block_stdin_scan])
1625
- fcb.stdout = extract_named_captures_from_option(titlexcall,
1626
- @delegate_object[:block_stdout_scan])
1627
-
1628
1621
  shell_color_option = SHELL_COLOR_OPTIONS[fcb[:shell]]
1629
1622
 
1630
1623
  if @delegate_object[:block_name_nick_match].present? && fcb.oname =~ Regexp.new(@delegate_object[:block_name_nick_match])
@@ -1695,7 +1688,6 @@ module MarkdownExec
1695
1688
 
1696
1689
  def inpseq_execute_block(block_name)
1697
1690
  @dml_block_state = block_state_for_name_from_cli(block_name)
1698
-
1699
1691
  dump_and_warn_block_state(selected: @dml_block_state.block)
1700
1692
  @dml_link_state, @dml_menu_default_dname = \
1701
1693
  exec_bash_next_state(
@@ -1760,8 +1752,11 @@ module MarkdownExec
1760
1752
  file.rewind
1761
1753
 
1762
1754
  if link_block_data.fetch(LinkKeys::EXEC, false)
1763
- @run_state.files = Hash.new([])
1764
- execute_command_with_streams([cmd])
1755
+ run_state_reset_stream_logs
1756
+ execute_command_with_streams([cmd]) do |_stdin, stdout, stderr, _thread|
1757
+ line = stdout || stderr
1758
+ output_lines.push(line) if line
1759
+ end
1765
1760
 
1766
1761
  ## select output_lines that look like assignment or match other specs
1767
1762
  #
@@ -1828,7 +1823,6 @@ module MarkdownExec
1828
1823
  document_filename: File.basename(@delegate_object[:filename]),
1829
1824
  document_filespec: @delegate_object[:filename],
1830
1825
  home: Dir.pwd,
1831
- # rest: '',
1832
1826
  started_at: Time.now.utc.strftime(@delegate_object[:execute_command_title_time_format])
1833
1827
  }
1834
1828
  end
@@ -1882,44 +1876,6 @@ module MarkdownExec
1882
1876
  expanded_expression
1883
1877
  end
1884
1878
  end
1885
-
1886
- # private
1887
-
1888
- # def read_block_name(line)
1889
- # bm = extract_named_captures_from_option(line, @delegate_object[:block_name_match])
1890
- # name = bm[:title]
1891
-
1892
- # if @delegate_object[:block_name_nick_match].present? && line =~ Regexp.new(@delegate_object[:block_name_nick_match])
1893
- # name = $~[0]
1894
- # else
1895
- # name = bm && bm[1] ? bm[:title] : name
1896
- # end
1897
- # name
1898
- # end
1899
-
1900
- # # Loads auto link block.
1901
- # def load_auto_link_block(all_blocks, link_state, mdoc, block_source:)
1902
- # block_name = @delegate_object[:document_load_link_block_name]
1903
- # return unless block_name.present? && @most_recent_loaded_filename != @delegate_object[:filename]
1904
-
1905
- # block = HashDelegator.block_find(all_blocks, :oname, block_name)
1906
- # return unless block
1907
-
1908
- # if block.fetch(:shell, '') != BlockType::LINK
1909
- # HashDelegator.error_handler('must be Link block type', { abort: true })
1910
-
1911
- # else
1912
- # # debounce_reset
1913
- # push_link_history_and_trigger_load(
1914
- # link_block_body: block.fetch(:body, ''),
1915
- # mdoc: mdoc,
1916
- # selected: block,
1917
- # link_state: link_state,
1918
- # block_source: block_source
1919
- # )
1920
- # end
1921
- # end
1922
-
1923
1879
  # Handle expression with wildcard characters
1924
1880
  def load_filespec_wildcard_expansion(expr, auto_load_single: false)
1925
1881
  files = find_files(expr)
@@ -1955,7 +1911,6 @@ module MarkdownExec
1955
1911
  # recreate menu with new options
1956
1912
  #
1957
1913
  all_blocks, mdoc = mdoc_and_blocks_from_nested_files if load_auto_opts_block(all_blocks)
1958
- # load_auto_link_block(all_blocks, link_state, mdoc, block_source: {})
1959
1914
 
1960
1915
  menu_blocks = mdoc.fcbs_per_options(@delegate_object)
1961
1916
  add_menu_chrome_blocks!(menu_blocks: menu_blocks, link_state: link_state)
@@ -2074,7 +2029,7 @@ module MarkdownExec
2074
2029
  @fout.fout formatted_string
2075
2030
  end
2076
2031
 
2077
- def output_execution_result
2032
+ def fout_execution_report
2078
2033
  @fout.fout fetch_color(data_sym: :execution_report_preview_head,
2079
2034
  color_sym: :execution_report_preview_frame_color)
2080
2035
  [
@@ -2121,7 +2076,7 @@ module MarkdownExec
2121
2076
  end
2122
2077
 
2123
2078
  def pop_add_current_code_to_head_and_trigger_load(link_state, block_names, code_lines,
2124
- dependencies, selected)
2079
+ dependencies, selected, next_block_name: nil)
2125
2080
  pop = @link_history.pop # updatable
2126
2081
  if pop.document_filename
2127
2082
  next_state = LinkState.new(
@@ -2146,7 +2101,7 @@ module MarkdownExec
2146
2101
  inherited_block_names: ((link_state&.inherited_block_names || []) + block_names).sort.uniq,
2147
2102
  inherited_dependencies: (link_state&.inherited_dependencies || {}).merge(dependencies || {}), ### merge, not replace, key data
2148
2103
  inherited_lines: HashDelegator.code_merge(link_state&.inherited_lines, code_lines),
2149
- next_block_name: '', # not link_block_data[LinkKeys::BLOCK] || ''
2104
+ next_block_name: next_block_name,
2150
2105
  next_document_filename: @delegate_object[:filename], # not next_document_filename
2151
2106
  next_load_file: LoadFile::REUSE # not next_document_filename == @delegate_object[:filename] ? LoadFile::REUSE : LoadFile::LOAD
2152
2107
  )
@@ -2172,7 +2127,7 @@ module MarkdownExec
2172
2127
  def post_execution_process
2173
2128
  do_save_execution_output
2174
2129
  output_execution_summary
2175
- output_execution_result
2130
+ fout_execution_report if @delegate_object[:output_execution_report]
2176
2131
  end
2177
2132
 
2178
2133
  # Prepare the blocks menu by adding labels and other necessary details.
@@ -2424,7 +2379,7 @@ module MarkdownExec
2424
2379
  end
2425
2380
  end
2426
2381
 
2427
- ## append blocks loaded, apply LinkKeys::EVAL
2382
+ ## append blocks loaded
2428
2383
  #
2429
2384
  if (load_expr = link_block_data.fetch(LinkKeys::LOAD, '')).present?
2430
2385
  load_filespec = load_filespec_from_expression(load_expr)
@@ -2439,10 +2394,11 @@ module MarkdownExec
2439
2394
  end
2440
2395
 
2441
2396
  next_document_filename = write_inherited_lines_to_file(link_state, link_block_data)
2397
+ next_block_name = link_block_data.fetch(LinkKeys::NEXT_BLOCK, nil) || link_block_data.fetch(LinkKeys::BLOCK, nil) || ''
2442
2398
 
2443
2399
  if link_block_data[LinkKeys::RETURN]
2444
2400
  pop_add_current_code_to_head_and_trigger_load(link_state, block_names, code_lines,
2445
- dependencies, selected)
2401
+ dependencies, selected, next_block_name: next_block_name)
2446
2402
 
2447
2403
  else
2448
2404
  link_history_push_and_next(
@@ -2451,8 +2407,7 @@ module MarkdownExec
2451
2407
  inherited_block_names: ((link_state&.inherited_block_names || []) + block_names).sort.uniq,
2452
2408
  inherited_dependencies: (link_state&.inherited_dependencies || {}).merge(dependencies || {}), ### merge, not replace, key data
2453
2409
  inherited_lines: HashDelegator.code_merge(link_state&.inherited_lines, code_lines),
2454
- next_block_name: link_block_data.fetch(LinkKeys::NEXT_BLOCK,
2455
- nil) || link_block_data[LinkKeys::BLOCK] || '',
2410
+ next_block_name: next_block_name,
2456
2411
  next_document_filename: next_document_filename,
2457
2412
  next_load_file: next_document_filename == @delegate_object[:filename] ? LoadFile::REUSE : LoadFile::LOAD
2458
2413
  )
@@ -2538,6 +2493,13 @@ module MarkdownExec
2538
2493
  end
2539
2494
  end
2540
2495
 
2496
+ def run_state_reset_stream_logs
2497
+ @run_state.files = Hash.new()
2498
+ @run_state.files[ExecutionStreams::STD_ERR] = []
2499
+ @run_state.files[ExecutionStreams::STD_IN] = []
2500
+ @run_state.files[ExecutionStreams::STD_OUT] = []
2501
+ end
2502
+
2541
2503
  def runtime_exception(exception_sym, name, items)
2542
2504
  if @delegate_object[exception_sym] != 0
2543
2505
  data = { name: name, detail: items.join(', ') }
@@ -2709,9 +2671,13 @@ module MarkdownExec
2709
2671
  dname = oname = title = fcb_title_groups.fetch(:name, '')
2710
2672
  end
2711
2673
 
2674
+ # disable fcb for data blocks
2675
+ disabled = fcb_title_groups.fetch(:shell, '') == 'yaml' ? '' : nil
2676
+
2712
2677
  MarkdownExec::FCB.new(
2713
2678
  body: [],
2714
2679
  call: rest.match(Regexp.new(@delegate_object[:block_calls_scan]))&.to_a&.first,
2680
+ disabled: disabled,
2715
2681
  dname: dname,
2716
2682
  headings: headings,
2717
2683
  indent: fcb_title_groups.fetch(:indent, ''),
@@ -2939,21 +2905,6 @@ module MarkdownExec
2939
2905
 
2940
2906
  def self.next_link_state(*args, **kwargs, &block)
2941
2907
  super
2942
- # result = super
2943
-
2944
- # @logger ||= StdOutErrLogger.new
2945
- # @logger.unknown(
2946
- # HashDelegator.clean_hash_recursively(
2947
- # { "HashDelegator.next_link_state":
2948
- # { 'args': args,
2949
- # 'at': Time.now.strftime('%FT%TZ'),
2950
- # 'for': /[^\/]+:\d+/.match(caller.first)[0],
2951
- # 'kwargs': kwargs,
2952
- # 'return': result } }
2953
- # )
2954
- # )
2955
-
2956
- # result
2957
2908
  end
2958
2909
  end
2959
2910
  end
@@ -3466,7 +3417,7 @@ module MarkdownExec
3466
3417
  end
3467
3418
 
3468
3419
  def test_format_execution_streams_with_valid_key
3469
- result = HashDelegator.format_execution_streams(:stdout,
3420
+ result = HashDelegator.format_execution_streams(ExecutionStreams::STD_OUT,
3470
3421
  { stdout: %w[output1 output2] })
3471
3422
 
3472
3423
  assert_equal 'output1output2', result
@@ -3475,7 +3426,7 @@ module MarkdownExec
3475
3426
  def test_format_execution_streams_with_empty_key
3476
3427
  @hd.instance_variable_get(:@run_state).stubs(:files).returns({})
3477
3428
 
3478
- result = HashDelegator.format_execution_streams(:stderr)
3429
+ result = HashDelegator.format_execution_streams(ExecutionStreams::STD_ERR)
3479
3430
 
3480
3431
  assert_equal '', result
3481
3432
  end
@@ -3598,19 +3549,19 @@ module MarkdownExec
3598
3549
 
3599
3550
  def test_handle_stream
3600
3551
  stream = StringIO.new("line 1\nline 2\n")
3601
- file_type = :stdout
3552
+ file_type = ExecutionStreams::STD_OUT
3602
3553
 
3603
3554
  Thread.new { @hd.handle_stream(stream: stream, file_type: file_type) }
3604
3555
 
3605
3556
  @hd.wait_for_stream_processing
3606
3557
 
3607
3558
  assert_equal ['line 1', 'line 2'],
3608
- @hd.instance_variable_get(:@run_state).files[:stdout]
3559
+ @hd.instance_variable_get(:@run_state).files[ExecutionStreams::STD_OUT]
3609
3560
  end
3610
3561
 
3611
3562
  def test_handle_stream_with_io_error
3612
3563
  stream = StringIO.new("line 1\nline 2\n")
3613
- file_type = :stdout
3564
+ file_type = ExecutionStreams::STD_OUT
3614
3565
  stream.stubs(:each_line).raises(IOError)
3615
3566
 
3616
3567
  Thread.new { @hd.handle_stream(stream: stream, file_type: file_type) }
@@ -3618,7 +3569,7 @@ module MarkdownExec
3618
3569
  @hd.wait_for_stream_processing
3619
3570
 
3620
3571
  assert_equal [],
3621
- @hd.instance_variable_get(:@run_state).files[:stdout]
3572
+ @hd.instance_variable_get(:@run_state).files[ExecutionStreams::STD_OUT]
3622
3573
  end
3623
3574
  end
3624
3575
 
@@ -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 = '2.0.8.2'
10
+ VERSION = '2.0.8.4'
11
11
  end
data/lib/mdoc.rb CHANGED
@@ -53,6 +53,17 @@ module MarkdownExec
53
53
  end
54
54
  end
55
55
 
56
+ # Collects and formats the shell command output to redirect script block code to a file or a variable.
57
+ #
58
+ # @param [Hash] fcb A hash containing information about the script block's stdout and body.
59
+ # @option fcb [Hash] :stdout A hash specifying the stdout details.
60
+ # @option stdout [Boolean] :type Indicates whether to export to a variable (true) or to write to a file (false).
61
+ # @option stdout [String] :name The name of the variable or file to which the body will be output.
62
+ # @option fcb [Array<String>] :body An array of strings representing the lines of the script block's body.
63
+ #
64
+ # @return [String] A string containing the formatted shell command to output the script block's body.
65
+ # If stdout[:type] is true, the command will export the body to a shell variable.
66
+ # If stdout[:type] is false, the command will write the body to a file.
56
67
  def collect_block_code_stdout(fcb)
57
68
  stdout = fcb[:stdout]
58
69
  body = fcb[:body].join("\n")
data/lib/menu.src.yml CHANGED
@@ -64,6 +64,7 @@
64
64
  :procname: val_as_str
65
65
 
66
66
  - :default: ">(?<full>(?<type>\\$)?(?<name>[A-Za-z_\\-\\.\\w]+))"
67
+ :description: Match to place block body into a file or a variable
67
68
  :env_var: MDE_BLOCK_STDOUT_SCAN
68
69
  :opt_name: block_stdout_scan
69
70
  :procname: val_as_str
@@ -106,12 +107,6 @@
106
107
  :opt_name: display_level_xbase_prefix
107
108
  :procname: val_as_str
108
109
 
109
- # - :default: "(document_link)"
110
- # :description: Name of Link block to load with the document
111
- # :env_var: MDE_DOCUMENT_LOAD_LINK_BLOCK_NAME
112
- # :opt_name: document_load_link_block_name
113
- # :procname: val_as_str
114
-
115
110
  - :default: "(document_options)"
116
111
  :description: Name of Opts block to load with the document
117
112
  :env_var: MDE_DOCUMENT_LOAD_OPTS_BLOCK_NAME
@@ -868,6 +863,13 @@
868
863
  :opt_name: output_execution_label_value_color
869
864
  :procname: val_as_str
870
865
 
866
+ - :arg_name: BOOL
867
+ :default: true
868
+ :description: Output execution report at end of execution
869
+ :env_var: MDE_OUTPUT_EXECUTION_REPORT
870
+ :opt_name: output_execution_report
871
+ :procname: val_as_bool
872
+
871
873
  - :arg_name: BOOL
872
874
  :default: false
873
875
  :description: Output saved script filename at end of execution
data/lib/menu.yml CHANGED
@@ -53,6 +53,7 @@
53
53
  :opt_name: block_stdin_scan
54
54
  :procname: val_as_str
55
55
  - :default: ">(?<full>(?<type>\\$)?(?<name>[A-Za-z_\\-\\.\\w]+))"
56
+ :description: Match to place block body into a file or a variable
56
57
  :env_var: MDE_BLOCK_STDOUT_SCAN
57
58
  :opt_name: block_stdout_scan
58
59
  :procname: val_as_str
@@ -726,6 +727,12 @@
726
727
  :env_var: MDE_OUTPUT_EXECUTION_LABEL_VALUE_COLOR
727
728
  :opt_name: output_execution_label_value_color
728
729
  :procname: val_as_str
730
+ - :arg_name: BOOL
731
+ :default: true
732
+ :description: Output execution report at end of execution
733
+ :env_var: MDE_OUTPUT_EXECUTION_REPORT
734
+ :opt_name: output_execution_report
735
+ :procname: val_as_bool
729
736
  - :arg_name: BOOL
730
737
  :default: false
731
738
  :description: Output saved script filename at end of execution
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: 2.0.8.2
4
+ version: 2.0.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fareed Stevenson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-07 00:00:00.000000000 Z
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard