markdown_exec 1.3.2 → 1.3.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +13 -11
- data/CHANGELOG.md +40 -3
- data/Gemfile +6 -3
- data/Gemfile.lock +112 -34
- data/README.md +5 -84
- data/Rakefile +105 -28
- data/bin/tab_completion.sh +2 -2
- data/lib/cached_nested_file_reader.rb +115 -0
- data/lib/colorize.rb +4 -0
- data/lib/env.rb +1 -0
- data/lib/env_opts.rb +54 -56
- data/lib/environment_opt_parse.rb +24 -19
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/markdown_exec.rb +589 -260
- data/lib/menu.yml +70 -4
- data/lib/object_present.rb +44 -0
- data/lib/rspec_helpers.rb +10 -0
- data/lib/tap.rb +51 -7
- metadata +4 -4
- data/lib/globfiles.rb +0 -40
- data/lib/yaml_env_opts.rb +0 -60
data/lib/menu.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# MDE - Markdown Executor (1.3.
|
1
|
+
# MDE - Markdown Executor (1.3.3.1)
|
2
2
|
---
|
3
3
|
- :arg_name: NAME
|
4
4
|
:compreply: false
|
@@ -101,6 +101,12 @@
|
|
101
101
|
:long_name: pwd
|
102
102
|
:opt_name: pwd
|
103
103
|
:procname: val_as_bool
|
104
|
+
- :arg_name: BOOL
|
105
|
+
:default: false
|
106
|
+
:description: Display only blocks of type "bash"
|
107
|
+
:env_var: MDE_BASH_ONLY
|
108
|
+
:opt_name: bash_only
|
109
|
+
:procname: val_as_bool
|
104
110
|
- :arg_name: INT.0-3
|
105
111
|
:default: 1
|
106
112
|
:description: Output display level (0 to 3 [data, +context, +info])
|
@@ -108,6 +114,32 @@
|
|
108
114
|
:long_name: display-level
|
109
115
|
:opt_name: display_level
|
110
116
|
:procname: val_as_int
|
117
|
+
- :arg_name: REGEX
|
118
|
+
:default:
|
119
|
+
:description: Exclude blocks with name matching
|
120
|
+
:env_var: MDE_EXCLUDE_BY_NAME_REGEX
|
121
|
+
:opt_name: exclude_by_name_regex
|
122
|
+
:procname: val_as_str
|
123
|
+
- :arg_name: REGEX
|
124
|
+
:default:
|
125
|
+
:description: Exclude blocks with shell matching
|
126
|
+
:env_var: MDE_EXCLUDE_BY_SHELL_REGEX
|
127
|
+
:opt_name: exclude_by_shell_regex
|
128
|
+
:procname: val_as_str
|
129
|
+
- :arg_name: BOOL
|
130
|
+
:default: true
|
131
|
+
:description: Hide all blocks of type "expect"
|
132
|
+
:env_var: MDE_EXCLUDE_EXPECT_BLOCKS
|
133
|
+
:opt_name: exclude_expect_blocks
|
134
|
+
:procname: val_as_bool
|
135
|
+
- :arg_name: BOOL
|
136
|
+
:default: true
|
137
|
+
:description: |-
|
138
|
+
Exclude blocks with name matching expression " \
|
139
|
+
"`block_name_hidden_match`
|
140
|
+
:env_var: MDE_HIDE_BLOCKS_BY_NAME
|
141
|
+
:opt_name: hide_blocks_by_name
|
142
|
+
:procname: val_as_bool
|
111
143
|
- :arg_name: INT.1-
|
112
144
|
:default: 32
|
113
145
|
:description: Max. items to return in list
|
@@ -133,6 +165,18 @@
|
|
133
165
|
:env_var: MDE_MENU_BLOCKS_WITH_HEADINGS
|
134
166
|
:opt_name: menu_blocks_with_headings
|
135
167
|
:procname: val_as_bool
|
168
|
+
- :arg_name: BOOL
|
169
|
+
:default: true
|
170
|
+
:description: Display Exit option at top of menu
|
171
|
+
:env_var: MDE_MENU_EXIT_AT_TOP
|
172
|
+
:opt_name: menu_exit_at_top
|
173
|
+
:procname: val_as_bool
|
174
|
+
- :arg_name: BOOL
|
175
|
+
:default: true
|
176
|
+
:description: Display Exit option in menu
|
177
|
+
:env_var: MDE_MENU_WITH_EXIT
|
178
|
+
:opt_name: menu_with_exit
|
179
|
+
:procname: val_as_bool
|
136
180
|
- :arg_name: BOOL
|
137
181
|
:default: false
|
138
182
|
:description: Display summary for execution
|
@@ -140,6 +184,12 @@
|
|
140
184
|
:long_name: output-execution-summary
|
141
185
|
:opt_name: output_execution_summary
|
142
186
|
:procname: val_as_bool
|
187
|
+
- :arg_name: BOOL
|
188
|
+
:default: false
|
189
|
+
:description: Output saved script filename at end of execution
|
190
|
+
:env_var: MDE_OUTPUT_SAVED_SCRIPT_FILENAME
|
191
|
+
:opt_name: output_saved_script_filename
|
192
|
+
:procname: val_as_bool
|
143
193
|
- :arg_name: BOOL
|
144
194
|
:default: false
|
145
195
|
:description: Display script prior to execution
|
@@ -206,6 +256,18 @@
|
|
206
256
|
:env_var: MDE_SAVED_STDOUT_GLOB
|
207
257
|
:opt_name: saved_stdout_glob
|
208
258
|
:procname: val_as_str
|
259
|
+
- :arg_name: REGEX
|
260
|
+
:default:
|
261
|
+
:description: Select blocks with name matching
|
262
|
+
:env_var: MDE_SELECT_BY_NAME_REGEX
|
263
|
+
:opt_name: select_by_name_regex
|
264
|
+
:procname: val_as_str
|
265
|
+
- :arg_name: REGEX
|
266
|
+
:default:
|
267
|
+
:description: Select blocks with shell matching
|
268
|
+
:env_var: MDE_SELECT_BY_SHELL_REGEX
|
269
|
+
:opt_name: select_by_shell_regex
|
270
|
+
:procname: val_as_str
|
209
271
|
- :default: "^[\\(\\[].*[\\)\\]]$"
|
210
272
|
:description: Pattern for blocks to hide from user-selection
|
211
273
|
:env_var: MDE_BLOCK_NAME_HIDDEN_MATCH
|
@@ -223,11 +285,11 @@
|
|
223
285
|
:env_var: MDE_BLOCK_REQUIRED_SCAN
|
224
286
|
:opt_name: block_required_scan
|
225
287
|
:procname: val_as_str
|
226
|
-
- :default: "<(?<full>(?<type>\\$)?(?<name>[A-Za-
|
288
|
+
- :default: "<(?<full>(?<type>\\$)?(?<name>[A-Za-z_\\-\\.\\w]+))"
|
227
289
|
:env_var: MDE_BLOCK_STDIN_SCAN
|
228
290
|
:opt_name: block_stdin_scan
|
229
291
|
:procname: val_as_str
|
230
|
-
- :default: ">(?<full>(?<type>\\$)?(?<name>[A-Za-
|
292
|
+
- :default: ">(?<full>(?<type>\\$)?(?<name>[A-Za-z_\\-\\.\\w]+))"
|
231
293
|
:env_var: MDE_BLOCK_STDOUT_SCAN
|
232
294
|
:opt_name: block_stdout_scan
|
233
295
|
:procname: val_as_str
|
@@ -239,7 +301,7 @@
|
|
239
301
|
:env_var: MDE_FENCED_START_AND_END_MATCH
|
240
302
|
:opt_name: fenced_start_and_end_match
|
241
303
|
:procname: val_as_str
|
242
|
-
- :default: "^`{3,}(?<shell>[^`\\s]*) *(?<
|
304
|
+
- :default: "^`{3,}(?<shell>[^`\\s]*) *:?(?<name>[^\\s]*) *(?<rest>.*) *$"
|
243
305
|
:env_var: MDE_FENCED_START_EX_MATCH
|
244
306
|
:opt_name: fenced_start_ex_match
|
245
307
|
:procname: val_as_str
|
@@ -255,6 +317,10 @@
|
|
255
317
|
:env_var: MDE_HEADING3_MATCH
|
256
318
|
:opt_name: heading3_match
|
257
319
|
:procname: val_as_str
|
320
|
+
- :default: "^ *@import (.+)$"
|
321
|
+
:env_var: MDE_IMPORT_PATTERN
|
322
|
+
:opt_name: import_pattern
|
323
|
+
:procname: val_as_str
|
258
324
|
- :default: "*.[Mm][Dd]"
|
259
325
|
:env_var: MDE_MD_FILENAME_GLOB
|
260
326
|
:opt_name: md_filename_glob
|
data/lib/object_present.rb
CHANGED
@@ -1,7 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
# frozen_string_literal: true
|
2
3
|
|
3
4
|
# encoding=utf-8
|
4
5
|
|
6
|
+
# version 2023-10-02
|
7
|
+
|
8
|
+
require 'bundler/setup'
|
9
|
+
Bundler.require(:default)
|
10
|
+
|
11
|
+
class FalseClass
|
12
|
+
unless defined?(blank?)
|
13
|
+
def present?
|
14
|
+
true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
5
19
|
# is the value empty?
|
6
20
|
#
|
7
21
|
class String
|
@@ -37,3 +51,33 @@ class Object
|
|
37
51
|
end
|
38
52
|
end
|
39
53
|
end
|
54
|
+
|
55
|
+
if $PROGRAM_NAME == __FILE__
|
56
|
+
require 'minitest/autorun'
|
57
|
+
|
58
|
+
class TestStringMethods < Minitest::Test
|
59
|
+
def test_blank
|
60
|
+
assert "".blank?
|
61
|
+
assert " ".blank?
|
62
|
+
assert "\t\n\r".blank?
|
63
|
+
refute "foo".blank?
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_present
|
67
|
+
assert "foo".present?
|
68
|
+
refute "".present?
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class TestObjectMethods < Minitest::Test
|
73
|
+
def test_present
|
74
|
+
assert "foo".present?
|
75
|
+
refute "".present?
|
76
|
+
assert Object.new.present?
|
77
|
+
assert 123.present?
|
78
|
+
assert true.present?
|
79
|
+
assert false.present?
|
80
|
+
refute nil.present?
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# output standard header for file load during testing
|
4
|
+
#
|
5
|
+
def spec_source(file, env_var_name = 'SPEC_DEBUG')
|
6
|
+
if (->(val) { val.nil? ? false : !(val.empty? || val == '0') })
|
7
|
+
.call(ENV.fetch(env_var_name, nil))
|
8
|
+
puts "#{env_var_name}: #{file}"
|
9
|
+
end
|
10
|
+
end
|
data/lib/tap.rb
CHANGED
@@ -5,16 +5,44 @@
|
|
5
5
|
require 'json'
|
6
6
|
require 'yaml'
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
# is the value a non-empty string or a binary?
|
9
|
+
#
|
10
|
+
# :reek:ManualDispatch ### temp
|
11
|
+
class Object
|
12
|
+
unless defined?(present?)
|
13
|
+
def present?
|
14
|
+
case self.class.to_s
|
15
|
+
when 'FalseClass', 'TrueClass'
|
16
|
+
true
|
17
|
+
else
|
18
|
+
self && (!respond_to?(:empty?) || !empty?)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
10
23
|
|
11
|
-
|
24
|
+
unless defined?(Env)
|
25
|
+
# utility functions to read environment variables
|
26
|
+
#
|
27
|
+
module Env
|
28
|
+
# :reek:UtilityFunction
|
29
|
+
def env_int(name, default: 0)
|
30
|
+
return default if name.nil? || (val = ENV.fetch(name, nil)).nil?
|
31
|
+
return default if val.empty?
|
32
|
+
|
33
|
+
val.to_i
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
12
37
|
|
13
38
|
# rubocop:disable Metrics/ParameterLists
|
14
39
|
|
15
40
|
## application-level debug control
|
16
41
|
#
|
42
|
+
# :reek:TooManyConstants
|
17
43
|
module Tap
|
44
|
+
include Env
|
45
|
+
|
18
46
|
DN = 'return'
|
19
47
|
NONE = 0x0
|
20
48
|
T1 = 1 # RESULT
|
@@ -49,6 +77,8 @@ module Tap
|
|
49
77
|
$tap_enable = false
|
50
78
|
$tap_mask = ALL2
|
51
79
|
|
80
|
+
# :reek:BooleanParameter
|
81
|
+
# :reek:ControlParameter
|
52
82
|
def tap_config(enable: true, envvar: nil, value: nil)
|
53
83
|
$tap_enable = false
|
54
84
|
if envvar
|
@@ -66,7 +96,10 @@ module Tap
|
|
66
96
|
self
|
67
97
|
end
|
68
98
|
|
69
|
-
|
99
|
+
# :reek:ControlParameter
|
100
|
+
# :reek:LongParameterList
|
101
|
+
def tap_inspect(name_ = nil, caller_first: nil, mask: TDD, name: DN, source: nil,
|
102
|
+
type: nil)
|
70
103
|
return self unless $tap_enable
|
71
104
|
return self unless (mask & $tap_mask).positive?
|
72
105
|
|
@@ -74,7 +107,7 @@ module Tap
|
|
74
107
|
outs = []
|
75
108
|
outs.push(source.to_s) if source.present?
|
76
109
|
|
77
|
-
vs = (
|
110
|
+
vs = (caller_first || caller[0]).scan(/in `?(\S+)'$/).fetch(0, []).fetch(0, '')
|
78
111
|
outs.push("#{vs}()") if vs.present?
|
79
112
|
|
80
113
|
outs.push(tap_named_value(name_ || name, method(fn).call))
|
@@ -91,6 +124,14 @@ module Tap
|
|
91
124
|
self
|
92
125
|
end
|
93
126
|
|
127
|
+
def tap_pry
|
128
|
+
return self unless $tap_enable
|
129
|
+
|
130
|
+
binding.pry
|
131
|
+
self
|
132
|
+
end
|
133
|
+
|
134
|
+
# :reek:ControlParameter
|
94
135
|
def tap_puts(name_ = nil, mask: TDD, name: nil)
|
95
136
|
return self unless $tap_enable
|
96
137
|
return self unless (mask & $tap_mask).positive?
|
@@ -99,8 +140,11 @@ module Tap
|
|
99
140
|
self
|
100
141
|
end
|
101
142
|
|
102
|
-
|
103
|
-
|
143
|
+
# :reek:ControlParameter
|
144
|
+
# :reek:LongParameterList
|
145
|
+
def tap_yaml(name_ = nil, caller_first: nil, mask: TDD, name: DN, source: nil)
|
146
|
+
tap_inspect name_, caller_first: (caller_first || caller[0]),
|
147
|
+
mask: mask, name: name, source: source, type: :yaml
|
104
148
|
end
|
105
149
|
|
106
150
|
private
|
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.3.
|
4
|
+
version: 1.3.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fareed Stevenson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clipboard
|
@@ -110,19 +110,19 @@ files:
|
|
110
110
|
- bin/setup
|
111
111
|
- bin/tab_completion.sh
|
112
112
|
- bin/tab_completion.sh.erb
|
113
|
+
- lib/cached_nested_file_reader.rb
|
113
114
|
- lib/cli.rb
|
114
115
|
- lib/colorize.rb
|
115
116
|
- lib/env.rb
|
116
117
|
- lib/env_opts.rb
|
117
118
|
- lib/environment_opt_parse.rb
|
118
|
-
- lib/globfiles.rb
|
119
119
|
- lib/markdown_exec.rb
|
120
120
|
- lib/markdown_exec/version.rb
|
121
121
|
- lib/menu.yml
|
122
122
|
- lib/object_present.rb
|
123
|
+
- lib/rspec_helpers.rb
|
123
124
|
- lib/shared.rb
|
124
125
|
- lib/tap.rb
|
125
|
-
- lib/yaml_env_opts.rb
|
126
126
|
homepage: https://rubygems.org/gems/markdown_exec
|
127
127
|
licenses:
|
128
128
|
- MIT
|
data/lib/globfiles.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# encoding=utf-8
|
4
|
-
|
5
|
-
# require 'json'
|
6
|
-
# require 'yaml'
|
7
|
-
|
8
|
-
# require_relative 'env'
|
9
|
-
# include Env
|
10
|
-
|
11
|
-
## directory listing of saved files matching glob
|
12
|
-
#
|
13
|
-
class Globfiles
|
14
|
-
def initialize(folder, glob)
|
15
|
-
@folder = folder
|
16
|
-
@glob = glob
|
17
|
-
end
|
18
|
-
|
19
|
-
def list_all
|
20
|
-
Dir.glob(File.join(@folder, @glob)).tap_inspect
|
21
|
-
end
|
22
|
-
|
23
|
-
## single most recent item
|
24
|
-
#
|
25
|
-
def most_recent(arr = nil)
|
26
|
-
arr = list_all if arr.nil?
|
27
|
-
return if arr.count < 1
|
28
|
-
|
29
|
-
arr.max.tap_inspect
|
30
|
-
end
|
31
|
-
|
32
|
-
## multiple recent items
|
33
|
-
#
|
34
|
-
def most_recent_list(list_count, arr = nil)
|
35
|
-
arr = list_all if arr.nil?
|
36
|
-
return if (ac = arr.count) < 1
|
37
|
-
|
38
|
-
arr.sort[-[ac, list_count].min..].reverse.tap_inspect
|
39
|
-
end
|
40
|
-
end # class Globfiles
|
data/lib/yaml_env_opts.rb
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# encoding=utf-8
|
4
|
-
|
5
|
-
require 'yaml'
|
6
|
-
|
7
|
-
require_relative 'env_opts'
|
8
|
-
require_relative 'object_present'
|
9
|
-
require_relative 'tap'
|
10
|
-
|
11
|
-
include Tap #; tap_config
|
12
|
-
|
13
|
-
# read configuration YAML file during initalization
|
14
|
-
# value priority: menu default < configuration file < environment variable < command argument
|
15
|
-
#
|
16
|
-
class YamlEnvOpts < EnvOpts
|
17
|
-
def initialize(opts_raw = {}, argv: ARGV, configuration_yaml_filespec: '', values: nil)
|
18
|
-
super(opts_raw || {}, nil)
|
19
|
-
per_values(values)
|
20
|
-
configure_yaml_filespec(configuration_yaml_filespec)
|
21
|
-
set_keys_value_per_environment_as_cast(opts_raw)
|
22
|
-
parse(argv)
|
23
|
-
|
24
|
-
self # rubocop:disable Lint/Void
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def apply_configuration(settings)
|
30
|
-
settings.tap_inspect 'settings'
|
31
|
-
return if settings.nil?
|
32
|
-
|
33
|
-
settings.each do |name, value|
|
34
|
-
set_key_value_as_cast(name, value)
|
35
|
-
end.tap_inspect
|
36
|
-
end
|
37
|
-
|
38
|
-
def configure_yaml_filespec(configuration_yaml_filespec)
|
39
|
-
apply_configuration(read_configuration_yaml(configuration_yaml_filespec))
|
40
|
-
end
|
41
|
-
|
42
|
-
def per_values(settings)
|
43
|
-
settings.tap_inspect 'settings'
|
44
|
-
return self if settings.nil?
|
45
|
-
return self if settings.count.zero?
|
46
|
-
|
47
|
-
settings.each do |name, value|
|
48
|
-
set_key_value_as_cast(name, value)
|
49
|
-
end
|
50
|
-
|
51
|
-
self
|
52
|
-
end
|
53
|
-
|
54
|
-
def read_configuration_yaml(configuration_yaml_filespec)
|
55
|
-
configuration_yaml_filespec.tap_inspect 'configuration_yaml_filespec'
|
56
|
-
return unless configuration_yaml_filespec.present?
|
57
|
-
|
58
|
-
YAML.safe_load(File.read(configuration_yaml_filespec) || '').tap_inspect
|
59
|
-
end
|
60
|
-
end
|