markdown_exec 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +16 -1
- data/CHANGELOG.md +7 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +19 -1
- data/README.md +4 -0
- data/Rakefile +9 -2
- data/bin/tab_completion.sh +2 -2
- data/lib/env.rb +7 -3
- data/lib/env_opts.rb +244 -0
- data/lib/environment_opt_parse.rb +4 -0
- data/lib/markdown_exec/version.rb +1 -1
- data/lib/markdown_exec.rb +8 -25
- data/lib/menu.yml +1 -1
- data/lib/object_present.rb +0 -1
- data/lib/tap.rb +32 -12
- data/lib/yaml_env_opts.rb +60 -0
- 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: 4350ee3346d6295cea603ec3602ce13c3cff3ebe83ff766c873141bebd28dca6
|
4
|
+
data.tar.gz: 57f150a38020be6404bdf140755c7328f70417f1fd98286c2974492d085707c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a412d4bf068a09371989336b50e82822e142fa27ee45c2d578a0d40834e74a618fbe968a26e10640a127c0c1078ecb1a65798bb19c7b171cfc07f11b08e03f3
|
7
|
+
data.tar.gz: e6df4504a02de72dcf40b07acc39cb24752916511217354d485502183469ac061ab841d7fdfbe30e63ffa93cd87c403ec619678998b17adce7e7b68bef87eb2d
|
data/.rubocop.yml
CHANGED
@@ -9,6 +9,9 @@ AllCops:
|
|
9
9
|
Layout/LeadingCommentSpace:
|
10
10
|
Enabled: false
|
11
11
|
|
12
|
+
Layout/LineContinuationLeadingSpace:
|
13
|
+
Enabled: false
|
14
|
+
|
12
15
|
Lint/SafeNavigationChain:
|
13
16
|
Enabled: false
|
14
17
|
|
@@ -38,7 +41,16 @@ Metrics/PerceivedComplexity:
|
|
38
41
|
|
39
42
|
Minitest/MultipleAssertions:
|
40
43
|
Enabled: false
|
41
|
-
|
44
|
+
|
45
|
+
# RSpec/AnyInstance:
|
46
|
+
# Enabled: false
|
47
|
+
|
48
|
+
# RSpec/MultipleExpectations:
|
49
|
+
# Enabled: true
|
50
|
+
|
51
|
+
# RSpec/StubbedMock:
|
52
|
+
# Enabled: false
|
53
|
+
|
42
54
|
Security/YAMLLoad:
|
43
55
|
Enabled: false
|
44
56
|
|
@@ -57,6 +69,9 @@ Style/MixinUsage:
|
|
57
69
|
Style/MultilineBlockChain:
|
58
70
|
Enabled: false
|
59
71
|
|
72
|
+
Style/SlicingWithRange:
|
73
|
+
Enabled: false
|
74
|
+
|
60
75
|
Style/StringLiterals:
|
61
76
|
Enabled: true
|
62
77
|
EnforcedStyle: single_quotes
|
data/CHANGELOG.md
CHANGED
@@ -78,6 +78,13 @@
|
|
78
78
|
- [ ] command to export each command to file, menu for list
|
79
79
|
- [ ] list of fenced code blocks to ignore, eg ```expect or ```mermaid
|
80
80
|
|
81
|
+
## [1.3.2] - 2022-11-12
|
82
|
+
|
83
|
+
### Added
|
84
|
+
|
85
|
+
- Add EnvOpts class
|
86
|
+
- RSpec for internal classes
|
87
|
+
|
81
88
|
## [1.3.1] - 2022-10-29
|
82
89
|
|
83
90
|
### Added
|
data/Gemfile
CHANGED
@@ -11,11 +11,11 @@ gem 'erb'
|
|
11
11
|
gem 'minitest', '~> 5.0'
|
12
12
|
gem 'rake', '~> 13.0'
|
13
13
|
gem 'reek'
|
14
|
-
|
14
|
+
gem 'rspec'
|
15
15
|
gem 'rubocop', '~> 1.21'
|
16
16
|
gem 'rubocop-minitest', require: false
|
17
17
|
gem 'rubocop-rake', require: false
|
18
|
-
|
18
|
+
gem 'rubocop-rspec', require: false
|
19
19
|
gem 'shellwords'
|
20
20
|
gem 'uri'
|
21
21
|
gem 'yaml'
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
markdown_exec (1.3.
|
4
|
+
markdown_exec (1.3.2)
|
5
5
|
clipboard (~> 1.3.6)
|
6
6
|
open3 (~> 0.1.1)
|
7
7
|
optparse (~> 0.1.1)
|
@@ -14,6 +14,7 @@ GEM
|
|
14
14
|
ast (2.4.2)
|
15
15
|
cgi (0.3.3)
|
16
16
|
clipboard (1.3.6)
|
17
|
+
diff-lcs (1.5.0)
|
17
18
|
erb (2.2.3)
|
18
19
|
cgi
|
19
20
|
json (2.6.2)
|
@@ -34,6 +35,19 @@ GEM
|
|
34
35
|
rainbow (>= 2.0, < 4.0)
|
35
36
|
regexp_parser (2.6.0)
|
36
37
|
rexml (3.2.5)
|
38
|
+
rspec (3.12.0)
|
39
|
+
rspec-core (~> 3.12.0)
|
40
|
+
rspec-expectations (~> 3.12.0)
|
41
|
+
rspec-mocks (~> 3.12.0)
|
42
|
+
rspec-core (3.12.0)
|
43
|
+
rspec-support (~> 3.12.0)
|
44
|
+
rspec-expectations (3.12.0)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.12.0)
|
47
|
+
rspec-mocks (3.12.0)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.12.0)
|
50
|
+
rspec-support (3.12.0)
|
37
51
|
rubocop (1.37.1)
|
38
52
|
json (~> 2.3)
|
39
53
|
parallel (~> 1.10)
|
@@ -50,6 +64,8 @@ GEM
|
|
50
64
|
rubocop (>= 0.90, < 2.0)
|
51
65
|
rubocop-rake (0.6.0)
|
52
66
|
rubocop (~> 1.0)
|
67
|
+
rubocop-rspec (2.14.2)
|
68
|
+
rubocop (~> 1.33)
|
53
69
|
ruby-progressbar (1.11.0)
|
54
70
|
shellwords (0.1.0)
|
55
71
|
tty-color (0.6.0)
|
@@ -77,9 +93,11 @@ DEPENDENCIES
|
|
77
93
|
minitest (~> 5.0)
|
78
94
|
rake (~> 13.0)
|
79
95
|
reek
|
96
|
+
rspec
|
80
97
|
rubocop (~> 1.21)
|
81
98
|
rubocop-minitest
|
82
99
|
rubocop-rake
|
100
|
+
rubocop-rspec
|
83
101
|
shellwords
|
84
102
|
uri
|
85
103
|
yaml
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -34,6 +34,7 @@ tap_config envvar: MarkdownExec::TAP_DEBUG
|
|
34
34
|
|
35
35
|
RuboCop::RakeTask.new do |task|
|
36
36
|
task.requires << 'rubocop-minitest'
|
37
|
+
task.requires << 'rubocop-rspec'
|
37
38
|
end
|
38
39
|
|
39
40
|
desc 'named task because minitest not included in rubocop tests'
|
@@ -41,8 +42,14 @@ task :rubocopminitest do
|
|
41
42
|
`rubocop --require rubocop-minitest`
|
42
43
|
end
|
43
44
|
|
45
|
+
# desc 'rspec'
|
46
|
+
# task :rspec do
|
47
|
+
# puts "in rspec"
|
48
|
+
# `pwd && rspec`
|
49
|
+
# end
|
50
|
+
|
44
51
|
task default: %i[test reek rubocop rubocopminitest]
|
45
|
-
# task default: %i[
|
52
|
+
# task default: %i[rspec test reek rubocop rubocopminitest]
|
46
53
|
|
47
54
|
# task :default => :build
|
48
55
|
|
@@ -630,7 +637,7 @@ def update_tab_completion(target)
|
|
630
637
|
|
631
638
|
svhs = YAML.load File.open(MENU_YML)
|
632
639
|
svhs.each do |svh|
|
633
|
-
svh[:compreply] = CLI
|
640
|
+
svh[:compreply] = CLI.value_for_cli(svh[:default]) if svh[:compreply].nil?
|
634
641
|
end.tap_inspect name: :svhs, type: :yaml
|
635
642
|
|
636
643
|
File.write target, ERB.new(File.read(filespec = File.join(BF, 'tab_completion.sh.erb'))).result(binding)
|
data/bin/tab_completion.sh
CHANGED
@@ -13,7 +13,7 @@ __filedirs_all()
|
|
13
13
|
}
|
14
14
|
|
15
15
|
_mde_echo_version() {
|
16
|
-
echo "1.3.
|
16
|
+
echo "1.3.2"
|
17
17
|
}
|
18
18
|
|
19
19
|
_mde() {
|
@@ -138,4 +138,4 @@ _mde() {
|
|
138
138
|
|
139
139
|
complete -o filenames -o nospace -F _mde mde
|
140
140
|
# _mde_echo_version
|
141
|
-
# echo "Updated: 2022-
|
141
|
+
# echo "Updated: 2022-11-13 18:09:17 UTC"
|
data/lib/env.rb
CHANGED
@@ -10,17 +10,21 @@ module Env
|
|
10
10
|
# :reek:NilCheck
|
11
11
|
# :reek:UtilityFunction
|
12
12
|
def env_bool(name, default: false)
|
13
|
-
return default if name.nil? || (val = ENV
|
13
|
+
return default if name.nil? || (val = ENV.fetch(name, nil)).nil?
|
14
14
|
return false if val.empty? || val == '0'
|
15
15
|
|
16
16
|
true
|
17
17
|
end
|
18
18
|
|
19
|
+
def env_bool_false(name)
|
20
|
+
!(val = (name && ENV.fetch(name, nil))).nil? && !(val.empty? || val == '0')
|
21
|
+
end
|
22
|
+
|
19
23
|
# skip :reek:DataClump
|
20
24
|
# skip :reek:NilCheck
|
21
25
|
# skip :reek:UtilityFunction
|
22
26
|
def env_int(name, default: 0)
|
23
|
-
return default if name.nil? || (val = ENV
|
27
|
+
return default if name.nil? || (val = ENV.fetch(name, nil)).nil?
|
24
28
|
return default if val.empty?
|
25
29
|
|
26
30
|
val.to_i
|
@@ -30,7 +34,7 @@ module Env
|
|
30
34
|
# skip :reek:NilCheck
|
31
35
|
# skip :reek:UtilityFunction
|
32
36
|
def env_str(name, default: '')
|
33
|
-
return default if name.nil? || (val = ENV
|
37
|
+
return default if name.nil? || (val = ENV.fetch(name, nil)).nil?
|
34
38
|
|
35
39
|
val || default
|
36
40
|
end
|
data/lib/env_opts.rb
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# encoding=utf-8
|
4
|
+
|
5
|
+
require_relative 'tap'
|
6
|
+
|
7
|
+
include Tap #; tap_config
|
8
|
+
|
9
|
+
# define options with initial values
|
10
|
+
# option to read value from environmnt variables
|
11
|
+
# option to cast input values
|
12
|
+
# value priority: default < environment < argument
|
13
|
+
#
|
14
|
+
class EnvOpts
|
15
|
+
attr_reader :opts, :values
|
16
|
+
|
17
|
+
def initialize(opts_raw = {}, argv = ARGV)
|
18
|
+
@opts = {}
|
19
|
+
@values = {}
|
20
|
+
add_options(opts_raw)
|
21
|
+
# parse(argv, &block) if block_given?
|
22
|
+
block_given? ? parse(argv, &block) : parse(argv)
|
23
|
+
|
24
|
+
self # rubocop:disable Lint/Void
|
25
|
+
end
|
26
|
+
|
27
|
+
# add options to menu
|
28
|
+
# calculate help text
|
29
|
+
#
|
30
|
+
def add_options(opts_raw)
|
31
|
+
return self if opts_raw.nil?
|
32
|
+
|
33
|
+
rows = opts_raw.map do |key, opt_raw|
|
34
|
+
key2 = key_name_to_option_name(key)
|
35
|
+
|
36
|
+
# set_per_options(key2, opt_raw)
|
37
|
+
@opts[key2] = (opt_raw ||= {})
|
38
|
+
set_key_value_as_cast key2, EnvOpts.optdefault(opt_raw)
|
39
|
+
|
40
|
+
set_key_value_per_environment_as_cast(key2, opt_raw)
|
41
|
+
|
42
|
+
[
|
43
|
+
[20, '-', "--#{key}"],
|
44
|
+
[16, '-', @opts[key2][:env].present? ? option_name_to_environment_name(key2, @opts[key2]) : ''],
|
45
|
+
# [24, '-', get_environment_value_from_option(key2, @opts[key2])],
|
46
|
+
[24, '-', @opts[key2][:default]],
|
47
|
+
[6, '-', if (fixed = opt_raw.fetch(:fixed, nil)).nil?
|
48
|
+
":#{option_cast(@opts[key2])}"
|
49
|
+
else
|
50
|
+
fixed.to_s
|
51
|
+
end]
|
52
|
+
]
|
53
|
+
end.tap_yaml 'rows'
|
54
|
+
|
55
|
+
max_widths = rows.reduce([0, 0, 0, 0]) do |memo, (c0, c1, c2, c3)|
|
56
|
+
[
|
57
|
+
[memo[0], c0[2].to_s.length].max,
|
58
|
+
[memo[1], c1[2].to_s.length].max,
|
59
|
+
[memo[2], c2[2].to_s.length].max,
|
60
|
+
[memo[3], c3[2].to_s.length].max
|
61
|
+
]
|
62
|
+
end.tap_inspect 'max_widths'
|
63
|
+
|
64
|
+
@values['help'] = rows.map do |(c0, c1, c2, c3)|
|
65
|
+
[format("%#{c0[1]}#{max_widths[0]}s", c0[2]),
|
66
|
+
format("%#{c1[1]}#{max_widths[1]}s", c1[2]),
|
67
|
+
format("%#{c2[1]}#{max_widths[2]}s", c2[2]),
|
68
|
+
format("%#{c3[1]}#{max_widths[3]}s", c3[2])]
|
69
|
+
end.map do |row|
|
70
|
+
row.join(' ')
|
71
|
+
end.join("\n")
|
72
|
+
@opts.tap_inspect '@opts'
|
73
|
+
@values.tap_inspect '@values'
|
74
|
+
|
75
|
+
self
|
76
|
+
end
|
77
|
+
|
78
|
+
# accept :d or :default option
|
79
|
+
#
|
80
|
+
def self.optdefault(opt_raw)
|
81
|
+
return opt_raw[:d] unless opt_raw[:d].nil?
|
82
|
+
|
83
|
+
opt_raw[:default]
|
84
|
+
end
|
85
|
+
|
86
|
+
def output_help
|
87
|
+
puts @values['help']
|
88
|
+
end
|
89
|
+
|
90
|
+
# process arguments as mostly pairs of option name and value
|
91
|
+
#
|
92
|
+
def parse(argv = ARGV)
|
93
|
+
return self if argv.nil? || !(argv&.count || 0).positive?
|
94
|
+
|
95
|
+
args_ind = 0
|
96
|
+
while args_ind < argv.count
|
97
|
+
args_consumed = 0
|
98
|
+
arg = argv.fetch(args_ind, '') #.tap_inspect 'argument', source: 'EnvOpts'
|
99
|
+
if arg.start_with? '--'
|
100
|
+
opt_name = arg[2..-1] #.tap_inspect 'opt_name', source: 'EnvOpts'
|
101
|
+
args_consumed = consume_arguments(opt_name, argv.fetch(args_ind + 1, nil))
|
102
|
+
end
|
103
|
+
|
104
|
+
if args_consumed.zero?
|
105
|
+
if arg == '--help'
|
106
|
+
output_help
|
107
|
+
exit
|
108
|
+
elsif block_given?
|
109
|
+
yield 'NAO', [arg]
|
110
|
+
args_consumed = 1
|
111
|
+
else
|
112
|
+
warn "Invalid argument: #{arg.inspect} in #{argv.inspect}"
|
113
|
+
exit 1
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
args_ind += args_consumed
|
118
|
+
end
|
119
|
+
@opts.tap_inspect '@opts'
|
120
|
+
@values.tap_inspect '@values'
|
121
|
+
|
122
|
+
self
|
123
|
+
end
|
124
|
+
|
125
|
+
# set option current values per environment values
|
126
|
+
#
|
127
|
+
def set_keys_value_per_environment_as_cast(opts_raw)
|
128
|
+
return self if opts_raw.nil?
|
129
|
+
|
130
|
+
opts_raw.each do |key, opt_raw|
|
131
|
+
set_key_value_per_environment_as_cast(key_name_to_option_name(key), opt_raw)
|
132
|
+
end
|
133
|
+
@opts.tap_inspect '@opts'
|
134
|
+
|
135
|
+
self
|
136
|
+
end
|
137
|
+
|
138
|
+
private
|
139
|
+
|
140
|
+
# convert key name or symbol to an option name
|
141
|
+
#
|
142
|
+
def key_name_to_option_name(key)
|
143
|
+
(key.is_a?(Symbol) ? symbol_name_to_option_name(key) : key) #.tap_inspect
|
144
|
+
end
|
145
|
+
|
146
|
+
# get cast of environment variable
|
147
|
+
#
|
148
|
+
def option_cast(opt_raw)
|
149
|
+
(opt_raw[:cast].present? ? opt_raw[:cast].to_s : 'to_s').tap_inspect
|
150
|
+
end
|
151
|
+
|
152
|
+
# update value for named option
|
153
|
+
# return number of arguments used
|
154
|
+
#
|
155
|
+
def consume_arguments(opt_name, value)
|
156
|
+
return 0 if (opt_raw = @opts.fetch(opt_name, nil)).nil?
|
157
|
+
|
158
|
+
return 0 unless opt_raw.fetch(:option, true)
|
159
|
+
|
160
|
+
if !(fixed = opt_raw.fetch(:fixed, nil)).nil?
|
161
|
+
set_key_value_as_cast(opt_name, fixed)
|
162
|
+
1
|
163
|
+
elsif value.nil?
|
164
|
+
0
|
165
|
+
else
|
166
|
+
set_key_value_as_cast(opt_name, value)
|
167
|
+
2
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# option names use hyphens
|
172
|
+
#
|
173
|
+
def method_name_to_option_name(name)
|
174
|
+
name.to_s.gsub('_', '-') #.tap_inspect
|
175
|
+
end
|
176
|
+
|
177
|
+
# read and write options using the option name as a method
|
178
|
+
#
|
179
|
+
def method_missing(method_name, *args)
|
180
|
+
method_name.tap_inspect 'method_name'
|
181
|
+
if method_name.to_s.end_with?('=')
|
182
|
+
value = args.first
|
183
|
+
name = method_name_to_option_name(method_name.to_s[0..-2])
|
184
|
+
set_key_value_as_cast(name, value)
|
185
|
+
else
|
186
|
+
@values[method_name_to_option_name(method_name)]
|
187
|
+
end.tap_inspect "ref #{method_name}", source: 'EnvOpts'
|
188
|
+
end
|
189
|
+
|
190
|
+
# option name to environment name
|
191
|
+
# if true or empty, compute from option name
|
192
|
+
#
|
193
|
+
def option_name_to_environment_name(opt_name, opt_raw)
|
194
|
+
case env_name = opt_raw.fetch(:env, '')
|
195
|
+
when true, ''
|
196
|
+
"#{@values['env-prefix']}#{opt_name.upcase.gsub('-', '_')}"
|
197
|
+
else
|
198
|
+
env_name
|
199
|
+
end.tap_inspect
|
200
|
+
end
|
201
|
+
|
202
|
+
# get environment value from option
|
203
|
+
#
|
204
|
+
def get_environment_value_from_option(opt_name, opt_raw)
|
205
|
+
ENV.fetch(option_name_to_environment_name(opt_name, opt_raw), nil).tap_inspect
|
206
|
+
end
|
207
|
+
|
208
|
+
# option names are available as methods
|
209
|
+
#
|
210
|
+
def respond_to_missing?(method_name, include_private = false)
|
211
|
+
(@opts.keys.include?(method_name_to_option_name(method_name)) || super)
|
212
|
+
end
|
213
|
+
|
214
|
+
def set_key_value_as_cast(key, value)
|
215
|
+
[key, value].tap_inspect 'key, value'
|
216
|
+
opt = @opts[key]
|
217
|
+
set_key_value_raw(key, (opt[:cast] ? value.send(opt[:cast]) : value))
|
218
|
+
end
|
219
|
+
|
220
|
+
# set key value_per environment as cast
|
221
|
+
#
|
222
|
+
def set_key_value_per_environment_as_cast(key, opt_raw)
|
223
|
+
key.tap_inspect 'key'
|
224
|
+
opt_raw.tap_inspect 'opt_raw'
|
225
|
+
return if opt_raw[:env].nil?
|
226
|
+
|
227
|
+
value = get_environment_value_from_option(key, opt_raw).tap_inspect 'value'
|
228
|
+
set_key_value_as_cast(key, opt_raw[:cast] ? value.send(opt_raw[:cast]) : value) unless value.nil?
|
229
|
+
end
|
230
|
+
|
231
|
+
# set key value (raw)
|
232
|
+
#
|
233
|
+
def set_key_value_raw(key, value)
|
234
|
+
[key, value].tap_inspect 'key, value'
|
235
|
+
@values[key] = value
|
236
|
+
end
|
237
|
+
|
238
|
+
# symbol name to option name
|
239
|
+
# option names use hyphens
|
240
|
+
#
|
241
|
+
def symbol_name_to_option_name(name)
|
242
|
+
name.to_s.gsub('_', '-') #.tap_inspect
|
243
|
+
end
|
244
|
+
end
|
@@ -7,6 +7,8 @@ require 'yaml'
|
|
7
7
|
|
8
8
|
require_relative 'object_present'
|
9
9
|
|
10
|
+
# add Hash.sym_keys
|
11
|
+
#
|
10
12
|
class Hash
|
11
13
|
unless defined?(sym_keys)
|
12
14
|
def sym_keys
|
@@ -18,6 +20,8 @@ class Hash
|
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
23
|
+
# parse application configuration from command-line options and environment variables
|
24
|
+
#
|
21
25
|
class EnvironmentOptParse
|
22
26
|
attr_reader :options, :remainder
|
23
27
|
|
data/lib/markdown_exec.rb
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
require 'English'
|
7
7
|
require 'clipboard'
|
8
8
|
require 'open3'
|
9
|
-
|
9
|
+
require 'optparse'
|
10
10
|
require 'shellwords'
|
11
11
|
require 'tty-prompt'
|
12
12
|
require 'yaml'
|
@@ -14,7 +14,7 @@ require 'yaml'
|
|
14
14
|
require_relative 'cli'
|
15
15
|
require_relative 'colorize'
|
16
16
|
require_relative 'env'
|
17
|
-
require_relative 'environment_opt_parse'
|
17
|
+
# require_relative 'environment_opt_parse'
|
18
18
|
require_relative 'object_present'
|
19
19
|
require_relative 'shared'
|
20
20
|
require_relative 'tap'
|
@@ -478,7 +478,7 @@ module MarkdownExec
|
|
478
478
|
yield line, nil, nil, exec_thr if block_given?
|
479
479
|
end
|
480
480
|
#d 'exec_thr now dead'
|
481
|
-
rescue
|
481
|
+
rescue StandardError
|
482
482
|
#d 'stdin error, thread killed, do nothing'
|
483
483
|
end
|
484
484
|
|
@@ -788,11 +788,9 @@ module MarkdownExec
|
|
788
788
|
blocks_in_file = list_blocks_in_file(opts.merge(struct: true))
|
789
789
|
mdoc = MDoc.new(blocks_in_file)
|
790
790
|
|
791
|
-
list_blocks_in_file(opts).
|
792
|
-
|
793
|
-
|
794
|
-
block
|
795
|
-
end.compact.tap_inspect
|
791
|
+
list_blocks_in_file(opts).reject do |block|
|
792
|
+
mdoc.hide_menu_block_per_options(opts, block)
|
793
|
+
end.tap_inspect
|
796
794
|
end
|
797
795
|
|
798
796
|
def list_recent_output(saved_stdout_folder, saved_stdout_glob, list_count)
|
@@ -1002,21 +1000,6 @@ module MarkdownExec
|
|
1002
1000
|
|
1003
1001
|
# :reek:NestedIterators
|
1004
1002
|
def run
|
1005
|
-
# eop = EnvironmentOptParse.new(
|
1006
|
-
# menu: File.join(File.expand_path(__dir__), 'menu.yml'),
|
1007
|
-
# options: {
|
1008
|
-
# menu_exit_at_top: true,
|
1009
|
-
# menu_with_exit: true
|
1010
|
-
# }
|
1011
|
-
# ).tap_yaml '** eop'
|
1012
|
-
# # eop = EnvironmentOptParse.new(menu: 'lib/menu.yml', options: ".#{MarkdownExec::APP_NAME.downcase}.yml", version: MarkdownExec::VERSION).tap_yaml '** eop'
|
1013
|
-
# eop.options.tap_inspect 'eop.options'
|
1014
|
-
# eop.remainder.tap_inspect 'eop.remainder'
|
1015
|
-
|
1016
|
-
# exec_block eop.options, eop.options[:block_name]
|
1017
|
-
|
1018
|
-
# return
|
1019
|
-
|
1020
1003
|
## default configuration
|
1021
1004
|
#
|
1022
1005
|
@options = base_options
|
@@ -1081,7 +1064,7 @@ module MarkdownExec
|
|
1081
1064
|
@options[:logged_stdout_filespec] = File.join @options[:saved_stdout_folder], @options[:logged_stdout_filename]
|
1082
1065
|
@logged_stdout_filespec = @options[:logged_stdout_filespec]
|
1083
1066
|
(dirname = File.dirname(@options[:logged_stdout_filespec])).tap_inspect name: :dirname
|
1084
|
-
Dir.
|
1067
|
+
Dir.mkdir_p dirname
|
1085
1068
|
|
1086
1069
|
ol = ["-STDOUT-\n"]
|
1087
1070
|
ol += @execute_files&.fetch(EF_STDOUT, [])
|
@@ -1218,7 +1201,7 @@ module MarkdownExec
|
|
1218
1201
|
File.join opts[:saved_script_folder], opts[:saved_script_filename]
|
1219
1202
|
|
1220
1203
|
dirname = File.dirname(@options[:saved_filespec])
|
1221
|
-
Dir.
|
1204
|
+
Dir.mkdir_p dirname
|
1222
1205
|
(shebang = if @options[:shebang]&.present?
|
1223
1206
|
"#{@options[:shebang]} #{@options[:shell]}\n"
|
1224
1207
|
else
|
data/lib/menu.yml
CHANGED
data/lib/object_present.rb
CHANGED
data/lib/tap.rb
CHANGED
@@ -6,8 +6,12 @@ require 'json'
|
|
6
6
|
require 'yaml'
|
7
7
|
|
8
8
|
require_relative 'env'
|
9
|
+
require_relative 'object_present'
|
10
|
+
|
9
11
|
include Env
|
10
12
|
|
13
|
+
# rubocop:disable Metrics/ParameterLists
|
14
|
+
|
11
15
|
## application-level debug control
|
12
16
|
#
|
13
17
|
module Tap
|
@@ -59,6 +63,7 @@ module Tap
|
|
59
63
|
end
|
60
64
|
# puts "$tap_enable: #{$tap_enable}"
|
61
65
|
# puts "$tap_mask: #{$tap_mask.to_s(2)}"
|
66
|
+
self
|
62
67
|
end
|
63
68
|
|
64
69
|
def tap_inspect(name_ = nil, caller0: nil, mask: TDD, name: DN, source: nil, type: nil)
|
@@ -67,31 +72,46 @@ module Tap
|
|
67
72
|
|
68
73
|
fn = CVT.fetch(type, CVT[:else])
|
69
74
|
outs = []
|
70
|
-
outs.push(
|
71
|
-
|
72
|
-
|
73
|
-
|
75
|
+
outs.push(source.to_s) if source.present?
|
76
|
+
|
77
|
+
vs = (caller0 || caller[0]).scan(/in `?(\S+)'$/).fetch(0, []).fetch(0, '')
|
78
|
+
outs.push("#{vs}()") if vs.present?
|
79
|
+
|
80
|
+
outs.push(tap_named_value(name_ || name, method(fn).call))
|
74
81
|
|
82
|
+
$stdout.puts(outs.join(' ')) if outs.length.positive?
|
75
83
|
self
|
76
84
|
end
|
77
85
|
|
78
86
|
def tap_print(mask: TDD)
|
87
|
+
return self unless $tap_enable
|
79
88
|
return self unless (mask & $tap_mask).positive?
|
80
89
|
|
81
|
-
print self
|
90
|
+
$stdout.print self
|
91
|
+
self
|
82
92
|
end
|
83
93
|
|
84
|
-
def tap_puts(name_ = nil,
|
85
|
-
|
94
|
+
def tap_puts(name_ = nil, mask: TDD, name: nil)
|
95
|
+
return self unless $tap_enable
|
96
|
+
return self unless (mask & $tap_mask).positive?
|
86
97
|
|
87
|
-
|
88
|
-
|
89
|
-
else
|
90
|
-
puts self
|
91
|
-
end
|
98
|
+
$stdout.puts tap_named_value(name_ || name, self)
|
99
|
+
self
|
92
100
|
end
|
93
101
|
|
94
102
|
def tap_yaml(name_ = nil, caller0: nil, mask: TDD, name: DN, source: nil)
|
95
103
|
tap_inspect name_, caller0: (caller0 || caller[0]), mask: mask, name: name, source: source, type: :yaml
|
96
104
|
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def tap_named_value(name, value)
|
109
|
+
if name.present?
|
110
|
+
"#{name}: #{value}"
|
111
|
+
else
|
112
|
+
value.to_s
|
113
|
+
end
|
114
|
+
end
|
97
115
|
end
|
116
|
+
|
117
|
+
# rubocop:enable Metrics/ParameterLists
|
@@ -0,0 +1,60 @@
|
|
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
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fareed Stevenson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clipboard
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/cli.rb
|
114
114
|
- lib/colorize.rb
|
115
115
|
- lib/env.rb
|
116
|
+
- lib/env_opts.rb
|
116
117
|
- lib/environment_opt_parse.rb
|
117
118
|
- lib/globfiles.rb
|
118
119
|
- lib/markdown_exec.rb
|
@@ -121,6 +122,7 @@ files:
|
|
121
122
|
- lib/object_present.rb
|
122
123
|
- lib/shared.rb
|
123
124
|
- lib/tap.rb
|
125
|
+
- lib/yaml_env_opts.rb
|
124
126
|
homepage: https://rubygems.org/gems/markdown_exec
|
125
127
|
licenses:
|
126
128
|
- MIT
|