markdown_exec 3.0.0 → 3.0.2

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: 5fce77c3fa5686b583f500f1f5afafcb21903c323dcb5466662130e240581957
4
- data.tar.gz: 0cb414335a8df51349d7fac27da3ab7d1b79af81af8f104605d1c2158b8067cc
3
+ metadata.gz: 7e95733b82149c0ae79c429132f53373975961457c9fc6dd6b5f4feed5618d63
4
+ data.tar.gz: bfc880428a6cb6e3f58f3248972fffdbe2a51449c3e12ee1b4542aee0148fa29
5
5
  SHA512:
6
- metadata.gz: ef7aed19a54e257e07dee6d7b9cef11062c68fb35aad42bcba9a33584086eb7b1016523dc013bb2bc88c34d0349190d4f9ca9b2e524daf086e4eae4bbf8b4d5b
7
- data.tar.gz: '08530d2e5f303fd6743dcbf9aaec45f375c91e4895541e4a466621401c4147954c498c4c72c570b1e2a34faee9bcfa58fe1434708c44b55f749fff854a54f4dd'
6
+ metadata.gz: d24fdac6f00933c9796fe8225c81d35745d2275055b8963b565955a4a9a581e232ddc99e67999e8b00053ecb573ae4e24be8875506d6257b645d4eea74661b40
7
+ data.tar.gz: 10423e9faec308472a9678b7726c78c5b0be55a702c866e6b4cbe722f6aa6f69cae80ed9a30857f08c60dae792fc70062ebb7a16fd3728d0bc289b9487bc3a98
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [3.0.2] - 2025-05-21
4
+
5
+ ### Added
6
+
7
+ - Options to permit the archiving of ad-hoc shell scripts.
8
+
9
+ ### Changed
10
+
11
+ - Force use of Bash shell for ad-hoc shell scripts.
12
+
13
+ ## [3.0.1] - 2025-05-21
14
+
15
+ ### Changed
16
+
17
+ - Block ids to reflect source file when imported.
18
+ - Disable UX block warnings for initial values.
19
+
3
20
  ## [3.0.0] - 2025-05-20
4
21
 
5
22
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- markdown_exec (3.0.0)
4
+ markdown_exec (3.0.2)
5
5
  clipboard (~> 1.3.6)
6
6
  open3 (~> 0.1.1)
7
7
  optparse (~> 0.1.1)
@@ -4,5 +4,5 @@ load 'test_helper'
4
4
 
5
5
  @test 'automatic block is invalid YAML' {
6
6
  spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-invalid.md \
7
- '_Error: HashDelegator../docs/dev/block-type-ux-invalid.md¤ItrBlkFrmNstFls:1 - --- !ruby/object:NullResult_message: Invalid YAML_data: invalid_ -- -- '
7
+ '_Error: HashDelegator.ItrBlkFrmNstFls:1¤./docs/dev/block-type-ux-invalid.md:1 - --- !ruby/object:NullResult_message: Invalid YAML_data: invalid_ -- -- '
8
8
  }
@@ -2,7 +2,19 @@
2
2
 
3
3
  load 'test_helper'
4
4
 
5
- @test 'An undefined variable is a precondition' {
5
+ @test 'An undefined variable is a precondition - initial' {
6
6
  spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-required-variables.md \
7
- 'A value must exist for: MISSING_VARIABLE_SPECIES='
7
+ 'SPECIES='
8
8
  }
9
+
10
+ # hangs
11
+ # Enter a value: []: #<Errno::EISDIR: Is a directory @ io_fillbuf - fd:12 test>
12
+ # ["/Users/fareed/Documents/dev/ruby/markdown_exec/lib/hash_delegator.rb:4650:in `gets'",
13
+ # "/Users/fareed/Documents/dev/ruby/markdown_exec/lib/hash_delegator.rb:4650:in `gets'",
14
+ # "/Users/fareed/Documents/dev/ruby/markdown_exec/lib/hash_delegator.rb:4650:in `block in ux_block_export_activated'",
15
+ #
16
+ #@test 'An undefined variable is a precondition - active' {
17
+ # spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-required-variables.md \
18
+ # test \
19
+ # 'A value must exist for: MISSING_VARIABLE_SPECIES='
20
+ #}
data/bats/import.bats CHANGED
@@ -14,3 +14,11 @@ load 'test_helper'
14
14
  spec_mde_args_expect docs/dev/import-missing.md \
15
15
  ' Error: CachedNestedFileReader.readlines -- No such file or directory - this-is-missing.md @@ '
16
16
  }
