markdown_exec 1.8.5 → 1.8.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +1 -1
- data/bin/tab_completion.sh +7 -3
- data/examples/linked.md +19 -0
- data/examples/linked1.md +10 -0
- data/examples/linked2.md +4 -0
- data/examples/opts.md +22 -2
- data/lib/cached_nested_file_reader.rb +1 -7
- data/lib/constants.rb +17 -0
- data/lib/directory_searcher.rb +1 -6
- data/lib/hash_delegator.rb +203 -96
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/markdown_exec.rb +12 -8
- data/lib/menu.src.yml +23 -12
- data/lib/menu.yml +23 -13
- data/lib/regexp_replacer.rb +58 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44e42ccdbdf5eed7e6ee36add8a5dcdcfe62d6cd3fb6fd531daf960c6ce7c9b7
|
4
|
+
data.tar.gz: 753076d46e44f5d17698be53a0421212d8f2c804368f9737591dc92a7d5457d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84d952fcfafed40a5e3949783760aec570448de48293fdae536b5386b95d8080d2c9c41f0149861686d2fd4985a59ebea6794e7953d7b4dc1185340d790e68a2
|
7
|
+
data.tar.gz: 9db0c523154e32c3094046084594564c9114fbd2519f6ff5d9a8fcc5feb0d31b76dc3ccd1d6c4e2625507b81b4f70f9b6fdf31e250d132a5fdf2fa54d3cb8c77
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/bin/tab_completion.sh
CHANGED
@@ -13,7 +13,7 @@ __filedirs_all()
|
|
13
13
|
}
|
14
14
|
|
15
15
|
_mde_echo_version() {
|
16
|
-
echo "1.8.
|
16
|
+
echo "1.8.6"
|
17
17
|
}
|
18
18
|
|
19
19
|
_mde() {
|
@@ -54,6 +54,8 @@ _mde() {
|
|
54
54
|
|
55
55
|
-?) COMPREPLY="''"; return 0 ;;
|
56
56
|
|
57
|
+
--find-path) COMPREPLY="''"; return 0 ;;
|
58
|
+
|
57
59
|
--how) COMPREPLY="''"; return 0 ;;
|
58
60
|
|
59
61
|
-?) COMPREPLY="''"; return 0 ;;
|
@@ -92,7 +94,7 @@ _mde() {
|
|
92
94
|
# present matching option names
|
93
95
|
#
|
94
96
|
if [[ ${cur} == -* ]] ; then
|
95
|
-
opts=("--block-name" "--config" "--debug" "--dump-dump-delegate-object" "--dump-blocks-in-file" "--dump-dump-inherited-lines" "--dump-menu-blocks" "--dump-selected-block" "--exit" "--filename" "--find" "--help" "--how" "--list-blocks" "--list-count" "--list-default-env" "--list-default-yaml" "--list-docs" "--list-recent-output" "--list-recent-scripts" "--output-execution-summary" "--output-script" "--output-stdout" "--path" "--pwd" "--run-last-script" "--save-executed-script" "--save-execution-output" "--saved-script-folder" "--saved-stdout-folder" "--select-recent-output" "--select-recent-script" "--tab-completions" "--user-must-approve" "--version" "--display-level")
|
97
|
+
opts=("--block-name" "--config" "--debug" "--dump-dump-delegate-object" "--dump-blocks-in-file" "--dump-dump-inherited-lines" "--dump-menu-blocks" "--dump-selected-block" "--exit" "--filename" "--find" "--find-path" "--help" "--how" "--list-blocks" "--list-count" "--list-default-env" "--list-default-yaml" "--list-docs" "--list-recent-output" "--list-recent-scripts" "--output-execution-summary" "--output-script" "--output-stdout" "--path" "--pwd" "--run-last-script" "--save-executed-script" "--save-execution-output" "--saved-script-folder" "--saved-stdout-folder" "--select-recent-output" "--select-recent-script" "--tab-completions" "--user-must-approve" "--version" "--display-level")
|
96
98
|
COMPREPLY=( $(compgen -W "$(printf "'%s' " "${opts[@]}")" -- "${cur}") )
|
97
99
|
|
98
100
|
return 0
|
@@ -133,6 +135,8 @@ _mde() {
|
|
133
135
|
|
134
136
|
-?) COMPREPLY=".FIND."; return 0 ;;
|
135
137
|
|
138
|
+
--find-path) COMPREPLY=".FIND_PATH."; return 0 ;;
|
139
|
+
|
136
140
|
--how) COMPREPLY=".HOW."; return 0 ;;
|
137
141
|
|
138
142
|
-?) COMPREPLY=".HOW."; return 0 ;;
|
@@ -174,4 +178,4 @@ _mde() {
|
|
174
178
|
|
175
179
|
complete -o filenames -o nospace -F _mde mde
|
176
180
|
# _mde_echo_version
|
177
|
-
# echo "Updated: 2023-12-
|
181
|
+
# echo "Updated: 2023-12-26 00:07:49 UTC"
|
data/examples/linked.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
Demonstrate setting a variable interactively for use in generated scripts.
|
2
2
|
|
3
3
|
```opts :(document_options)
|
4
|
+
dump_inherited_lines: true
|
4
5
|
pause_after_script_execution: false
|
5
6
|
user_must_approve: false
|
6
7
|
```
|
@@ -15,6 +16,15 @@ block: display_variable
|
|
15
16
|
VARIABLE=A
|
16
17
|
```
|
17
18
|
|
19
|
+
```link :set_to_A_eval +(set_to_A_eval)
|
20
|
+
block: display_variable
|
21
|
+
eval: true
|
22
|
+
```
|
23
|
+
|
24
|
+
```bash :(set_to_A_eval)
|
25
|
+
echo VARIABLE=A
|
26
|
+
```
|
27
|
+
|
18
28
|
::: Set VARIABLE to "B"
|
19
29
|
|
20
30
|
```link :set_to_B +(set_to_B)
|
@@ -25,6 +35,15 @@ block: display_variable
|
|
25
35
|
VARIABLE=B
|
26
36
|
```
|
27
37
|
|
38
|
+
```link :set_to_B_eval +(set_to_B_eval)
|
39
|
+
block: display_variable
|
40
|
+
eval: true
|
41
|
+
```
|
42
|
+
|
43
|
+
```bash :(set_to_B_eval)
|
44
|
+
echo VARIABLE=B
|
45
|
+
```
|
46
|
+
|
28
47
|
::: Display value of VARIABLE
|
29
48
|
|
30
49
|
```bash :display_variable
|
data/examples/linked1.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Demo document linking
|
2
2
|
|
3
|
+
```opts :(document_options)
|
4
|
+
dump_inherited_lines: true
|
5
|
+
pause_after_script_execution: false
|
6
|
+
user_must_approve: false
|
7
|
+
```
|
8
|
+
|
3
9
|
::: * This is document 1 *
|
4
10
|
::: This document links to a matching document to demonstrate navigation between documents.
|
5
11
|
|
@@ -15,6 +21,10 @@ colorize_env_vars 'vars for page3' PAGE3_VAR_VIA_INHERIT page3_var_via_environme
|
|
15
21
|
PAGE2_VAR_VIA_INHERIT=for_page2_from_page1_via_inherited_code_blocks
|
16
22
|
```
|
17
23
|
|
24
|
+
```link :linked2 +(vars2)
|
25
|
+
file: examples/linked2.md
|
26
|
+
```
|
27
|
+
|
18
28
|
```link :(linked2) +(vars2)
|
19
29
|
file: examples/linked2.md
|
20
30
|
```
|
data/examples/linked2.md
CHANGED
@@ -20,6 +20,10 @@ colorize_env_vars 'vars for page3' PAGE3_VAR_VIA_INHERIT page3_var_via_environme
|
|
20
20
|
PAGE3_VAR_VIA_INHERIT=for_page3_from_page2_via_inherited_code_blocks
|
21
21
|
```
|
22
22
|
|
23
|
+
```link :linked3 +(vars3)
|
24
|
+
file: examples/linked3.md
|
25
|
+
```
|
26
|
+
|
23
27
|
```link :(linked3) +(vars3)
|
24
28
|
file: examples/linked3.md
|
25
29
|
```
|
data/examples/opts.md
CHANGED
@@ -2,13 +2,15 @@
|
|
2
2
|
|
3
3
|
::: These Opts blocks set the color of a couple of menu options to demonstrate the live update of options.
|
4
4
|
|
5
|
-
```opts
|
5
|
+
```opts
|
6
|
+
# color scheme 1
|
6
7
|
menu_divider_color: yellow
|
7
8
|
menu_note_match: "^ *(?<line>.+?) *$"
|
8
9
|
menu_task_color: fg_rgb_255_63_255
|
9
10
|
```
|
10
11
|
|
11
|
-
```opts
|
12
|
+
```opts
|
13
|
+
# color scheme 2
|
12
14
|
menu_divider_color: red
|
13
15
|
menu_note_color: yellow
|
14
16
|
menu_note_match: "^\\+ +(?<line>.+?) *$"
|
@@ -27,3 +29,21 @@ note 1
|
|
27
29
|
note 2 ends with /
|
28
30
|
/ note 3 starts with /
|
29
31
|
note 4
|
32
|
+
|
33
|
+
::: These options toggle the dump of debug information.
|
34
|
+
|
35
|
+
```opts
|
36
|
+
dump_blocks_in_file: true # Dump BlocksInFile (stage 1)
|
37
|
+
dump_delegate_object: true # Dump @delegate_object
|
38
|
+
dump_inherited_lines: true # Dump inherited lines
|
39
|
+
dump_menu_blocks: true # Dump MenuBlocks (stage 2)
|
40
|
+
dump_selected_block: true # Dump selected block
|
41
|
+
```
|
42
|
+
|
43
|
+
```opts
|
44
|
+
dump_blocks_in_file: false # Dump BlocksInFile (stage 1)
|
45
|
+
dump_delegate_object: false # Dump @delegate_object
|
46
|
+
dump_inherited_lines: false # Dump inherited lines
|
47
|
+
dump_menu_blocks: false # Dump MenuBlocks (stage 2)
|
48
|
+
dump_selected_block: false # Dump selected block
|
49
|
+
```
|
@@ -6,15 +6,9 @@
|
|
6
6
|
# version 2023-10-03
|
7
7
|
|
8
8
|
require 'fileutils'
|
9
|
+
require_relative 'constants'
|
9
10
|
require_relative 'exceptions'
|
10
11
|
|
11
|
-
# a struct to hold the data for a single line
|
12
|
-
NestedLine = Struct.new(:text, :depth) do
|
13
|
-
def to_s
|
14
|
-
text
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
12
|
##
|
19
13
|
# The CachedNestedFileReader class provides functionality to read file lines with the ability
|
20
14
|
# to process '#import filename' directives. When such a directive is encountered in a file,
|
data/lib/constants.rb
CHANGED
@@ -3,12 +3,20 @@
|
|
3
3
|
|
4
4
|
# encoding=utf-8
|
5
5
|
|
6
|
+
require_relative 'block_types'
|
7
|
+
|
6
8
|
class ExecutionStreams
|
7
9
|
StdErr = :stderr
|
8
10
|
StdIn = :stdin
|
9
11
|
StdOut = :stdout
|
10
12
|
end
|
11
13
|
|
14
|
+
IndexedLine = Struct.new(:index, :line) do
|
15
|
+
def to_s
|
16
|
+
line
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
12
20
|
class LoadFile
|
13
21
|
Load = true
|
14
22
|
Reuse = false
|
@@ -34,6 +42,13 @@ class MenuState
|
|
34
42
|
EXIT = :exit
|
35
43
|
end
|
36
44
|
|
45
|
+
# a struct to hold the data for a single line
|
46
|
+
NestedLine = Struct.new(:text, :depth) do
|
47
|
+
def to_s
|
48
|
+
text
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
37
52
|
# selected block and subsequent menu state
|
38
53
|
#
|
39
54
|
SelectedBlockMenuState = Struct.new(:block, :state)
|
@@ -44,3 +59,5 @@ SHELL_COLOR_OPTIONS = {
|
|
44
59
|
BlockType::OPTS => :menu_opts_color,
|
45
60
|
BlockType::VARS => :menu_vars_color
|
46
61
|
}.freeze
|
62
|
+
|
63
|
+
### Struct.new(:state, :block)
|
data/lib/directory_searcher.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
# encoding=utf-8
|
5
5
|
|
6
6
|
require 'find'
|
7
|
+
require_relative 'constants'
|
7
8
|
|
8
9
|
def format_and_highlight_hash(
|
9
10
|
data,
|
@@ -89,12 +90,6 @@ def format_and_highlight_lines(
|
|
89
90
|
highlight_color_sym)}#{line_postfix}\n" + formatted_deps.join("\n")
|
90
91
|
end
|
91
92
|
|
92
|
-
IndexedLine = Struct.new(:index, :line) do
|
93
|
-
def to_s
|
94
|
-
line
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
93
|
# Class DirectorySearcher
|
99
94
|
# This class provides methods to search for a specified pattern
|
100
95
|
# in directory names, file names, and contents of files within given paths.
|
data/lib/hash_delegator.rb
CHANGED
@@ -359,7 +359,7 @@ module MarkdownExec
|
|
359
359
|
@fout.fout "Error ENOENT: #{err.inspect}"
|
360
360
|
end
|
361
361
|
|
362
|
-
def
|
362
|
+
def load_cli_or_user_selected_block(all_blocks, menu_blocks, default)
|
363
363
|
if @delegate_object[:block_name].present?
|
364
364
|
block = all_blocks.find do |item|
|
365
365
|
item[:oname] == @delegate_object[:block_name]
|
@@ -373,7 +373,7 @@ module MarkdownExec
|
|
373
373
|
|
374
374
|
SelectedBlockMenuState.new(block, state)
|
375
375
|
rescue StandardError
|
376
|
-
error_handler('
|
376
|
+
error_handler('load_cli_or_user_selected_block')
|
377
377
|
end
|
378
378
|
|
379
379
|
# This method is responsible for handling the execution of generic blocks in a markdown document.
|
@@ -383,8 +383,7 @@ module MarkdownExec
|
|
383
383
|
# @param mdoc [Object] The markdown document object containing code blocks.
|
384
384
|
# @param selected [Hash] The selected item from the menu to be executed.
|
385
385
|
# @return [LoadFileLinkState] An object indicating whether to load the next block or reuse the current one.
|
386
|
-
def
|
387
|
-
link_state = nil, block_source:)
|
386
|
+
def compile_execute_and_trigger_reuse(mdoc, selected, link_state = nil, block_source:)
|
388
387
|
required_lines = collect_required_code_lines(mdoc, selected, link_state,
|
389
388
|
block_source: block_source)
|
390
389
|
output_or_approval = @delegate_object[:output_script] || @delegate_object[:user_must_approve]
|
@@ -602,8 +601,8 @@ module MarkdownExec
|
|
602
601
|
# @param opts [Hash] Options hash containing configuration settings.
|
603
602
|
# @param mdoc [YourMDocClass] An instance of the MDoc class.
|
604
603
|
#
|
605
|
-
def
|
606
|
-
|
604
|
+
def execute_shell_type(selected, mdoc, link_state = LinkState.new,
|
605
|
+
block_source:)
|
607
606
|
if selected.fetch(:shell, '') == BlockType::LINK
|
608
607
|
push_link_history_and_trigger_load(selected.fetch(:body, ''), mdoc, selected,
|
609
608
|
link_state)
|
@@ -618,8 +617,8 @@ module MarkdownExec
|
|
618
617
|
options_state.load_file_link_state
|
619
618
|
|
620
619
|
else
|
621
|
-
|
622
|
-
|
620
|
+
compile_execute_and_trigger_reuse(mdoc, selected, link_state,
|
621
|
+
block_source: block_source)
|
623
622
|
end
|
624
623
|
end
|
625
624
|
|
@@ -922,10 +921,12 @@ module MarkdownExec
|
|
922
921
|
end
|
923
922
|
end
|
924
923
|
|
925
|
-
def
|
926
|
-
return false unless @
|
924
|
+
def shift_cli_argument!
|
925
|
+
return false unless @menu_base_options[:input_cli_rest].present?
|
927
926
|
|
928
|
-
@cli_block_name = @
|
927
|
+
@cli_block_name = @menu_base_options[:input_cli_rest].shift
|
928
|
+
# @delegate_object[:input_cli_rest].shift
|
929
|
+
# p [__LINE__, @cli_block_name, @menu_base_options[:input_cli_rest]]
|
929
930
|
true
|
930
931
|
end
|
931
932
|
|
@@ -1272,102 +1273,208 @@ module MarkdownExec
|
|
1272
1273
|
# Markdown document, obtain approval, and execute the chosen block of code.
|
1273
1274
|
#
|
1274
1275
|
# @return [Nil] Returns nil if no code block is selected or an error occurs.
|
1275
|
-
def
|
1276
|
+
def document_menu_loop
|
1276
1277
|
@menu_base_options = @delegate_object
|
1278
|
+
link_state, block_name_from_cli, now_using_cli = initialize_selection_states
|
1279
|
+
menu_default_dname = nil
|
1280
|
+
|
1281
|
+
loop do
|
1282
|
+
# @bsp 'loop',block_name_from_cli,@cli_block_name
|
1283
|
+
block_name_from_cli, now_using_cli, blocks_in_file, menu_blocks, mdoc = \
|
1284
|
+
set_delobj_menu_loop_vars(block_name_from_cli, now_using_cli, link_state)
|
1285
|
+
|
1286
|
+
# cli or user selection
|
1287
|
+
#
|
1288
|
+
block_state = load_cli_or_user_selected_block(blocks_in_file, menu_blocks,
|
1289
|
+
menu_default_dname)
|
1290
|
+
if block_state.state == MenuState::EXIT
|
1291
|
+
# @bsp 'MenuState::EXIT -> break'
|
1292
|
+
break
|
1293
|
+
end
|
1294
|
+
|
1295
|
+
dump_and_warn_block_state(block_state.block)
|
1296
|
+
link_state, menu_default_dname = exec_bash_next_state(block_state.block, mdoc,
|
1297
|
+
link_state)
|
1298
|
+
if prompt_user_exit(block_name_from_cli, block_state.block)
|
1299
|
+
# @bsp 'prompt_user_exit -> break'
|
1300
|
+
break
|
1301
|
+
end
|
1302
|
+
|
1303
|
+
link_state.block_name, block_name_from_cli, cli_break = \
|
1304
|
+
next_state_from_cli(now_using_cli, block_state)
|
1305
|
+
|
1306
|
+
if cli_break
|
1307
|
+
# @bsp 'read_block_name_from_cli + next_link_state -> break'
|
1308
|
+
break
|
1309
|
+
end
|
1310
|
+
end
|
1311
|
+
rescue StandardError
|
1312
|
+
error_handler('document_menu_loop',
|
1313
|
+
{ abort: true })
|
1314
|
+
end
|
1315
|
+
|
1316
|
+
def next_state_from_cli(now_using_cli, block_state)
|
1317
|
+
was_using_cli = now_using_cli
|
1318
|
+
block_name_from_cli, = read_block_name_from_cli(now_using_cli)
|
1319
|
+
block_name, block_name_from_cli, cli_break = \
|
1320
|
+
next_link_state(block_name_from_cli, was_using_cli, block_state)
|
1321
|
+
|
1322
|
+
[block_name, block_name_from_cli, cli_break]
|
1323
|
+
end
|
1324
|
+
|
1325
|
+
def exec_bash_next_state(block_state_block, mdoc, link_state)
|
1326
|
+
lfls = execute_shell_type(
|
1327
|
+
block_state_block,
|
1328
|
+
mdoc,
|
1329
|
+
link_state,
|
1330
|
+
block_source: { document_filename: @delegate_object[:filename] }
|
1331
|
+
)
|
1332
|
+
|
1333
|
+
# if the same menu is being displayed, collect the display name of the selected menu item for use as the default item
|
1334
|
+
[lfls.link_state,
|
1335
|
+
lfls.load_file == LoadFile::Load ? nil : block_state_block[:dname]]
|
1336
|
+
end
|
1337
|
+
|
1338
|
+
def set_delobj_menu_loop_vars(block_name_from_cli, now_using_cli, link_state)
|
1339
|
+
block_name_from_cli, now_using_cli = \
|
1340
|
+
manage_cli_selection_state(block_name_from_cli, now_using_cli, link_state)
|
1341
|
+
set_delob_filename_block_name(link_state, block_name_from_cli)
|
1342
|
+
|
1343
|
+
# update @delegate_object and @menu_base_options in auto_load
|
1344
|
+
#
|
1345
|
+
blocks_in_file, menu_blocks, mdoc = mdoc_menu_and_blocks_from_nested_files
|
1346
|
+
dump_delobj(blocks_in_file, menu_blocks, link_state)
|
1347
|
+
|
1348
|
+
[block_name_from_cli, now_using_cli, blocks_in_file, menu_blocks, mdoc]
|
1349
|
+
end
|
1350
|
+
|
1351
|
+
# user prompt to exit if the menu will be displayed again
|
1352
|
+
#
|
1353
|
+
def prompt_user_exit(block_name_from_cli, block_state_block)
|
1354
|
+
!block_name_from_cli &&
|
1355
|
+
block_state_block[:shell] == BlockType::BASH &&
|
1356
|
+
@delegate_object[:pause_after_script_execution] &&
|
1357
|
+
prompt_select_continue == MenuState::EXIT
|
1358
|
+
end
|
1359
|
+
|
1360
|
+
def manage_cli_selection_state(block_name_from_cli, now_using_cli, link_state)
|
1361
|
+
if block_name_from_cli && @cli_block_name == '.'
|
1362
|
+
# @bsp 'pause cli control, allow user to select block'
|
1363
|
+
block_name_from_cli = false
|
1364
|
+
now_using_cli = false
|
1365
|
+
@menu_base_options[:block_name] = \
|
1366
|
+
@delegate_object[:block_name] = \
|
1367
|
+
link_state.block_name = \
|
1368
|
+
@cli_block_name = nil
|
1369
|
+
end
|
1370
|
+
|
1371
|
+
@delegate_object = @menu_base_options.dup
|
1372
|
+
@menu_user_clicked_back_link = false
|
1373
|
+
[block_name_from_cli, now_using_cli]
|
1374
|
+
end
|
1375
|
+
|
1376
|
+
def next_link_state(block_name_from_cli, was_using_cli, block_state)
|
1377
|
+
# @bsp 'next_link_state',block_name_from_cli, was_using_cli, block_state
|
1378
|
+
# Set block_name based on block_name_from_cli
|
1379
|
+
block_name = block_name_from_cli ? @cli_block_name : nil
|
1380
|
+
|
1381
|
+
# Determine the state of breaker based on was_using_cli and the block type
|
1382
|
+
breaker = !block_name_from_cli && was_using_cli && block_state.block[:shell] == BlockType::BASH
|
1383
|
+
|
1384
|
+
# Reset block_name_from_cli if the conditions are not met
|
1385
|
+
block_name_from_cli ||= false
|
1386
|
+
|
1387
|
+
[block_name, block_name_from_cli, breaker]
|
1388
|
+
end
|
1389
|
+
|
1390
|
+
# Initialize the selection states for the execution loop.
|
1391
|
+
def initialize_selection_states
|
1277
1392
|
link_state = LinkState.new(
|
1278
1393
|
block_name: @delegate_object[:block_name],
|
1279
1394
|
document_filename: @delegate_object[:filename]
|
1280
1395
|
)
|
1281
|
-
block_name_from_cli = link_state
|
1282
|
-
|
1283
|
-
|
1284
|
-
menu_default_dname = nil
|
1396
|
+
block_name_from_cli, now_using_cli = handle_cli_block_name(link_state)
|
1397
|
+
[link_state, block_name_from_cli, now_using_cli]
|
1398
|
+
end
|
1285
1399
|
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1400
|
+
# Update the state related to CLI block name.
|
1401
|
+
#
|
1402
|
+
# This method updates the flags indicating whether a CLI block name is being used
|
1403
|
+
# and if it was being used previously.
|
1404
|
+
#
|
1405
|
+
# @param block_name_from_cli [Boolean] Indicates if the block name is from CLI.
|
1406
|
+
# @return [Array] Returns the updated state of block name from CLI and its usage.
|
1407
|
+
def read_block_name_from_cli(block_name_from_cli)
|
1408
|
+
# was_using_cli = block_name_from_cli
|
1409
|
+
block_name_from_cli = shift_cli_argument!
|
1410
|
+
now_using_cli = block_name_from_cli
|
1297
1411
|
|
1298
|
-
|
1299
|
-
|
1300
|
-
@delegate_object,
|
1301
|
-
label: '@delegate_object'
|
1302
|
-
)
|
1303
|
-
end
|
1412
|
+
[block_name_from_cli, now_using_cli]
|
1413
|
+
end
|
1304
1414
|
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
if @delegate_object[:dump_inherited_lines]
|
1318
|
-
warn format_and_highlight_lines(
|
1319
|
-
link_state.inherited_lines,
|
1320
|
-
label: 'inherited_lines'
|
1321
|
-
)
|
1322
|
-
end
|
1415
|
+
# Update the block name in the link state and delegate object.
|
1416
|
+
#
|
1417
|
+
# This method updates the block name based on whether it was specified
|
1418
|
+
# through the CLI or derived from the link state.
|
1419
|
+
#
|
1420
|
+
# @param link_state [LinkState] The current link state object.
|
1421
|
+
# @param block_name_from_cli [Boolean] Indicates if the block name is from CLI.
|
1422
|
+
def set_delob_filename_block_name(link_state, block_name_from_cli)
|
1423
|
+
@delegate_object[:filename] = link_state.document_filename
|
1424
|
+
link_state.block_name = @delegate_object[:block_name] =
|
1425
|
+
block_name_from_cli ? @cli_block_name : link_state.block_name
|
1426
|
+
end
|
1323
1427
|
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1428
|
+
# Handle CLI block name and determine the current CLI usage state.
|
1429
|
+
#
|
1430
|
+
# This method processes the CLI block name from the link state and sets
|
1431
|
+
# the initial state for CLI usage.
|
1432
|
+
#
|
1433
|
+
# @param link_state [LinkState] The current link state object.
|
1434
|
+
# @return [Array] Returns the state of block name from CLI and current usage of CLI.
|
1435
|
+
def handle_cli_block_name(link_state)
|
1436
|
+
block_name_from_cli = link_state.block_name.present?
|
1437
|
+
@cli_block_name = link_state.block_name
|
1438
|
+
now_using_cli = block_name_from_cli
|
1327
1439
|
|
1328
|
-
|
1329
|
-
|
1330
|
-
{ abort: true })
|
1331
|
-
# error_handler("Block not found -- #{opts[:block_name]}", { abort: true })
|
1332
|
-
end
|
1440
|
+
[block_name_from_cli, now_using_cli]
|
1441
|
+
end
|
1333
1442
|
|
1334
|
-
|
1335
|
-
|
1336
|
-
|
1443
|
+
# Outputs warnings based on the delegate object's configuration
|
1444
|
+
#
|
1445
|
+
# @param delegate_object [Hash] The delegate object containing configuration flags.
|
1446
|
+
# @param blocks_in_file [Hash] Hash of blocks present in the file.
|
1447
|
+
# @param menu_blocks [Hash] Hash of menu blocks.
|
1448
|
+
# @param link_state [LinkState] Current state of the link.
|
1449
|
+
def dump_delobj(blocks_in_file, menu_blocks, link_state)
|
1450
|
+
if @delegate_object[:dump_delegate_object]
|
1451
|
+
warn format_and_highlight_hash(@delegate_object, label: '@delegate_object')
|
1452
|
+
end
|
1337
1453
|
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
block_source: { document_filename: @delegate_object[:filename] }
|
1343
|
-
)
|
1344
|
-
load_file = load_file_link_state.load_file
|
1345
|
-
link_state = load_file_link_state.link_state
|
1454
|
+
if @delegate_object[:dump_blocks_in_file]
|
1455
|
+
warn format_and_highlight_dependencies(compact_and_index_hash(blocks_in_file),
|
1456
|
+
label: 'blocks_in_file')
|
1457
|
+
end
|
1346
1458
|
|
1347
|
-
|
1348
|
-
|
1459
|
+
if @delegate_object[:dump_menu_blocks]
|
1460
|
+
warn format_and_highlight_dependencies(compact_and_index_hash(menu_blocks),
|
1461
|
+
label: 'menu_blocks')
|
1462
|
+
end
|
1349
1463
|
|
1350
|
-
|
1351
|
-
#
|
1352
|
-
if !block_name_from_cli &&
|
1353
|
-
block_state.block[:shell] == BlockType::BASH &&
|
1354
|
-
@delegate_object[:pause_after_script_execution] &&
|
1355
|
-
prompt_select_continue == MenuState::EXIT
|
1356
|
-
return
|
1357
|
-
end
|
1464
|
+
return unless @delegate_object[:dump_inherited_lines]
|
1358
1465
|
|
1359
|
-
|
1360
|
-
|
1361
|
-
break if block_state.state == MenuState::CONTINUE && load_file == LoadFile::Load
|
1362
|
-
break if block_name_from_cli
|
1363
|
-
end
|
1364
|
-
break if load_file == LoadFile::Reuse
|
1466
|
+
warn format_and_highlight_lines(link_state.inherited_lines, label: 'inherited_lines')
|
1467
|
+
end
|
1365
1468
|
|
1366
|
-
|
1469
|
+
def dump_and_warn_block_state(block_state_block)
|
1470
|
+
if block_state_block.nil?
|
1471
|
+
Exceptions.warn_format("Block not found -- name: #{@delegate_object[:block_name]}",
|
1472
|
+
{ abort: true })
|
1367
1473
|
end
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1474
|
+
|
1475
|
+
return unless @delegate_object[:dump_selected_block]
|
1476
|
+
|
1477
|
+
warn block_state_block.to_yaml.sub(/^(?:---\n)?/, "Block:\n")
|
1371
1478
|
end
|
1372
1479
|
|
1373
1480
|
# Presents a TTY prompt to select an option or exit, returns metadata including option and selected
|
@@ -1561,7 +1668,7 @@ module MarkdownExec
|
|
1561
1668
|
yield_line_if_selected(line, selected_messages, &block)
|
1562
1669
|
|
1563
1670
|
else
|
1564
|
-
# '
|
1671
|
+
# @bsp 'line is not recognized for block state'
|
1565
1672
|
|
1566
1673
|
end
|
1567
1674
|
end
|
@@ -1988,7 +2095,7 @@ if $PROGRAM_NAME == __FILE__
|
|
1988
2095
|
@hd.instance_variable_set(:@delegate_object,
|
1989
2096
|
{ block_name: 'block1' })
|
1990
2097
|
|
1991
|
-
result = @hd.
|
2098
|
+
result = @hd.load_cli_or_user_selected_block(all_blocks, [], nil)
|
1992
2099
|
|
1993
2100
|
assert_equal all_blocks.first, result.block
|
1994
2101
|
assert_nil result.state
|
@@ -1999,7 +2106,7 @@ if $PROGRAM_NAME == __FILE__
|
|
1999
2106
|
:some_state)
|
2000
2107
|
@hd.stubs(:wait_for_user_selected_block).returns(block_state)
|
2001
2108
|
|
2002
|
-
result = @hd.
|
2109
|
+
result = @hd.load_cli_or_user_selected_block([], [], nil)
|
2003
2110
|
|
2004
2111
|
assert_equal block_state.block, result.block
|
2005
2112
|
assert_equal :some_state, result.state
|
@@ -2291,7 +2398,7 @@ if $PROGRAM_NAME == __FILE__
|
|
2291
2398
|
@selected_item = mock('FCB')
|
2292
2399
|
end
|
2293
2400
|
|
2294
|
-
def
|
2401
|
+
def test_compile_execute_and_trigger_reuse_without_user_approval
|
2295
2402
|
# Mock the delegate object configuration
|
2296
2403
|
@hd.instance_variable_set(:@delegate_object,
|
2297
2404
|
{ output_script: false,
|
@@ -2301,7 +2408,7 @@ if $PROGRAM_NAME == __FILE__
|
|
2301
2408
|
# Expectations and assertions go here
|
2302
2409
|
end
|
2303
2410
|
|
2304
|
-
def
|
2411
|
+
def test_compile_execute_and_trigger_reuse_with_user_approval
|
2305
2412
|
# Mock the delegate object configuration
|
2306
2413
|
@hd.instance_variable_set(:@delegate_object,
|
2307
2414
|
{ output_script: false,
|
@@ -2311,7 +2418,7 @@ if $PROGRAM_NAME == __FILE__
|
|
2311
2418
|
# Expectations and assertions go here
|
2312
2419
|
end
|
2313
2420
|
|
2314
|
-
def
|
2421
|
+
def test_compile_execute_and_trigger_reuse_with_output_script
|
2315
2422
|
# Mock the delegate object configuration
|
2316
2423
|
@hd.instance_variable_set(:@delegate_object,
|
2317
2424
|
{ output_script: true,
|
data/lib/markdown_exec.rb
CHANGED
@@ -41,6 +41,8 @@ tap_config envvar: MarkdownExec::TAP_DEBUG
|
|
41
41
|
$stderr.sync = true
|
42
42
|
$stdout.sync = true
|
43
43
|
|
44
|
+
ARGV_SEP = '--'
|
45
|
+
|
44
46
|
# custom error: file specified is missing
|
45
47
|
#
|
46
48
|
class FileMissingError < StandardError; end
|
@@ -136,10 +138,11 @@ module MarkdownExec
|
|
136
138
|
)
|
137
139
|
end
|
138
140
|
|
139
|
-
# return arguments before
|
141
|
+
# return arguments before ARGV_SEP
|
142
|
+
# arguments after ARGV_SEP are passed to the generatede script
|
140
143
|
#
|
141
144
|
def arguments_for_mde(argv = ARGV)
|
142
|
-
case ind = argv.find_index(
|
145
|
+
case ind = argv.find_index(ARGV_SEP)
|
143
146
|
when nil
|
144
147
|
argv
|
145
148
|
when 0
|
@@ -205,14 +208,13 @@ module MarkdownExec
|
|
205
208
|
# Reports and executes block logic
|
206
209
|
def execute_block_logic(files)
|
207
210
|
@options[:filename] = select_document_if_multiple(files)
|
208
|
-
@options.
|
211
|
+
@options.document_menu_loop
|
209
212
|
end
|
210
213
|
|
211
214
|
## Executes the block specified in the options
|
212
215
|
#
|
213
216
|
def execute_block_with_error_handling
|
214
217
|
finalize_cli_argument_processing
|
215
|
-
@options[:input_cli_rest] = @rest
|
216
218
|
execute_code_block_based_on_options(@options)
|
217
219
|
rescue FileMissingError
|
218
220
|
warn "File missing: #{$!}"
|
@@ -293,6 +295,7 @@ module MarkdownExec
|
|
293
295
|
#
|
294
296
|
block_name = rest.shift
|
295
297
|
@options[:block_name] = block_name if block_name.present?
|
298
|
+
@options[:input_cli_rest] = @rest
|
296
299
|
rescue FileMissingError
|
297
300
|
warn_format('finalize_cli_argument_processing',
|
298
301
|
"File missing -- #{$!}", { abort: true })
|
@@ -346,10 +349,11 @@ module MarkdownExec
|
|
346
349
|
->(_) { exit }
|
347
350
|
when 'find'
|
348
351
|
->(value) {
|
352
|
+
find_path = @options[:find_path].present? ? @options[:find_path] : @options[:path]
|
349
353
|
@fout.fout 'Searching in: ' \
|
350
|
-
"#{HashDelegator.new(@options).string_send_color(
|
354
|
+
"#{HashDelegator.new(@options).string_send_color(find_path,
|
351
355
|
:menu_chrome_color)}"
|
352
|
-
searcher = DirectorySearcher.new(value, [
|
356
|
+
searcher = DirectorySearcher.new(value, [find_path])
|
353
357
|
|
354
358
|
@fout.fout 'In file contents'
|
355
359
|
hash = searcher.search_in_file_contents
|
@@ -546,7 +550,7 @@ module MarkdownExec
|
|
546
550
|
|
547
551
|
saved_name_split filename
|
548
552
|
@options[:save_executed_script] = false
|
549
|
-
@options.
|
553
|
+
@options.document_menu_loop
|
550
554
|
rescue StandardError
|
551
555
|
error_handler('run_last_script')
|
552
556
|
end
|
@@ -613,7 +617,7 @@ module MarkdownExec
|
|
613
617
|
|
614
618
|
saved_name_split(filename)
|
615
619
|
|
616
|
-
@options.
|
620
|
+
@options.document_menu_loop ### ({ save_executed_script: false })
|
617
621
|
end
|
618
622
|
|
619
623
|
public
|
data/lib/menu.src.yml
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
|
18
18
|
- :arg_name: NAME
|
19
19
|
:compreply: false
|
20
|
-
:description: Name of block
|
20
|
+
:description: Name of block to execute
|
21
21
|
:env_var: MDE_BLOCK_NAME
|
22
22
|
:long_name: block-name
|
23
23
|
:opt_name: block_name
|
@@ -203,18 +203,20 @@
|
|
203
203
|
## match fenced code indented by spaces
|
204
204
|
#
|
205
205
|
- :default: "^(?<indent> *)`{3,}"
|
206
|
+
:description: Matches the start and end of a fenced code block
|
206
207
|
:env_var: MDE_FENCED_START_AND_END_REGEX
|
207
208
|
:opt_name: fenced_start_and_end_regex
|
208
209
|
:procname: val_as_str
|
209
210
|
|
210
211
|
- :default: "^(?<indent> *)`{3,}(?<shell>[^`\\s]*) *:?(?<name>[^\\s]*) *(?<rest>.*) *$"
|
212
|
+
:description: Match the start of a fenced block
|
211
213
|
:env_var: MDE_FENCED_START_EXTENDED_REGEX
|
212
214
|
:opt_name: fenced_start_extended_regex
|
213
215
|
:procname: val_as_str
|
214
216
|
|
215
217
|
- :arg_name: RELATIVE_PATH
|
216
218
|
:compreply: "."
|
217
|
-
:description: Name of document
|
219
|
+
:description: Name of the document to load
|
218
220
|
:env_var: MDE_FILENAME
|
219
221
|
:long_name: filename
|
220
222
|
:opt_name: filename
|
@@ -228,6 +230,14 @@
|
|
228
230
|
:procname: find
|
229
231
|
:short_name: "?"
|
230
232
|
|
233
|
+
- :arg_name: FIND_PATH
|
234
|
+
:default: ""
|
235
|
+
:description: Path for find (uses PATH if empty)
|
236
|
+
:env_var: MDE_FIND_PATH
|
237
|
+
:long_name: find-path
|
238
|
+
:opt_name: find_path
|
239
|
+
:procname: val_as_str
|
240
|
+
|
231
241
|
- :default: "^# *(?<name>[^#]*?) *$"
|
232
242
|
:env_var: MDE_HEADING1_MATCH
|
233
243
|
:opt_name: heading1_match
|
@@ -354,7 +364,7 @@
|
|
354
364
|
|
355
365
|
- :arg_name: BOOL
|
356
366
|
:default: false
|
357
|
-
:description:
|
367
|
+
:description: Controls whether headings(levels 1,2,3) are displayed in the block selection menu
|
358
368
|
:env_var: MDE_MENU_BLOCKS_WITH_HEADINGS
|
359
369
|
:opt_name: menu_blocks_with_headings
|
360
370
|
:procname: val_as_bool
|
@@ -424,7 +434,8 @@
|
|
424
434
|
|
425
435
|
- :arg_name: BOOL
|
426
436
|
:default: false
|
427
|
-
:description: Include imported notes in menu
|
437
|
+
# :description: Include imported notes in menu
|
438
|
+
:description: Whether imported blocks should be included in the menu
|
428
439
|
:env_var: MDE_MENU_INCLUDE_IMPORTED_NOTES
|
429
440
|
:opt_name: menu_include_imported_notes
|
430
441
|
:procname: val_as_bool
|
@@ -606,7 +617,7 @@
|
|
606
617
|
|
607
618
|
- :arg_name: BOOL
|
608
619
|
:default: true
|
609
|
-
:description:
|
620
|
+
:description: Whether standard output from execution is displayed
|
610
621
|
:env_var: MDE_OUTPUT_STDOUT
|
611
622
|
:long_name: output-stdout
|
612
623
|
:opt_name: output_stdout
|
@@ -628,14 +639,14 @@
|
|
628
639
|
|
629
640
|
- :arg_name: BOOL
|
630
641
|
:default: true
|
631
|
-
:description:
|
632
|
-
:env_var:
|
642
|
+
:description: Wheter to pause after manually executing a block and the next menu
|
643
|
+
:env_var: MDE_PAUSE_AFTER_SCRIPT_EXECUTION
|
633
644
|
:opt_name: pause_after_script_execution
|
634
645
|
:procname: val_as_bool
|
635
646
|
|
636
647
|
- :default: "\nContinue?"
|
637
|
-
:description: Prompt after
|
638
|
-
:env_var:
|
648
|
+
:description: Prompt after manually executing a block and the next menu
|
649
|
+
:env_var: MDE_PROMPT_AFTER_SCRIPT_EXECUTION
|
639
650
|
:opt_name: prompt_after_script_execution
|
640
651
|
:procname: val_as_str
|
641
652
|
|
@@ -717,7 +728,7 @@
|
|
717
728
|
|
718
729
|
- :arg_name: BOOL
|
719
730
|
:default: false
|
720
|
-
:description:
|
731
|
+
:description: Wheter to save an executed script`
|
721
732
|
:env_var: MDE_SAVE_EXECUTED_SCRIPT
|
722
733
|
:long_name: save-executed-script
|
723
734
|
:opt_name: save_executed_script
|
@@ -759,7 +770,7 @@
|
|
759
770
|
|
760
771
|
- :arg_name: RELATIVE_PATH
|
761
772
|
:default: logs
|
762
|
-
:description:
|
773
|
+
:description: Folder where saved scripts are stored
|
763
774
|
:env_var: MDE_SAVED_SCRIPT_FOLDER
|
764
775
|
:long_name: saved-script-folder
|
765
776
|
:opt_name: saved_script_folder
|
@@ -884,7 +895,7 @@
|
|
884
895
|
|
885
896
|
- :arg_name: BOOL
|
886
897
|
:default: true
|
887
|
-
:description:
|
898
|
+
:description: Requires user approval before executing a script
|
888
899
|
:env_var: MDE_USER_MUST_APPROVE
|
889
900
|
:long_name: user-must-approve
|
890
901
|
:opt_name: user_must_approve
|
data/lib/menu.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# MDE - Markdown Executor (1.8.
|
1
|
+
# MDE - Markdown Executor (1.8.6)
|
2
2
|
---
|
3
3
|
- :description: Show current configuration values
|
4
4
|
:procname: show_config
|
@@ -15,7 +15,7 @@
|
|
15
15
|
:procname: val_as_str
|
16
16
|
- :arg_name: NAME
|
17
17
|
:compreply: false
|
18
|
-
:description: Name of block
|
18
|
+
:description: Name of block to execute
|
19
19
|
:env_var: MDE_BLOCK_NAME
|
20
20
|
:long_name: block-name
|
21
21
|
:opt_name: block_name
|
@@ -174,17 +174,19 @@
|
|
174
174
|
:procname: exit
|
175
175
|
:short_name: x
|
176
176
|
- :default: "^(?<indent> *)`{3,}"
|
177
|
+
:description: Matches the start and end of a fenced code block
|
177
178
|
:env_var: MDE_FENCED_START_AND_END_REGEX
|
178
179
|
:opt_name: fenced_start_and_end_regex
|
179
180
|
:procname: val_as_str
|
180
181
|
- :default: "^(?<indent> *)`{3,}(?<shell>[^`\\s]*) *:?(?<name>[^\\s]*) *(?<rest>.*)
|
181
182
|
*$"
|
183
|
+
:description: Match the start of a fenced block
|
182
184
|
:env_var: MDE_FENCED_START_EXTENDED_REGEX
|
183
185
|
:opt_name: fenced_start_extended_regex
|
184
186
|
:procname: val_as_str
|
185
187
|
- :arg_name: RELATIVE_PATH
|
186
188
|
:compreply: "."
|
187
|
-
:description: Name of document
|
189
|
+
:description: Name of the document to load
|
188
190
|
:env_var: MDE_FILENAME
|
189
191
|
:long_name: filename
|
190
192
|
:opt_name: filename
|
@@ -196,6 +198,13 @@
|
|
196
198
|
:long_name: find
|
197
199
|
:procname: find
|
198
200
|
:short_name: "?"
|
201
|
+
- :arg_name: FIND_PATH
|
202
|
+
:default: ''
|
203
|
+
:description: Path for find (uses PATH if empty)
|
204
|
+
:env_var: MDE_FIND_PATH
|
205
|
+
:long_name: find-path
|
206
|
+
:opt_name: find_path
|
207
|
+
:procname: val_as_str
|
199
208
|
- :default: "^# *(?<name>[^#]*?) *$"
|
200
209
|
:env_var: MDE_HEADING1_MATCH
|
201
210
|
:opt_name: heading1_match
|
@@ -300,7 +309,8 @@
|
|
300
309
|
:procname: val_as_bool
|
301
310
|
- :arg_name: BOOL
|
302
311
|
:default: false
|
303
|
-
:description:
|
312
|
+
:description: Controls whether headings(levels 1,2,3) are displayed in the block
|
313
|
+
selection menu
|
304
314
|
:env_var: MDE_MENU_BLOCKS_WITH_HEADINGS
|
305
315
|
:opt_name: menu_blocks_with_headings
|
306
316
|
:procname: val_as_bool
|
@@ -359,7 +369,7 @@
|
|
359
369
|
:procname: val_as_bool
|
360
370
|
- :arg_name: BOOL
|
361
371
|
:default: false
|
362
|
-
:description:
|
372
|
+
:description: Whether imported blocks should be included in the menu
|
363
373
|
:env_var: MDE_MENU_INCLUDE_IMPORTED_NOTES
|
364
374
|
:opt_name: menu_include_imported_notes
|
365
375
|
:procname: val_as_bool
|
@@ -511,7 +521,7 @@
|
|
511
521
|
:procname: val_as_bool
|
512
522
|
- :arg_name: BOOL
|
513
523
|
:default: true
|
514
|
-
:description:
|
524
|
+
:description: Whether standard output from execution is displayed
|
515
525
|
:env_var: MDE_OUTPUT_STDOUT
|
516
526
|
:long_name: output-stdout
|
517
527
|
:opt_name: output_stdout
|
@@ -530,15 +540,15 @@
|
|
530
540
|
:short_name: p
|
531
541
|
- :arg_name: BOOL
|
532
542
|
:default: true
|
533
|
-
:description:
|
534
|
-
:env_var:
|
543
|
+
:description: Wheter to pause after manually executing a block and the next menu
|
544
|
+
:env_var: MDE_PAUSE_AFTER_SCRIPT_EXECUTION
|
535
545
|
:opt_name: pause_after_script_execution
|
536
546
|
:procname: val_as_bool
|
537
547
|
- :default: |2-
|
538
548
|
|
539
549
|
Continue?
|
540
|
-
:description: Prompt after
|
541
|
-
:env_var:
|
550
|
+
:description: Prompt after manually executing a block and the next menu
|
551
|
+
:env_var: MDE_PROMPT_AFTER_SCRIPT_EXECUTION
|
542
552
|
:opt_name: prompt_after_script_execution
|
543
553
|
:procname: val_as_str
|
544
554
|
- :default: |2-
|
@@ -615,7 +625,7 @@
|
|
615
625
|
:procname: val_as_int
|
616
626
|
- :arg_name: BOOL
|
617
627
|
:default: false
|
618
|
-
:description:
|
628
|
+
:description: Wheter to save an executed script`
|
619
629
|
:env_var: MDE_SAVE_EXECUTED_SCRIPT
|
620
630
|
:long_name: save-executed-script
|
621
631
|
:opt_name: save_executed_script
|
@@ -651,7 +661,7 @@
|
|
651
661
|
:procname: val_as_str
|
652
662
|
- :arg_name: RELATIVE_PATH
|
653
663
|
:default: logs
|
654
|
-
:description:
|
664
|
+
:description: Folder where saved scripts are stored
|
655
665
|
:env_var: MDE_SAVED_SCRIPT_FOLDER
|
656
666
|
:long_name: saved-script-folder
|
657
667
|
:opt_name: saved_script_folder
|
@@ -760,7 +770,7 @@
|
|
760
770
|
:procname: val_as_bool
|
761
771
|
- :arg_name: BOOL
|
762
772
|
:default: true
|
763
|
-
:description:
|
773
|
+
:description: Requires user approval before executing a script
|
764
774
|
:env_var: MDE_USER_MUST_APPROVE
|
765
775
|
:long_name: user-must-approve
|
766
776
|
:opt_name: user_must_approve
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# encoding=utf-8
|
5
|
+
|
6
|
+
require 'find'
|
7
|
+
|
8
|
+
class RegexpReplacer
|
9
|
+
# Constructor to initialize with file path
|
10
|
+
def initialize(file_path)
|
11
|
+
@file_path = file_path
|
12
|
+
end
|
13
|
+
|
14
|
+
# Perform the replacement based on the specified option
|
15
|
+
def perform_replacement(option)
|
16
|
+
content = File.read(@file_path)
|
17
|
+
modified_content = case option
|
18
|
+
when 1
|
19
|
+
replace_pattern1(content)
|
20
|
+
when 2
|
21
|
+
replace_pattern2(content)
|
22
|
+
else
|
23
|
+
raise "Invalid option. Please choose 1 or 2."
|
24
|
+
end
|
25
|
+
File.write(@file_path, modified_content)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# Replacement for pattern 1
|
31
|
+
def replace_pattern1(content)
|
32
|
+
regexp = /^( *)# (@\w+) ('.+)/
|
33
|
+
substitution = '\1;;pp __LINE__,\3 #\2'
|
34
|
+
content.gsub(regexp, substitution)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Replacement for pattern 2
|
38
|
+
def replace_pattern2(content)
|
39
|
+
regexp = /^( *);;pp __LINE__,(.+) #(@\w+)/
|
40
|
+
substitution = '\1# \3 \2'
|
41
|
+
content.gsub(regexp, substitution)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Running the script with command line arguments
|
46
|
+
if ARGV.length != 2
|
47
|
+
puts "Usage: ruby regexp_replacer.rb [file_path] [option (1 or 2)]"
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
|
51
|
+
file_path, option = ARGV
|
52
|
+
replacer = RegexpReplacer.new(file_path)
|
53
|
+
begin
|
54
|
+
replacer.perform_replacement(option.to_i)
|
55
|
+
puts "Replacement performed successfully."
|
56
|
+
rescue StandardError => e
|
57
|
+
puts "Error: #{e.message}"
|
58
|
+
end
|
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: 1.8.
|
4
|
+
version: 1.8.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fareed Stevenson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-12-
|
11
|
+
date: 2023-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clipboard
|
@@ -157,6 +157,7 @@ files:
|
|
157
157
|
- lib/option_value.rb
|
158
158
|
- lib/pty1.rb
|
159
159
|
- lib/regexp.rb
|
160
|
+
- lib/regexp_replacer.rb
|
160
161
|
- lib/rspec_helpers.rb
|
161
162
|
- lib/saved_assets.rb
|
162
163
|
- lib/saved_files_matcher.rb
|