markdown_exec 3.0.3 → 3.0.5
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 +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +1 -1
- data/bats/block-type-ux-echo-hash-transform.bats +8 -0
- data/bats/block-type-ux-echo.bats +2 -1
- data/docs/dev/block-type-ux-echo-hash-transform.md +40 -0
- data/docs/dev/block-type-ux-echo.md +3 -0
- data/lib/hash_delegator.rb +55 -33
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/mdoc.rb +9 -6
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3f36dcdba359857aa80f8888d8eaf61e5d2675952a5809341bd993cf30c9ef1
|
4
|
+
data.tar.gz: cc753bd25f2b229b6c3d7bab99249c2b6786e4b3efa3ca56c098ff4838f9ad78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f982dcfa66c59168f8cdf6b1d9d5fc9af2b946f8d9dc42b4d8af9061bb94758784916f1d2afafe7bb215f60d8588900aff43132a8418199f19abbb1b033087cc
|
7
|
+
data.tar.gz: a7219bde3d387303ca86ea096dc9fbcb059c028c74d9bff1696d9f6bb2d8b77715e9080aec424e4ea35a53462fe895ea6210e930ab6d6a1129172fd95f6a9312
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [3.0.5] - 2025-05-23
|
4
|
+
|
5
|
+
### Changed
|
6
|
+
|
7
|
+
- Values for UX echo are validated and transformed.
|
8
|
+
|
9
|
+
## [3.0.4] - 2025-05-28
|
10
|
+
|
11
|
+
### Changed
|
12
|
+
|
13
|
+
- Apply shell option when not specified for a block.
|
14
|
+
|
3
15
|
## [3.0.3] - 2025-05-23
|
4
16
|
|
5
17
|
### Changed
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env bats
|
2
|
+
|
3
|
+
load 'test_helper'
|
4
|
+
|
5
|
+
@test 'Each key in the echo hash is processed.' {
|
6
|
+
spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-echo-hash-transform.md \
|
7
|
+
'Tapanuli Orangutan_Species: PONGO TAPANULIENSIS_Genus: PONGO_Tapanuli Orangutan_Family: H:Hominidae_Order: P:Primates'
|
8
|
+
}
|
@@ -10,7 +10,8 @@ load 'test_helper'
|
|
10
10
|
@test 'inherited lines' {
|
11
11
|
spec_mde_xansi_dname_doc_blocks_expect docs/dev/block-type-ux-echo.md \
|
12
12
|
'(menu_with_inherited_lines)' \
|
13
|
-
'VAR=
|
13
|
+
'VAR=markdown_exec_IAB='
|
14
|
+
# 'VAR=markdown_exec_VAR=markdown_exec_IAB='
|
14
15
|
}
|
15
16
|
|
16
17
|
@test 'selected block - output of wc includes whitespace' {
|
@@ -0,0 +1,40 @@
|
|
1
|
+
/ Each key in the echo hash is processed.
|
2
|
+
/
|
3
|
+
/ Each value is transformed.
|
4
|
+
```ux
|
5
|
+
echo:
|
6
|
+
Species: Pongo tapanuliensis
|
7
|
+
Genus: Pongo
|
8
|
+
format: Tapanuli Orangutan
|
9
|
+
name: Species
|
10
|
+
transform: :upcase
|
11
|
+
```
|
12
|
+
Species: ${Species}
|
13
|
+
Genus: ${Genus}
|
14
|
+
/
|
15
|
+
/ Each value is validated and transformed.
|
16
|
+
```ux
|
17
|
+
echo:
|
18
|
+
Family: Hominidae
|
19
|
+
Order: Primates
|
20
|
+
format: Tapanuli Orangutan
|
21
|
+
name: Family
|
22
|
+
transform: '%{capital}:%{name}'
|
23
|
+
validate: >
|
24
|
+
^(?<name>(?<capital>.?).*)$
|
25
|
+
```
|
26
|
+
Family: ${Family}
|
27
|
+
Order: ${Order}
|
28
|
+
//
|
29
|
+
// Each key in the exec hash is processed.
|
30
|
+
/```ux
|
31
|
+
/exec:
|
32
|
+
/ Species2: printf %s 'Histiophryne psychedelica'
|
33
|
+
/ Genus2: printf %s 'Histiophryne'
|
34
|
+
/format: Psychedelic Frogfish
|
35
|
+
/name: Species2
|
36
|
+
/transform: :downcase
|
37
|
+
/```
|
38
|
+
/Species2: ${Species2}
|
39
|
+
/Genus2: ${Genus2}
|
40
|
+
@import bats-document-configuration.md
|
data/lib/hash_delegator.rb
CHANGED
@@ -1094,17 +1094,18 @@ module MarkdownExec
|
|
1094
1094
|
@ux_most_recent_filename = @delegate_object[:filename]
|
1095
1095
|
|
1096
1096
|
(blocks.each.with_object([]) do |block, merged_options|
|
1097
|
-
command_result_w_e_t_nl =
|
1098
|
-
|
1099
|
-
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1097
|
+
command_result_w_e_t_nl =
|
1098
|
+
code_from_ux_block_to_set_environment_variables(
|
1099
|
+
block,
|
1100
|
+
mdoc,
|
1101
|
+
force: @delegate_object[:ux_auto_load_force_default],
|
1102
|
+
only_default: true,
|
1103
|
+
silent: true
|
1104
|
+
)
|
1104
1105
|
if command_result_w_e_t_nl.failure?
|
1105
1106
|
merged_options
|
1106
1107
|
else
|
1107
|
-
merged_options.push(command_result_w_e_t_nl.
|
1108
|
+
merged_options.push(command_result_w_e_t_nl.new_lines)
|
1108
1109
|
end
|
1109
1110
|
end).to_a
|
1110
1111
|
end
|
@@ -1115,6 +1116,7 @@ module MarkdownExec
|
|
1115
1116
|
selected, mdoc, inherited_code: nil, force: true, only_default: false,
|
1116
1117
|
silent:
|
1117
1118
|
)
|
1119
|
+
ret_command_result = nil
|
1118
1120
|
exit_prompt = @delegate_object[:prompt_filespec_back]
|
1119
1121
|
|
1120
1122
|
required = mdoc.collect_recursively_required_code(
|
@@ -1169,7 +1171,20 @@ module MarkdownExec
|
|
1169
1171
|
end
|
1170
1172
|
return command_result_w_e_t_nl if command_result_w_e_t_nl.failure?
|
1171
1173
|
|
1174
|
+
command_result_w_e_t_nl.new_lines =
|
1175
|
+
command_result_w_e_t_nl.new_lines.map do |name_force|
|
1176
|
+
transformed = if command_result_w_e_t_nl.transformable
|
1177
|
+
transform_export_value(name_force[:text], export)
|
1178
|
+
else
|
1179
|
+
name_force[:text]
|
1180
|
+
end
|
1181
|
+
ENV[name_force[:name]] = transformed
|
1182
|
+
code_line_safe_assign(
|
1183
|
+
name_force[:name], transformed, force: name_force[:force]
|
1184
|
+
)
|
1185
|
+
end
|
1172
1186
|
required_lines.concat(command_result_w_e_t_nl.new_lines)
|
1187
|
+
|
1173
1188
|
if SelectResponse.continue?(command_result_w_e_t_nl.stdout)
|
1174
1189
|
if command_result_w_e_t_nl.transformable
|
1175
1190
|
command_result_w_e_t_nl.stdout = transform_export_value(
|
@@ -1179,16 +1194,18 @@ module MarkdownExec
|
|
1179
1194
|
|
1180
1195
|
if command_result_w_e_t_nl.exportable
|
1181
1196
|
ENV[export.name] = command_result_w_e_t_nl.stdout.to_s
|
1182
|
-
required_lines.push code_line_safe_assign(
|
1183
|
-
|
1197
|
+
required_lines.push code_line_safe_assign(
|
1198
|
+
export.name, command_result_w_e_t_nl.stdout, force: force
|
1199
|
+
)
|
1184
1200
|
end
|
1185
1201
|
end
|
1202
|
+
ret_command_result = command_result_w_e_t_nl
|
1186
1203
|
else
|
1187
1204
|
raise "Invalid data type: #{data.inspect}"
|
1188
1205
|
end
|
1189
1206
|
end
|
1190
1207
|
|
1191
|
-
CommandResult.new(stdout: required_lines)
|
1208
|
+
ret_command_result || CommandResult.new(stdout: required_lines)
|
1192
1209
|
end
|
1193
1210
|
|
1194
1211
|
# sets ENV
|
@@ -1377,11 +1394,13 @@ module MarkdownExec
|
|
1377
1394
|
end
|
1378
1395
|
|
1379
1396
|
if allow_execution
|
1380
|
-
execute_required_lines(
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1397
|
+
execute_required_lines(
|
1398
|
+
blockname: selected.pub_name,
|
1399
|
+
erls: { play_bin: play_bin,
|
1400
|
+
shell: selected_shell(selected.shell) },
|
1401
|
+
required_lines: required_lines,
|
1402
|
+
shell: selected_shell(selected.shell)
|
1403
|
+
)
|
1385
1404
|
end
|
1386
1405
|
|
1387
1406
|
link_state.block_name = nil
|
@@ -1694,6 +1713,10 @@ module MarkdownExec
|
|
1694
1713
|
@prior_execution_block = nil
|
1695
1714
|
end
|
1696
1715
|
|
1716
|
+
def selected_shell(shell_name)
|
1717
|
+
shell_name.empty? ? shell : shell_name
|
1718
|
+
end
|
1719
|
+
|
1697
1720
|
# Determines the state of a selected block in the menu based
|
1698
1721
|
# on the selected option.
|
1699
1722
|
# It categorizes the selected option into either EXIT, BACK,
|
@@ -2490,7 +2513,7 @@ module MarkdownExec
|
|
2490
2513
|
if @delegate_object[:save_executed_script]
|
2491
2514
|
write_command_file(blockname: blockname,
|
2492
2515
|
required_lines: required_lines,
|
2493
|
-
shell: shell)
|
2516
|
+
shell: selected_shell(shell))
|
2494
2517
|
end
|
2495
2518
|
if @dml_block_state
|
2496
2519
|
calc_logged_stdout_filename(block_name: @dml_block_state.block.oname)
|
@@ -2498,7 +2521,7 @@ module MarkdownExec
|
|
2498
2521
|
format_and_execute_command(
|
2499
2522
|
code_lines: required_lines,
|
2500
2523
|
erls: erls,
|
2501
|
-
shell: shell
|
2524
|
+
shell: selected_shell(shell)
|
2502
2525
|
)
|
2503
2526
|
post_execution_process
|
2504
2527
|
end
|
@@ -2615,8 +2638,8 @@ module MarkdownExec
|
|
2615
2638
|
command_result.warning = warning_required_empty(export) unless silent
|
2616
2639
|
else
|
2617
2640
|
ENV[name] = command_result.stdout.to_s
|
2618
|
-
new_lines <<
|
2619
|
-
|
2641
|
+
new_lines << { name: name, force: force,
|
2642
|
+
text: command_result.stdout }
|
2620
2643
|
end
|
2621
2644
|
end
|
2622
2645
|
|
@@ -2705,7 +2728,7 @@ module MarkdownExec
|
|
2705
2728
|
formatted_command,
|
2706
2729
|
args: @pass_args,
|
2707
2730
|
erls: erls,
|
2708
|
-
shell: shell
|
2731
|
+
shell: selected_shell(shell)
|
2709
2732
|
)
|
2710
2733
|
@fout.fout fetch_color(data_sym: :script_execution_tail,
|
2711
2734
|
color_sym: :script_execution_frame_color)
|
@@ -2968,8 +2991,8 @@ module MarkdownExec
|
|
2968
2991
|
else
|
2969
2992
|
iter_blocks_from_nested_files do |btype, fcb|
|
2970
2993
|
case btype
|
2971
|
-
when :blocks
|
2972
|
-
when :filter
|
2994
|
+
when :blocks then yield fcb
|
2995
|
+
when :filter then %i[blocks]
|
2973
2996
|
end
|
2974
2997
|
end
|
2975
2998
|
end
|
@@ -3138,9 +3161,9 @@ module MarkdownExec
|
|
3138
3161
|
opts_block_name)
|
3139
3162
|
return if selected_blocks.empty?
|
3140
3163
|
|
3141
|
-
dependency_map = selected_blocks.
|
3164
|
+
dependency_map = selected_blocks.to_h do |block|
|
3142
3165
|
[block.id, block.reqs]
|
3143
|
-
end
|
3166
|
+
end
|
3144
3167
|
|
3145
3168
|
selected_blocks.each do |block|
|
3146
3169
|
mdoc.collect_dependencies(memo: dependency_map, block: block)
|
@@ -3576,7 +3599,7 @@ module MarkdownExec
|
|
3576
3599
|
bash_script_lines
|
3577
3600
|
)
|
3578
3601
|
)
|
3579
|
-
temp_file.close
|
3602
|
+
temp_file.close # Close the file before chmod and execution
|
3580
3603
|
File.chmod(0o755, temp_file.path)
|
3581
3604
|
|
3582
3605
|
if @delegate_object[:archive_ad_hoc_scripts]
|
@@ -3587,8 +3610,7 @@ module MarkdownExec
|
|
3587
3610
|
`cp #{temp_file.path} #{archive_filename}`
|
3588
3611
|
end
|
3589
3612
|
|
3590
|
-
output =
|
3591
|
-
#### use shell per configuration
|
3613
|
+
output = `#{shell} #{temp_file.path}`
|
3592
3614
|
|
3593
3615
|
CommandResult.new(stdout: output, exit_status: $?.exitstatus)
|
3594
3616
|
end
|
@@ -3868,7 +3890,7 @@ module MarkdownExec
|
|
3868
3890
|
elsif sel == MenuOptions::SAVE_SCRIPT
|
3869
3891
|
save_to_file(
|
3870
3892
|
required_lines: required_lines, selected: selected,
|
3871
|
-
shell: selected.shell
|
3893
|
+
shell: selected_shell(selected.shell)
|
3872
3894
|
)
|
3873
3895
|
end
|
3874
3896
|
|
@@ -4204,7 +4226,7 @@ module MarkdownExec
|
|
4204
4226
|
required_lines:, selected:, shell:
|
4205
4227
|
)
|
4206
4228
|
write_command_file(
|
4207
|
-
required_lines: required_lines, blockname: selected.pub_name, shell: shell
|
4229
|
+
required_lines: required_lines, blockname: selected.pub_name, shell: selected_shell(shell)
|
4208
4230
|
)
|
4209
4231
|
@fout.fout "File saved: #{@run_state.saved_filespec}"
|
4210
4232
|
end
|
@@ -4215,7 +4237,7 @@ module MarkdownExec
|
|
4215
4237
|
saved_asset_format:
|
4216
4238
|
shell_escape_asset_format(
|
4217
4239
|
code_lines: link_state&.inherited_lines,
|
4218
|
-
shell: shell
|
4240
|
+
shell: selected_shell(shell)
|
4219
4241
|
)
|
4220
4242
|
).generate_name
|
4221
4243
|
end
|
@@ -4390,7 +4412,6 @@ module MarkdownExec
|
|
4390
4412
|
marker = Random.new.rand.to_s
|
4391
4413
|
|
4392
4414
|
code = (code_lines || []) + ["echo -n \"#{marker}#{raw}\""]
|
4393
|
-
# !!t code
|
4394
4415
|
File.write filespec, HashDelegator.join_code_lines(code)
|
4395
4416
|
File.chmod 0o755, filespec
|
4396
4417
|
|
@@ -4501,6 +4522,7 @@ module MarkdownExec
|
|
4501
4522
|
return value unless export.transform.present?
|
4502
4523
|
|
4503
4524
|
if export.transform.is_a? Symbol
|
4525
|
+
### TBD validate for symbol
|
4504
4526
|
value.send(export.transform)
|
4505
4527
|
else
|
4506
4528
|
format(
|
@@ -4607,7 +4629,7 @@ module MarkdownExec
|
|
4607
4629
|
new_lines = []
|
4608
4630
|
command_result = nil
|
4609
4631
|
|
4610
|
-
case
|
4632
|
+
case FCB.act_source(export)
|
4611
4633
|
when false, UxActSource::FALSE
|
4612
4634
|
raise 'Should not be reached.'
|
4613
4635
|
|
data/lib/mdoc.rb
CHANGED
@@ -469,6 +469,9 @@ module MarkdownExec
|
|
469
469
|
else
|
470
470
|
blocks = [block]
|
471
471
|
end
|
472
|
+
blocks.each do |block|
|
473
|
+
memo[block.id] = []
|
474
|
+
end
|
472
475
|
return memo unless blocks.count.positive?
|
473
476
|
|
474
477
|
required_blocks = blocks.map(&:reqs).flatten(1)
|
@@ -542,11 +545,11 @@ if $PROGRAM_NAME == __FILE__
|
|
542
545
|
end if false
|
543
546
|
|
544
547
|
def test_collect_dependencies_with_valid_source
|
545
|
-
@mdoc.stubs(:
|
546
|
-
.with('source1').returns(OpenStruct.new(id: 'source1',
|
547
|
-
|
548
|
-
@mdoc.stubs(:
|
549
|
-
.with('source2').returns(OpenStruct.new(id: 'source2', reqs: []))
|
548
|
+
@mdoc.stubs(:get_blocks_by_anyname)
|
549
|
+
.with('source1').returns([OpenStruct.new(id: 'source1',
|
550
|
+
reqs: ['source2'])])
|
551
|
+
@mdoc.stubs(:get_blocks_by_anyname)
|
552
|
+
.with('source2').returns([OpenStruct.new(id: 'source2', reqs: [])])
|
550
553
|
|
551
554
|
expected = { 'source1' => ['source2'], 'source2' => [] }
|
552
555
|
assert_equal expected, @mdoc.collect_dependencies(pubname: 'source1')
|
@@ -627,7 +630,7 @@ if $PROGRAM_NAME == __FILE__
|
|
627
630
|
result = @doc.recursively_required_hash('block3')
|
628
631
|
assert_equal ({ 'block3' => ['block1'],
|
629
632
|
'block1' => ['block2'],
|
630
|
-
'block2' => nil }),
|
633
|
+
'block2' => [nil] }),
|
631
634
|
result
|
632
635
|
|
633
636
|
result_no_reqs = @doc.recursively_required_hash(nil)
|
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.
|
4
|
+
version: 3.0.5
|
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-
|
11
|
+
date: 2025-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clipboard
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- bats/block-type-ux-auto.bats
|
117
117
|
- bats/block-type-ux-chained.bats
|
118
118
|
- bats/block-type-ux-default.bats
|
119
|
+
- bats/block-type-ux-echo-hash-transform.bats
|
119
120
|
- bats/block-type-ux-echo-hash.bats
|
120
121
|
- bats/block-type-ux-echo.bats
|
121
122
|
- bats/block-type-ux-exec.bats
|
@@ -168,6 +169,7 @@ files:
|
|
168
169
|
- docs/dev/block-type-ux-auto.md
|
169
170
|
- docs/dev/block-type-ux-chained.md
|
170
171
|
- docs/dev/block-type-ux-default.md
|
172
|
+
- docs/dev/block-type-ux-echo-hash-transform.md
|
171
173
|
- docs/dev/block-type-ux-echo-hash.md
|
172
174
|
- docs/dev/block-type-ux-echo.md
|
173
175
|
- docs/dev/block-type-ux-exec.md
|