17
+
18
+ @test 'Directives - import; list block ids' {
19
+ BATS_OUTPUT_FILTER=A
20
+ BATS_SAFE=_
21
+ spec_mde_args_expect docs/dev/import.md \
22
+ --list-block-message id --list-blocks \
23
+ 'ItrBlkFrmNstFls:1¤./docs/dev/specs-import.md:0_ItrBlkFrmNstFls:4¤./docs/dev/specs-import.md:3_ItrBlkFrmNstFls:7¤./docs/dev/specs-import.md:6'
24
+ }
@@ -1,5 +1,5 @@
1
1
  / an automatic UX block that has a precondition that must be met before it is executed
2
- ```ux :[document_ux_SPECIES]
2
+ ```ux :test
3
3
  exec: printf "$MISSING_VARIABLE"
4
4
  name: SPECIES
5
5
  required:
@@ -39,6 +39,8 @@ class CachedNestedFileReader
39
39
  )
40
40
  end
41
41
 
42
+ # yield each line to the block
43
+ # return the processed lines
42
44
  def readlines(filename, depth = 0, context: '', import_paths: nil,
43
45
  indention: '', &block)
44
46
  if @file_cache.key?(filename)
@@ -70,7 +72,7 @@ class CachedNestedFileReader
70
72
  indention: import_indention,
71
73
  &block)
72
74
  else
73
- nested_line = NestedLine.new(line, depth, indention)
75
+ nested_line = NestedLine.new(line, depth, indention, filename, ind)
74
76
  processed_lines.push(nested_line)
75
77
  block&.call(nested_line)
76
78
  end
data/lib/constants.rb CHANGED
@@ -92,7 +92,7 @@ class MenuState
92
92
  end
93
93
 
94
94
  # a struct to hold the data for a single line
95
- NestedLine = Struct.new(:text, :depth, :indention) do
95
+ NestedLine = Struct.new(:text, :depth, :indention, :filename, :index) do
96
96
  def to_s
97
97
  indention + text
98
98
  end
@@ -1098,7 +1098,8 @@ module MarkdownExec
1098
1098
  block,
1099
1099
  mdoc,
1100
1100
  force: @delegate_object[:ux_auto_load_force_default],
1101
- only_default: true
1101
+ only_default: true,
1102
+ silent: true
1102
1103
  )
1103
1104
  if command_result_w_e_t_nl.failure?
1104
1105
  merged_options
@@ -1111,7 +1112,8 @@ module MarkdownExec
1111
1112
  # parse YAML body defining the UX for a single variable
1112
1113
  # set ENV value for the variable and return code lines for the same
1113
1114
  def code_from_ux_block_to_set_environment_variables(
1114
- selected, mdoc, inherited_code: nil, force: true, only_default: false
1115
+ selected, mdoc, inherited_code: nil, force: true, only_default: false,
1116
+ silent:
1115
1117
  )
1116
1118
  exit_prompt = @delegate_object[:prompt_filespec_back]
1117
1119
 
@@ -1161,7 +1163,7 @@ module MarkdownExec
1161
1163
  command_result_w_e_t_nl =
1162
1164
  ux_block_export_activated(eval_code, export, exit_prompt)
1163
1165
  if command_result_w_e_t_nl.failure?
1164
- warn command_result_w_e_t_nl.warning if command_result_w_e_t_nl.warning&.present?
1166
+ warn command_result_w_e_t_nl.warning if command_result_w_e_t_nl.warning&.present? && !silent
1165
1167
  return command_result_w_e_t_nl
1166
1168
  end
1167
1169
  end
@@ -2019,7 +2021,8 @@ module MarkdownExec
2019
2021
  command_result_w_e_t_nl = code_from_ux_block_to_set_environment_variables(
2020
2022
  selected,
2021
2023
  @dml_mdoc,
2022
- inherited_code: @dml_link_state.inherited_lines
2024
+ inherited_code: @dml_link_state.inherited_lines,
2025
+ silent: true
2023
2026
  )
2024
2027
  ### TBD if command_result_w_e_t_nl.failure?
2025
2028
  next_state_append_code(
@@ -2581,7 +2584,7 @@ module MarkdownExec
2581
2584
  end
2582
2585
 
2583
2586
  def export_echo_with_code(
2584
- bash_script_lines, export, force:
2587
+ bash_script_lines, export, force:, silent:
2585
2588
  )
2586
2589
  exportable = true
2587
2590
  command_result = nil
@@ -2596,7 +2599,7 @@ module MarkdownExec
2596
2599
  )
2597
2600
  if command_result.exit_status == EXIT_STATUS_REQUIRED_EMPTY
2598
2601
  exportable = false
2599
- command_result.warning = warning_required_empty(export)
2602
+ command_result.warning = warning_required_empty(export) unless silent
2600
2603
  end
