markdown_exec 1.8.5 → 1.8.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.pryrc +0 -1
- data/.rubocop.yml +0 -2
- data/CHANGELOG.md +22 -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 +24 -2
- data/lib/ansi_formatter.rb +1 -5
- data/lib/cached_nested_file_reader.rb +1 -7
- data/lib/constants.rb +17 -0
- data/lib/directory_searcher.rb +1 -6
- data/lib/filter.rb +15 -3
- data/lib/hash_delegator.rb +557 -504
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/markdown_exec.rb +12 -8
- data/lib/mdoc.rb +33 -12
- data/lib/menu.src.yml +95 -16
- data/lib/menu.yml +84 -17
- data/lib/regexp_replacer.rb +58 -0
- data/lib/saved_assets.rb +10 -8
- metadata +5 -4
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/mdoc.rb
CHANGED
@@ -23,6 +23,7 @@ module MarkdownExec
|
|
23
23
|
#
|
24
24
|
def initialize(table = [])
|
25
25
|
@table = table
|
26
|
+
# &bc '@table.count:',@table.count
|
26
27
|
end
|
27
28
|
|
28
29
|
def collect_block_code_cann(fcb)
|
@@ -69,20 +70,28 @@ module MarkdownExec
|
|
69
70
|
# @param name [String] The name of the code block to start the retrieval from.
|
70
71
|
# @return [Array<Hash>] An array of code blocks required by the specified code block.
|
71
72
|
#
|
72
|
-
def
|
73
|
+
def collect_block_dependencies(name)
|
73
74
|
name_block = get_block_by_anyname(name)
|
74
75
|
if name_block.nil? || name_block.keys.empty?
|
75
76
|
raise "Named code block `#{name}` not found. (@#{__LINE__})"
|
76
77
|
end
|
77
78
|
|
78
79
|
dependencies = collect_dependencies(name_block[:oname])
|
80
|
+
# &bc 'dependencies.count:',dependencies.count
|
79
81
|
all_dependency_names = collect_unique_names(dependencies).push(name_block[:oname]).uniq
|
80
|
-
|
82
|
+
# &bc 'all_dependency_names.count:',all_dependency_names.count
|
81
83
|
|
82
|
-
# in order of appearance in
|
83
|
-
#
|
84
|
-
blocks = @table.select
|
85
|
-
|
84
|
+
# select non-chrome blocks in order of appearance in source documents
|
85
|
+
#
|
86
|
+
blocks = @table.select do |fcb|
|
87
|
+
!fcb.fetch(:chrome, false) && all_dependency_names.include?(fcb.fetch(:oname))
|
88
|
+
end
|
89
|
+
# &bc 'blocks.count:',blocks.count
|
90
|
+
|
91
|
+
## add cann key to blocks, calc unmet_dependencies
|
92
|
+
#
|
93
|
+
unmet_dependencies = all_dependency_names.dup
|
94
|
+
blocks = blocks.map do |fcb|
|
86
95
|
unmet_dependencies.delete(fcb[:oname]) # may not exist if block name is duplicated
|
87
96
|
if (call = fcb[:call])
|
88
97
|
[get_block_by_oname("[#{call.match(/^%\((\S+) |\)/)[1]}]")
|
@@ -91,6 +100,7 @@ module MarkdownExec
|
|
91
100
|
[]
|
92
101
|
end + [fcb]
|
93
102
|
end.flatten(1)
|
103
|
+
# &bc 'unmet_dependencies.count:',unmet_dependencies.count
|
94
104
|
|
95
105
|
{ all_dependency_names: all_dependency_names,
|
96
106
|
blocks: blocks,
|
@@ -103,11 +113,13 @@ module MarkdownExec
|
|
103
113
|
# @param name [String] The name of the code block to start the collection from.
|
104
114
|
# @return [Array<String>] An array of strings containing the collected code blocks.
|
105
115
|
#
|
106
|
-
def collect_recursively_required_code(name, label_body: true, label_format_above: nil,
|
107
|
-
label_format_below: nil
|
108
|
-
block_search =
|
116
|
+
def collect_recursively_required_code(name, block_source:, label_body: true, label_format_above: nil,
|
117
|
+
label_format_below: nil)
|
118
|
+
block_search = collect_block_dependencies(name)
|
109
119
|
if block_search[:blocks]
|
110
120
|
blocks = collect_wrapped_blocks(block_search[:blocks])
|
121
|
+
# &bc 'blocks.count:',blocks.count
|
122
|
+
|
111
123
|
block_search.merge(
|
112
124
|
{ block_names: blocks.map { |block| block[:oname] },
|
113
125
|
code: blocks.map do |fcb|
|
@@ -134,6 +146,8 @@ module MarkdownExec
|
|
134
146
|
else
|
135
147
|
block_search.merge({ block_names: [], code: [] })
|
136
148
|
end
|
149
|
+
rescue StandardError
|
150
|
+
error_handler('collect_recursively_required_code')
|
137
151
|
end
|
138
152
|
|
139
153
|
def collect_unique_names(hash)
|
@@ -160,6 +174,13 @@ module MarkdownExec
|
|
160
174
|
end.flatten(1).compact
|
161
175
|
end
|
162
176
|
|
177
|
+
def error_handler(name = '', opts = {})
|
178
|
+
Exceptions.error_handler(
|
179
|
+
"MDoc.#{name} -- #{$!}",
|
180
|
+
opts
|
181
|
+
)
|
182
|
+
end
|
183
|
+
|
163
184
|
# Retrieves code blocks based on the provided options.
|
164
185
|
#
|
165
186
|
# @param opts [Hash] The options used for filtering code blocks.
|
@@ -432,13 +453,13 @@ if $PROGRAM_NAME == __FILE__
|
|
432
453
|
end
|
433
454
|
|
434
455
|
### broken test
|
435
|
-
def
|
436
|
-
result = @doc.
|
456
|
+
def test_collect_block_dependencies
|
457
|
+
result = @doc.collect_block_dependencies('block3')[:blocks]
|
437
458
|
expected_result = [@table[0], @table[1], @table[2]]
|
438
459
|
assert_equal expected_result, result
|
439
460
|
|
440
461
|
assert_raises(RuntimeError) do
|
441
|
-
@doc.
|
462
|
+
@doc.collect_block_dependencies('missing_block')
|
442
463
|
end
|
443
464
|
end
|
444
465
|
|
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,17 +230,25 @@
|
|
228
230
|
:procname: find
|
229
231
|
:short_name: "?"
|
230
232
|
|
231
|
-
- :
|
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
|
+
|
241
|
+
- :default: "^# *(?<line>[^#]*?) *$"
|
232
242
|
:env_var: MDE_HEADING1_MATCH
|
233
243
|
:opt_name: heading1_match
|
234
244
|
:procname: val_as_str
|
235
245
|
|
236
|
-
- :default: "^## *(?<
|
246
|
+
- :default: "^## *(?<line>[^#]*?) *$"
|
237
247
|
:env_var: MDE_HEADING2_MATCH
|
238
248
|
:opt_name: heading2_match
|
239
249
|
:procname: val_as_str
|
240
250
|
|
241
|
-
- :default: "^### *(?<
|
251
|
+
- :default: "^### *(?<line>.+?) *$"
|
242
252
|
:env_var: MDE_HEADING3_MATCH
|
243
253
|
:opt_name: heading3_match
|
244
254
|
:procname: val_as_str
|
@@ -353,8 +363,8 @@
|
|
353
363
|
:procname: val_as_bool
|
354
364
|
|
355
365
|
- :arg_name: BOOL
|
356
|
-
:default:
|
357
|
-
:description:
|
366
|
+
:default: true
|
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
|
@@ -409,6 +419,42 @@
|
|
409
419
|
:opt_name: menu_final_divider
|
410
420
|
:procname: val_as_str
|
411
421
|
|
422
|
+
- :default: fg_rgbh_80_80_c0
|
423
|
+
:description: Color for heading 1 in menu
|
424
|
+
:env_var: MDE_MENU_HEADING1_COLOR
|
425
|
+
:opt_name: menu_heading1_color
|
426
|
+
:procname: val_as_str
|
427
|
+
|
428
|
+
- :default: "# %{line}"
|
429
|
+
:description: format for menu heading1 in menu
|
430
|
+
:env_var: MDE_MENU_HEADING1_FORMAT
|
431
|
+
:opt_name: menu_heading1_format
|
432
|
+
:procname: val_as_str
|
433
|
+
|
434
|
+
- :default: fg_rgbh_60_60_c0
|
435
|
+
:description: Color for heading 2 in menu
|
436
|
+
:env_var: MDE_MENU_HEADING2_COLOR
|
437
|
+
:opt_name: menu_heading2_color
|
438
|
+
:procname: val_as_str
|
439
|
+
|
440
|
+
- :default: "## %{line}"
|
441
|
+
:description: format for menu heading2 in menu
|
442
|
+
:env_var: MDE_MENU_HEADING2_FORMAT
|
443
|
+
:opt_name: menu_heading2_format
|
444
|
+
:procname: val_as_str
|
445
|
+
|
446
|
+
- :default: fg_rgbh_40_40_c0
|
447
|
+
:description: Color for heading 3 in menu
|
448
|
+
:env_var: MDE_MENU_HEADING3_COLOR
|
449
|
+
:opt_name: menu_heading3_color
|
450
|
+
:procname: val_as_str
|
451
|
+
|
452
|
+
- :default: "### %{line}"
|
453
|
+
:description: format for menu heading3 in menu
|
454
|
+
:env_var: MDE_MENU_HEADING3_FORMAT
|
455
|
+
:opt_name: menu_heading3_format
|
456
|
+
:procname: val_as_str
|
457
|
+
|
412
458
|
- :default: "0"
|
413
459
|
:description: Import levels for blocks to appear in menu. Empty is all.
|
414
460
|
:env_var: MDE_MENU_IMPORT_LEVEL_MATCH
|
@@ -424,11 +470,31 @@
|
|
424
470
|
|
425
471
|
- :arg_name: BOOL
|
426
472
|
:default: false
|
427
|
-
:description: Include imported notes in menu
|
473
|
+
# :description: Include imported notes in menu
|
474
|
+
:description: Whether imported blocks should be included in the menu
|
428
475
|
:env_var: MDE_MENU_INCLUDE_IMPORTED_NOTES
|
429
476
|
:opt_name: menu_include_imported_notes
|
430
477
|
:procname: val_as_bool
|
431
478
|
|
479
|
+
- :arg_name: BOOL
|
480
|
+
:default: true
|
481
|
+
:description: Display inherited lines at top of menu (vs bottom)
|
482
|
+
:env_var: MDE_MENU_INHERITED_LINES_AT_TOP
|
483
|
+
:opt_name: menu_inherited_lines_at_top
|
484
|
+
:procname: val_as_bool
|
485
|
+
|
486
|
+
- :default: fg_rgbh_94_00_D3
|
487
|
+
:description: Color of inherited lines in menu
|
488
|
+
:env_var: MDE_MENU_INHERITED_LINES_COLOR
|
489
|
+
:opt_name: menu_inherited_lines_color
|
490
|
+
:procname: val_as_str
|
491
|
+
|
492
|
+
- :default: "%{line}"
|
493
|
+
:description: format for inherited lines in menu
|
494
|
+
:env_var: MDE_MENU_INHERITED_LINES_FORMAT
|
495
|
+
:opt_name: menu_inherited_lines_format
|
496
|
+
:procname: val_as_str
|
497
|
+
|
432
498
|
- :default:
|
433
499
|
:line: ""
|
434
500
|
:description: opening demarcation for menu
|
@@ -500,6 +566,12 @@
|
|
500
566
|
:opt_name: menu_opts_set_format
|
501
567
|
:procname: val_as_str
|
502
568
|
|
569
|
+
- :default: "."
|
570
|
+
:description: Block name to display menu
|
571
|
+
:env_var: MDE_MENU_PERSIST_BLOCK_NAME
|
572
|
+
:opt_name: menu_persist_block_name
|
573
|
+
:procname: val_as_str
|
574
|
+
|
503
575
|
- :default: fg_rgbh_ff_ff_ff
|
504
576
|
:description: Color of menu task
|
505
577
|
:env_var: MDE_MENU_TASK_COLOR
|
@@ -556,6 +628,13 @@
|
|
556
628
|
:opt_name: menu_with_exit
|
557
629
|
:procname: val_as_bool
|
558
630
|
|
631
|
+
- :arg_name: BOOL
|
632
|
+
:default: true
|
633
|
+
:description: Display inherited lines in menu
|
634
|
+
:env_var: MDE_MENU_WITH_INHERITED_LINES
|
635
|
+
:opt_name: menu_with_inherited_lines
|
636
|
+
:procname: val_as_bool
|
637
|
+
|
559
638
|
- :arg_name: BOOL
|
560
639
|
:default: false
|
561
640
|
:description: Hide decorative menu entries
|
@@ -606,7 +685,7 @@
|
|
606
685
|
|
607
686
|
- :arg_name: BOOL
|
608
687
|
:default: true
|
609
|
-
:description:
|
688
|
+
:description: Whether standard output from execution is displayed
|
610
689
|
:env_var: MDE_OUTPUT_STDOUT
|
611
690
|
:long_name: output-stdout
|
612
691
|
:opt_name: output_stdout
|
@@ -628,14 +707,14 @@
|
|
628
707
|
|
629
708
|
- :arg_name: BOOL
|
630
709
|
:default: true
|
631
|
-
:description:
|
632
|
-
:env_var:
|
710
|
+
:description: Wheter to pause after manually executing a block and the next menu
|
711
|
+
:env_var: MDE_PAUSE_AFTER_SCRIPT_EXECUTION
|
633
712
|
:opt_name: pause_after_script_execution
|
634
713
|
:procname: val_as_bool
|
635
714
|
|
636
715
|
- :default: "\nContinue?"
|
637
|
-
:description: Prompt after
|
638
|
-
:env_var:
|
716
|
+
:description: Prompt after manually executing a block and the next menu
|
717
|
+
:env_var: MDE_PROMPT_AFTER_SCRIPT_EXECUTION
|
639
718
|
:opt_name: prompt_after_script_execution
|
640
719
|
:procname: val_as_str
|
641
720
|
|
@@ -717,7 +796,7 @@
|
|
717
796
|
|
718
797
|
- :arg_name: BOOL
|
719
798
|
:default: false
|
720
|
-
:description:
|
799
|
+
:description: Wheter to save an executed script`
|
721
800
|
:env_var: MDE_SAVE_EXECUTED_SCRIPT
|
722
801
|
:long_name: save-executed-script
|
723
802
|
:opt_name: save_executed_script
|
@@ -759,7 +838,7 @@
|
|
759
838
|
|
760
839
|
- :arg_name: RELATIVE_PATH
|
761
840
|
:default: logs
|
762
|
-
:description:
|
841
|
+
:description: Folder where saved scripts are stored
|
763
842
|
:env_var: MDE_SAVED_SCRIPT_FOLDER
|
764
843
|
:long_name: saved-script-folder
|
765
844
|
:opt_name: saved_script_folder
|
@@ -884,7 +963,7 @@
|
|
884
963
|
|
885
964
|
- :arg_name: BOOL
|
886
965
|
:default: true
|
887
|
-
:description:
|
966
|
+
:description: Requires user approval before executing a script
|
888
967
|
:env_var: MDE_USER_MUST_APPROVE
|
889
968
|
:long_name: user-must-approve
|
890
969
|
: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.7)
|
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,15 +198,22 @@
|
|
196
198
|
:long_name: find
|
197
199
|
:procname: find
|
198
200
|
:short_name: "?"
|
199
|
-
- :
|
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
|
208
|
+
- :default: "^# *(?<line>[^#]*?) *$"
|
200
209
|
:env_var: MDE_HEADING1_MATCH
|
201
210
|
:opt_name: heading1_match
|
202
211
|
:procname: val_as_str
|
203
|
-
- :default: "^## *(?<
|
212
|
+
- :default: "^## *(?<line>[^#]*?) *$"
|
204
213
|
:env_var: MDE_HEADING2_MATCH
|
205
214
|
:opt_name: heading2_match
|
206
215
|
:procname: val_as_str
|
207
|
-
- :default: "^### *(?<
|
216
|
+
- :default: "^### *(?<line>.+?) *$"
|
208
217
|
:env_var: MDE_HEADING3_MATCH
|
209
218
|
:opt_name: heading3_match
|
210
219
|
:procname: val_as_str
|
@@ -299,8 +308,9 @@
|
|
299
308
|
:opt_name: menu_blocks_with_docname
|
300
309
|
:procname: val_as_bool
|
301
310
|
- :arg_name: BOOL
|
302
|
-
:default:
|
303
|
-
:description:
|
311
|
+
:default: true
|
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
|
@@ -346,6 +356,36 @@
|
|
346
356
|
:env_var: MDE_MENU_FINAL_DIVIDER
|
347
357
|
:opt_name: menu_final_divider
|
348
358
|
:procname: val_as_str
|
359
|
+
- :default: fg_rgbh_80_80_c0
|
360
|
+
:description: Color for heading 1 in menu
|
361
|
+
:env_var: MDE_MENU_HEADING1_COLOR
|
362
|
+
:opt_name: menu_heading1_color
|
363
|
+
:procname: val_as_str
|
364
|
+
- :default: "# %{line}"
|
365
|
+
:description: format for menu heading1 in menu
|
366
|
+
:env_var: MDE_MENU_HEADING1_FORMAT
|
367
|
+
:opt_name: menu_heading1_format
|
368
|
+
:procname: val_as_str
|
369
|
+
- :default: fg_rgbh_60_60_c0
|
370
|
+
:description: Color for heading 2 in menu
|
371
|
+
:env_var: MDE_MENU_HEADING2_COLOR
|
372
|
+
:opt_name: menu_heading2_color
|
373
|
+
:procname: val_as_str
|
374
|
+
- :default: "## %{line}"
|
375
|
+
:description: format for menu heading2 in menu
|
376
|
+
:env_var: MDE_MENU_HEADING2_FORMAT
|
377
|
+
:opt_name: menu_heading2_format
|
378
|
+
:procname: val_as_str
|
379
|
+
- :default: fg_rgbh_40_40_c0
|
380
|
+
:description: Color for heading 3 in menu
|
381
|
+
:env_var: MDE_MENU_HEADING3_COLOR
|
382
|
+
:opt_name: menu_heading3_color
|
383
|
+
:procname: val_as_str
|
384
|
+
- :default: "### %{line}"
|
385
|
+
:description: format for menu heading3 in menu
|
386
|
+
:env_var: MDE_MENU_HEADING3_FORMAT
|
387
|
+
:opt_name: menu_heading3_format
|
388
|
+
:procname: val_as_str
|
349
389
|
- :default: '0'
|
350
390
|
:description: Import levels for blocks to appear in menu. Empty is all.
|
351
391
|
:env_var: MDE_MENU_IMPORT_LEVEL_MATCH
|
@@ -359,10 +399,26 @@
|
|
359
399
|
:procname: val_as_bool
|
360
400
|
- :arg_name: BOOL
|
361
401
|
:default: false
|
362
|
-
:description:
|
402
|
+
:description: Whether imported blocks should be included in the menu
|
363
403
|
:env_var: MDE_MENU_INCLUDE_IMPORTED_NOTES
|
364
404
|
:opt_name: menu_include_imported_notes
|
365
405
|
:procname: val_as_bool
|
406
|
+
- :arg_name: BOOL
|
407
|
+
:default: true
|
408
|
+
:description: Display inherited lines at top of menu (vs bottom)
|
409
|
+
:env_var: MDE_MENU_INHERITED_LINES_AT_TOP
|
410
|
+
:opt_name: menu_inherited_lines_at_top
|
411
|
+
:procname: val_as_bool
|
412
|
+
- :default: fg_rgbh_94_00_D3
|
413
|
+
:description: Color of inherited lines in menu
|
414
|
+
:env_var: MDE_MENU_INHERITED_LINES_COLOR
|
415
|
+
:opt_name: menu_inherited_lines_color
|
416
|
+
:procname: val_as_str
|
417
|
+
- :default: "%{line}"
|
418
|
+
:description: format for inherited lines in menu
|
419
|
+
:env_var: MDE_MENU_INHERITED_LINES_FORMAT
|
420
|
+
:opt_name: menu_inherited_lines_format
|
421
|
+
:procname: val_as_str
|
366
422
|
- :default:
|
367
423
|
:line: ''
|
368
424
|
:description: opening demarcation for menu
|
@@ -421,6 +477,11 @@
|
|
421
477
|
:env_var: MDE_MENU_OPTS_SET_FORMAT
|
422
478
|
:opt_name: menu_opts_set_format
|
423
479
|
:procname: val_as_str
|
480
|
+
- :default: "."
|
481
|
+
:description: Block name to display menu
|
482
|
+
:env_var: MDE_MENU_PERSIST_BLOCK_NAME
|
483
|
+
:opt_name: menu_persist_block_name
|
484
|
+
:procname: val_as_str
|
424
485
|
- :default: fg_rgbh_ff_ff_ff
|
425
486
|
:description: Color of menu task
|
426
487
|
:env_var: MDE_MENU_TASK_COLOR
|
@@ -468,6 +529,12 @@
|
|
468
529
|
:env_var: MDE_MENU_WITH_EXIT
|
469
530
|
:opt_name: menu_with_exit
|
470
531
|
:procname: val_as_bool
|
532
|
+
- :arg_name: BOOL
|
533
|
+
:default: true
|
534
|
+
:description: Display inherited lines in menu
|
535
|
+
:env_var: MDE_MENU_WITH_INHERITED_LINES
|
536
|
+
:opt_name: menu_with_inherited_lines
|
537
|
+
:procname: val_as_bool
|
471
538
|
- :arg_name: BOOL
|
472
539
|
:default: false
|
473
540
|
:description: Hide decorative menu entries
|
@@ -511,7 +578,7 @@
|
|
511
578
|
:procname: val_as_bool
|
512
579
|
- :arg_name: BOOL
|
513
580
|
:default: true
|
514
|
-
:description:
|
581
|
+
:description: Whether standard output from execution is displayed
|
515
582
|
:env_var: MDE_OUTPUT_STDOUT
|
516
583
|
:long_name: output-stdout
|
517
584
|
:opt_name: output_stdout
|
@@ -530,15 +597,15 @@
|
|
530
597
|
:short_name: p
|
531
598
|
- :arg_name: BOOL
|
532
599
|
:default: true
|
533
|
-
:description:
|
534
|
-
:env_var:
|
600
|
+
:description: Wheter to pause after manually executing a block and the next menu
|
601
|
+
:env_var: MDE_PAUSE_AFTER_SCRIPT_EXECUTION
|
535
602
|
:opt_name: pause_after_script_execution
|
536
603
|
:procname: val_as_bool
|
537
604
|
- :default: |2-
|
538
605
|
|
539
606
|
Continue?
|
540
|
-
:description: Prompt after
|
541
|
-
:env_var:
|
607
|
+
:description: Prompt after manually executing a block and the next menu
|
608
|
+
:env_var: MDE_PROMPT_AFTER_SCRIPT_EXECUTION
|
542
609
|
:opt_name: prompt_after_script_execution
|
543
610
|
:procname: val_as_str
|
544
611
|
- :default: |2-
|
@@ -615,7 +682,7 @@
|
|
615
682
|
:procname: val_as_int
|
616
683
|
- :arg_name: BOOL
|
617
684
|
:default: false
|
618
|
-
:description:
|
685
|
+
:description: Wheter to save an executed script`
|
619
686
|
:env_var: MDE_SAVE_EXECUTED_SCRIPT
|
620
687
|
:long_name: save-executed-script
|
621
688
|
:opt_name: save_executed_script
|
@@ -651,7 +718,7 @@
|
|
651
718
|
:procname: val_as_str
|
652
719
|
- :arg_name: RELATIVE_PATH
|
653
720
|
:default: logs
|
654
|
-
:description:
|
721
|
+
:description: Folder where saved scripts are stored
|
655
722
|
:env_var: MDE_SAVED_SCRIPT_FOLDER
|
656
723
|
:long_name: saved-script-folder
|
657
724
|
:opt_name: saved_script_folder
|
@@ -760,7 +827,7 @@
|
|
760
827
|
:procname: val_as_bool
|
761
828
|
- :arg_name: BOOL
|
762
829
|
:default: true
|
763
|
-
:description:
|
830
|
+
:description: Requires user approval before executing a script
|
764
831
|
:env_var: MDE_USER_MUST_APPROVE
|
765
832
|
:long_name: user-must-approve
|
766
833
|
: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 'v'
|
19
|
+
verbose(content)
|
20
|
+
when 'q'
|
21
|
+
quiet(content)
|
22
|
+
else
|
23
|
+
raise "Invalid option. Please choose 'v' or 'q'."
|
24
|
+
end
|
25
|
+
File.write(@file_path, modified_content)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# Replacement for pattern 'v'
|
31
|
+
def verbose(content)
|
32
|
+
regexp = /^( *)# (&\w+) ('.+)/
|
33
|
+
substitution = '\1;;pp [__LINE__,\3] #\2'
|
34
|
+
content.gsub(regexp, substitution)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Replacement for pattern 'q'
|
38
|
+
def quiet(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 ('v' or 'q')]"
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
|
51
|
+
file_path, option = ARGV
|
52
|
+
replacer = RegexpReplacer.new(file_path)
|
53
|
+
begin
|
54
|
+
replacer.perform_replacement(option)
|
55
|
+
puts "Replacement performed successfully."
|
56
|
+
rescue StandardError => e
|
57
|
+
puts "Error: #{e.message}"
|
58
|
+
end
|