2601
2604
 
2602
2605
  when Hash
@@ -2609,7 +2612,7 @@ module MarkdownExec
2609
2612
  )
2610
2613
  )
2611
2614
  if command_result.exit_status == EXIT_STATUS_REQUIRED_EMPTY
2612
- command_result.warning = warning_required_empty(export)
2615
+ command_result.warning = warning_required_empty(export) unless silent
2613
2616
  else
2614
2617
  ENV[name] = command_result.stdout.to_s
2615
2618
  new_lines << code_line_safe_assign(name, command_result.stdout,
@@ -2937,17 +2940,20 @@ module MarkdownExec
2937
2940
 
2938
2941
  state = initial_state
2939
2942
  selected_types = yield :filter
2943
+ index = 0
2940
2944
  cfile.readlines(
2941
2945
  @delegate_object[:filename],
2942
2946
  import_paths: options_import_paths
2943
- ).each_with_index do |nested_line, index|
2944
- next unless nested_line
2947
+ ) do |nested_line|
2948
+ next if nested_line.nil?
2945
2949
 
2946
2950
  update_line_and_block_state(
2947
2951
  nested_line, state, selected_types,
2948
- source_id: "#{@delegate_object[:filename]}¤ItrBlkFrmNstFls:#{index}",
2952
+ source_id: "ItrBlkFrmNstFls:#{index}¤#{nested_line.filename}:#{nested_line.index}",
2949
2953
  &block
2950
2954
  )
2955
+
2956
+ index += 1
2951
2957
  end
2952
2958
  end
2953
2959
 
@@ -2962,10 +2968,8 @@ module MarkdownExec
2962
2968
  else
2963
2969
  iter_blocks_from_nested_files do |btype, fcb|
2964
2970
  case btype
2965
- when :blocks
2966
- yield fcb
2967
- when :filter
2968
- %i[blocks]
2971
+ when :blocks; yield fcb
2972
+ when :filter; %i[blocks]
2969
2973
  end
2970
2974
  end
2971
2975
  end
@@ -3010,7 +3014,7 @@ module MarkdownExec
3010
3014
  )
3011
3015
 
3012
3016
  else
3013
- output_lines = `#{cmd}`.split("\n")
3017
+ output_lines = `bash #{file.path}`.split("\n")
3014
3018
  end
3015
3019
  end
3016
3020
 
@@ -3564,11 +3568,24 @@ module MarkdownExec
3564
3568
 
3565
3569
  def output_from_adhoc_bash_script_file(bash_script_lines)
3566
3570
  Tempfile.create('script_exec') do |temp_file|
3567
- temp_file.write(HashDelegator.join_code_lines(bash_script_lines))
3568
- temp_file.flush
3571
+ temp_file.write(
3572
+ HashDelegator.join_code_lines(
3573
+ bash_script_lines
3574
+ )
3575
+ )
3576
+ temp_file.close # Close the file before chmod and execution
3569
3577
  File.chmod(0o755, temp_file.path)
3570
3578
 
3571
- output = `#{temp_file.path}`
3579
+ if @delegate_object[:archive_ad_hoc_scripts]
3580
+ archive_filename = format(
3581
+ @delegate_object[:archive_path_format],
3582
+ time: Time.now.strftime(@delegate_object[:archive_time_format])
3583
+ )
3584
+ `cp #{temp_file.path} #{archive_filename}`
3585
+ end
3586
+
3587
+ output = `bash #{temp_file.path}`
3588
+ #### use shell per configuration
3572
3589
 
3573
3590
  CommandResult.new(stdout: output, exit_status: $?.exitstatus)
3574
3591
  end
@@ -4587,7 +4604,7 @@ module MarkdownExec
4587
4604
  new_lines = []
4588
4605
  command_result = nil
4589
4606
 
4590
- case as = FCB.act_source(export)####
4607
+ case as = FCB.act_source(export)
4591
4608
  when false, UxActSource::FALSE
4592
4609
  raise 'Should not be reached.'
4593
4610
 
@@ -4599,7 +4616,8 @@ module MarkdownExec
4599
4616
  command_result, exportable, new_lines = export_echo_with_code(
4600
4617
  bash_script_lines,
4601
4618
  export,
4602
- force: true
4619
+ force: true,
4620
+ silent: false
4603
4621
  )
4604
4622
  if command_result.failure?
4605
4623
  command_result
@@ -4634,7 +4652,8 @@ module MarkdownExec
4634
4652
  command_result, exportable, new_lines = export_echo_with_code(
4635
4653
  bash_script_lines,
4636
4654
  export,
4637
- force: true
4655
+ force: true,
4656
+ silent: false
4638
4657
  )
4639
4658
 
4640
4659
  command_result
@@ -4688,6 +4707,7 @@ module MarkdownExec
4688
4707
  exportable = true
4689
4708
  new_lines = []
4690
4709
  command_result = nil
4710
+ silent = true
4691
4711
 
4692
4712
  case FCB.init_source(export)
4693
4713
  when false, UxActSource::FALSE
@@ -4703,7 +4723,8 @@ module MarkdownExec
4703
4723
  command_result, exportable, new_lines = export_echo_with_code(
4704
4724
  bash_script_lines,
4705
4725
  export,
4706
- force: false
4726
+ force: false,
4727
+ silent: silent
4707
4728
  )
4708
4729
  unless command_result.failure?
4709
4730
  command_result.stdout = (exportable && command_result.stdout.split("\n").first) || ''
@@ -4732,7 +4753,8 @@ module MarkdownExec
4732
4753
  command_result, exportable, new_lines = export_echo_with_code(
4733
4754
  bash_script_lines,
4734
4755
  export,
4735
- force: false
4756
+ force: false,
4757
+ silent: silent
4736
4758
  )
4737
4759
 
4738
4760
  when ':exec', UxActSource::EXEC
@@ -4750,7 +4772,7 @@ module MarkdownExec
4750
4772
  # add message for required variables
4751
4773
  if command_result.exit_status == EXIT_STATUS_REQUIRED_EMPTY
4752
4774
  command_result.warning = warning_required_empty(export)
4753
- warn command_result.warning
4775
+ warn command_result.warning unless silent
4754
4776
  end
4755
4777
 
4756
4778
  command_result.exportable = exportable
@@ -5198,6 +5220,7 @@ module MarkdownExec
5198
5220
  mdoc_menu_and_blocks_from_nested_files(
5199
5221
  @dml_link_state, source_id: source_id
5200
5222
  )
5223
+
5201
5224
  dump_delobj(@dml_blocks_in_file, @dml_menu_blocks, @dml_link_state)
5202
5225
  end
5203
5226
 
@@ -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.0'
10
+ VERSION = '3.0.2'
11
11
  end
data/lib/menu.src.yml CHANGED
@@ -4,6 +4,25 @@
4
4
  :description: Show current configuration values
5
5
  :procname: show_config
6
6
 
7
+ - :opt_name: archive_ad_hoc_scripts
8
+ :env_var: MDE_ARCHIVE_AD_HOC_SCRIPTS
9
+ :description: Archive ad-hoc bash scripts
10
+ :arg_name: BOOL
11
+ :default: false
12
+ :procname: val_as_bool
13
+
14
+ - :opt_name: archive_time_format
15
+ :env_var: MDE_ARCHIVE_TIME_FORMAT
16
+ :description: Time format for archive filenames
17
+ :default: '%Y-%m-%d-%H-%M-%S-%N'
18
+ :procname: val_as_str
19
+
20
+ - :opt_name: archive_path_format
21
+ :env_var: MDE_ARCHIVE_PATH_FORMAT
22
+ :description: Format for archive file paths
23
+ :default: '/tmp/mde-ad-hoc-%{time}'
24
+ :procname: val_as_str
25
+
7
26
  - :opt_name: bash_only
8
27
  :env_var: MDE_BASH_ONLY
9
28
  :description: Execute only blocks of type "bash"
data/lib/menu.yml CHANGED
@@ -2,6 +2,22 @@
2
2
  - :short_name: '0'
3
3
  :description: Show current configuration values
4
4
  :procname: show_config
5
+ - :opt_name: archive_ad_hoc_scripts
6
+ :env_var: MDE_ARCHIVE_AD_HOC_SCRIPTS
7
+ :description: Archive ad-hoc bash scripts
8
+ :arg_name: BOOL
9
+ :default: false
10
+ :procname: val_as_bool
11
+ - :opt_name: archive_time_format
12
+ :env_var: MDE_ARCHIVE_TIME_FORMAT
13
+ :description: Time format for archive filenames
14
+ :default: "%Y-%m-%d-%H-%M-%S-%N"
15
+ :procname: val_as_str
16
+ - :opt_name: archive_path_format
17
+ :env_var: MDE_ARCHIVE_PATH_FORMAT
18
+ :description: Format for archive file paths
19
+ :default: "/tmp/mde-ad-hoc-%{time}"
20
+ :procname: val_as_str
5
21
  - :opt_name: bash_only
6
22
  :env_var: MDE_BASH_ONLY
7
23
  :description: Execute only blocks of type "bash"
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.0
4
+ version: 3.0.2
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-05-20 00:00:00.000000000 Z
11
+ date: 2025-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard