markdown_exec 1.2.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/menu.yml ADDED
@@ -0,0 +1,364 @@
1
+ # MDE - Markdown Executor (1.3.1)
2
+ ---
3
+ - :arg_name: NAME
4
+ :compreply: false
5
+ :description: Name of block
6
+ :env_var: MDE_BLOCK_NAME
7
+ :long_name: block-name
8
+ :opt_name: block_name
9
+ :short_name: b
10
+ :procname: val_as_str
11
+ - :arg_name: PATH
12
+ :default: "."
13
+ :description: Read configuration file
14
+ :long_name: config
15
+ :procname: path
16
+ - :arg_name: BOOL
17
+ :default: false
18
+ :description: Debug output
19
+ :env_var: MDE_DEBUG
20
+ :long_name: debug
21
+ :short_name: d
22
+ :procname: debug
23
+ - :arg_name: RELATIVE_PATH
24
+ :compreply: "."
25
+ :description: Name of document
26
+ :env_var: MDE_FILENAME
27
+ :long_name: filename
28
+ :opt_name: filename
29
+ :short_name: f
30
+ :procname: val_as_str
31
+ - :description: App help
32
+ :long_name: help
33
+ :short_name: h
34
+ :procname: help
35
+ - :arg_name: RELATIVE_PATH
36
+ :default: "."
37
+ :description: Path to documents
38
+ :env_var: MDE_PATH
39
+ :long_name: path
40
+ :opt_name: path
41
+ :short_name: p
42
+ :procname: val_as_str
43
+ - :arg_name: BOOL
44
+ :default: true
45
+ :description: Pause for user to approve script
46
+ :env_var: MDE_USER_MUST_APPROVE
47
+ :long_name: user-must-approve
48
+ :opt_name: user_must_approve
49
+ :short_name: q
50
+ :procname: val_as_bool
51
+ - :description: Print the gem's version
52
+ :long_name: version
53
+ :short_name: v
54
+ :procname: version
55
+ - :description: Exit app
56
+ :long_name: exit
57
+ :short_name: x
58
+ :procname: exit
59
+ - :description: Show current configuration values
60
+ :short_name: '0'
61
+ :procname: show_config
62
+ - :description: List blocks
63
+ :long_name: list-blocks
64
+ :opt_name: list_blocks
65
+ :procname: val_as_bool
66
+ - :description: List default configuration as environment variables
67
+ :long_name: list-default-env
68
+ :opt_name: list_default_env
69
+ - :description: List default configuration as YAML
70
+ :long_name: list-default-yaml
71
+ :opt_name: list_default_yaml
72
+ - :description: List docs in current folder
73
+ :long_name: list-docs
74
+ :opt_name: list_docs
75
+ :procname: val_as_bool
76
+ - :description: List recent saved output
77
+ :long_name: list-recent-output
78
+ :opt_name: list_recent_output
79
+ :procname: val_as_bool
80
+ - :description: List recent saved scripts
81
+ :long_name: list-recent-scripts
82
+ :opt_name: list_recent_scripts
83
+ :procname: val_as_bool
84
+ - :description: Select and execute a recently saved output
85
+ :long_name: select-recent-output
86
+ :opt_name: select_recent_output
87
+ :procname: val_as_bool
88
+ - :description: Select and execute a recently saved script
89
+ :long_name: select-recent-script
90
+ :opt_name: select_recent_script
91
+ :procname: val_as_bool
92
+ - :description: List tab completions
93
+ :long_name: tab-completions
94
+ :opt_name: tab_completions
95
+ :procname: val_as_bool
96
+ - :description: Run most recently saved script
97
+ :long_name: run-last-script
98
+ :opt_name: run_last_script
99
+ :procname: val_as_bool
100
+ - :description: Gem home folder
101
+ :long_name: pwd
102
+ :opt_name: pwd
103
+ :procname: val_as_bool
104
+ - :arg_name: INT.0-3
105
+ :default: 1
106
+ :description: Output display level (0 to 3 [data, +context, +info])
107
+ :env_var: MDE_DISPLAY_LEVEL
108
+ :long_name: display-level
109
+ :opt_name: display_level
110
+ :procname: val_as_int
111
+ - :arg_name: INT.1-
112
+ :default: 32
113
+ :description: Max. items to return in list
114
+ :env_var: MDE_LIST_COUNT
115
+ :long_name: list-count
116
+ :opt_name: list_count
117
+ :procname: val_as_int
118
+ - :arg_name: PREFIX
119
+ :default: mde
120
+ :description: Name prefix for stdout files
121
+ :env_var: MDE_LOGGED_STDOUT_FILENAME_PREFIX
122
+ :opt_name: logged_stdout_filename_prefix
123
+ :procname: val_as_str
124
+ - :arg_name: BOOL
125
+ :default: false
126
+ :description: Display document name in block selection menu
127
+ :env_var: MDE_MENU_BLOCKS_WITH_DOCNAME
128
+ :opt_name: menu_blocks_with_docname
129
+ :procname: val_as_bool
130
+ - :arg_name: BOOL
131
+ :default: false
132
+ :description: Display headings (levels 1,2,3) in block selection menu
133
+ :env_var: MDE_MENU_BLOCKS_WITH_HEADINGS
134
+ :opt_name: menu_blocks_with_headings
135
+ :procname: val_as_bool
136
+ - :arg_name: BOOL
137
+ :default: false
138
+ :description: Display summary for execution
139
+ :env_var: MDE_OUTPUT_EXECUTION_SUMMARY
140
+ :long_name: output-execution-summary
141
+ :opt_name: output_execution_summary
142
+ :procname: val_as_bool
143
+ - :arg_name: BOOL
144
+ :default: false
145
+ :description: Display script prior to execution
146
+ :env_var: MDE_OUTPUT_SCRIPT
147
+ :long_name: output-script
148
+ :opt_name: output_script
149
+ :procname: val_as_bool
150
+ - :arg_name: BOOL
151
+ :default: true
152
+ :description: Display standard output from execution
153
+ :env_var: MDE_OUTPUT_STDOUT
154
+ :long_name: output-stdout
155
+ :opt_name: output_stdout
156
+ :procname: val_as_bool
157
+ - :arg_name: BOOL
158
+ :default: false
159
+ :description: Save executed script
160
+ :env_var: MDE_SAVE_EXECUTED_SCRIPT
161
+ :long_name: save-executed-script
162
+ :opt_name: save_executed_script
163
+ :procname: val_as_bool
164
+ - :arg_name: BOOL
165
+ :default: false
166
+ :description: Save standard output of the executed script
167
+ :env_var: MDE_SAVE_EXECUTION_OUTPUT
168
+ :long_name: save-execution-output
169
+ :opt_name: save_execution_output
170
+ :procname: val_as_bool
171
+ - :arg_name: INT
172
+ :default: 493
173
+ :description: chmod for saved scripts
174
+ :env_var: MDE_SAVED_SCRIPT_CHMOD
175
+ :opt_name: saved_script_chmod
176
+ :procname: val_as_int
177
+ - :arg_name: PREFIX
178
+ :default: mde
179
+ :description: Name prefix for saved scripts
180
+ :env_var: MDE_SAVED_SCRIPT_FILENAME_PREFIX
181
+ :opt_name: saved_script_filename_prefix
182
+ :procname: val_as_str
183
+ - :arg_name: RELATIVE_PATH
184
+ :default: logs
185
+ :description: Saved script folder
186
+ :env_var: MDE_SAVED_SCRIPT_FOLDER
187
+ :long_name: saved-script-folder
188
+ :opt_name: saved_script_folder
189
+ :procname: val_as_str
190
+ - :arg_name: GLOB
191
+ :default: mde_*.sh
192
+ :description: Glob matching saved scripts
193
+ :env_var: MDE_SAVED_SCRIPT_GLOB
194
+ :opt_name: saved_script_glob
195
+ :procname: val_as_str
196
+ - :arg_name: RELATIVE_PATH
197
+ :default: logs
198
+ :description: Saved stdout folder
199
+ :env_var: MDE_SAVED_STDOUT_FOLDER
200
+ :long_name: saved-stdout-folder
201
+ :opt_name: saved_stdout_folder
202
+ :procname: val_as_str
203
+ - :arg_name: GLOB
204
+ :default: mde_*.out.txt
205
+ :description: Glob matching saved outputs
206
+ :env_var: MDE_SAVED_STDOUT_GLOB
207
+ :opt_name: saved_stdout_glob
208
+ :procname: val_as_str
209
+ - :default: "^[\\(\\[].*[\\)\\]]$"
210
+ :description: Pattern for blocks to hide from user-selection
211
+ :env_var: MDE_BLOCK_NAME_HIDDEN_MATCH
212
+ :opt_name: block_name_hidden_match
213
+ :procname: val_as_str
214
+ - :default: ":(?<title>\\S+)( |$)"
215
+ :env_var: MDE_BLOCK_NAME_MATCH
216
+ :opt_name: block_name_match
217
+ :procname: val_as_str
218
+ - :default: "%\\([^\\)]+\\)"
219
+ :env_var: MDE_BLOCK_CALLS_SCAN
220
+ :opt_name: block_calls_scan
221
+ :procname: val_as_str
222
+ - :default: "\\+\\S+"
223
+ :env_var: MDE_BLOCK_REQUIRED_SCAN
224
+ :opt_name: block_required_scan
225
+ :procname: val_as_str
226
+ - :default: "<(?<full>(?<type>\\$)?(?<name>[A-Za-z]\\S*))"
227
+ :env_var: MDE_BLOCK_STDIN_SCAN
228
+ :opt_name: block_stdin_scan
229
+ :procname: val_as_str
230
+ - :default: ">(?<full>(?<type>\\$)?(?<name>[A-Za-z]\\S*))"
231
+ :env_var: MDE_BLOCK_STDOUT_SCAN
232
+ :opt_name: block_stdout_scan
233
+ :procname: val_as_str
234
+ - :default: "> "
235
+ :env_var: MDE_DISPLAY_LEVEL_XBASE_PREFIX
236
+ :opt_name: display_level_xbase_prefix
237
+ :procname: val_as_str
238
+ - :default: "^`{3,}"
239
+ :env_var: MDE_FENCED_START_AND_END_MATCH
240
+ :opt_name: fenced_start_and_end_match
241
+ :procname: val_as_str
242
+ - :default: "^`{3,}(?<shell>[^`\\s]*) *(?<name>.*)$"
243
+ :env_var: MDE_FENCED_START_EX_MATCH
244
+ :opt_name: fenced_start_ex_match
245
+ :procname: val_as_str
246
+ - :default: "^# *(?<name>[^#]*?) *$"
247
+ :env_var: MDE_HEADING1_MATCH
248
+ :opt_name: heading1_match
249
+ :procname: val_as_str
250
+ - :default: "^## *(?<name>[^#]*?) *$"
251
+ :env_var: MDE_HEADING2_MATCH
252
+ :opt_name: heading2_match
253
+ :procname: val_as_str
254
+ - :default: "^### *(?<name>.+?) *$"
255
+ :env_var: MDE_HEADING3_MATCH
256
+ :opt_name: heading3_match
257
+ :procname: val_as_str
258
+ - :default: "*.[Mm][Dd]"
259
+ :env_var: MDE_MD_FILENAME_GLOB
260
+ :opt_name: md_filename_glob
261
+ :procname: val_as_str
262
+ - :default: ".+\\.md"
263
+ :env_var: MDE_MD_FILENAME_MATCH
264
+ :opt_name: md_filename_match
265
+ :procname: val_as_str
266
+ - :default: "-:= %s =:-"
267
+ :description: format for menu dividers and demarcations
268
+ :env_var: MDE_MENU_DIVIDER_FORMAT
269
+ :opt_name: menu_divider_format
270
+ :procname: val_as_str
271
+ - :default: magenta
272
+ :description: Color of menu divider
273
+ :env_var: MDE_MENU_DIVIDER_COLOR
274
+ :opt_name: menu_divider_color
275
+ :procname: val_as_str
276
+ - :default: "^::: +(?<name>.+?)$"
277
+ :description: Pattern for topics/dividers in block selection menu
278
+ :env_var: MDE_MENU_DIVIDER_MATCH
279
+ :opt_name: menu_divider_match
280
+ :procname: val_as_str
281
+ - :default: ">"
282
+ :description: Symbol before each divider
283
+ :env_var: MDE_MENU_DIVIDER_SYMBOL
284
+ :opt_name: menu_divider_symbol
285
+ :procname: val_as_str
286
+ - :default: "~~~"
287
+ :description: closing demarcations for menu
288
+ :env_var: MDE_MENU_FINAL_DIVIDER
289
+ :opt_name: menu_final_divider
290
+ :procname: val_as_str
291
+ - :default: ''
292
+ :description: opening demarcation for menu
293
+ :env_var: MDE_MENU_INITIAL_DIVIDER
294
+ :opt_name: menu_initial_divider
295
+ :procname: val_as_str
296
+ - :description: Options for viewing saved output file
297
+ :env_var: MDE_OUTPUT_VIEWER_OPTIONS
298
+ :opt_name: output_viewer_options
299
+ :procname: val_as_str
300
+ - :default: 36
301
+ :description: 'Maximum # of rows in select list'
302
+ :env_var: MDE_SELECT_PAGE_HEIGHT
303
+ :opt_name: select_page_height
304
+ :procname: val_as_int
305
+ - :default: "#!/usr/bin/env"
306
+ :description: Shebang for saved scripts
307
+ :env_var: MDE_SHEBANG
308
+ :opt_name: shebang
309
+ :procname: val_as_str
310
+ - :default: bash
311
+ :description: Shell for launched scripts
312
+ :env_var: MDE_SHELL
313
+ :opt_name: shell
314
+ :procname: val_as_str
315
+ - :default: Process?
316
+ :description: Prompt to approve a block
317
+ :env_var: MDE_PROMPT_APPROVE_BLOCK
318
+ :opt_name: prompt_approve_block
319
+ :procname: val_as_str
320
+ - :default: 'Choose a block:'
321
+ :description: Prompt to select a block
322
+ :env_var: MDE_PROMPT_SELECT_BLOCK
323
+ :opt_name: prompt_select_block
324
+ :procname: val_as_str
325
+ - :default: 'Choose a file:'
326
+ :description: Prompt to select a markdown document
327
+ :env_var: MDE_PROMPT_SELECT_MD
328
+ :opt_name: prompt_select_md
329
+ :procname: val_as_str
330
+ - :default: 'Choose a file:'
331
+ :description: Prompt to select a saved file
332
+ :env_var: MDE_PROMPT_SELECT_OUTPUT
333
+ :opt_name: prompt_select_output
334
+ :procname: val_as_str
335
+ - :default: Copy script to clipboard
336
+ :description: Prompt to copy script to clipboard
337
+ :env_var: MDE_PROMPT_SCRIPT_TO_CLIPBOARD
338
+ :opt_name: prompt_script_to_clipboard
339
+ :procname: val_as_str
340
+ - :default: Save script
341
+ :description: Prompt to save script
342
+ :env_var: MDE_PROMPT_SAVE_SCRIPT
343
+ :opt_name: prompt_save_script
344
+ :procname: val_as_str
345
+ - :default: 'No'
346
+ :description: Prompt for no
347
+ :env_var: MDE_PROMPT_NO
348
+ :opt_name: prompt_no
349
+ :procname: val_as_str
350
+ - :default: 'Yes'
351
+ :description: Prompt for yes
352
+ :env_var: MDE_PROMPT_YES
353
+ :opt_name: prompt_yes
354
+ :procname: val_as_str
355
+ - :default: " #=#=#"
356
+ :description: Output divider
357
+ :env_var: MDE_OUTPUT_DIVIDER
358
+ :opt_name: output_divider
359
+ :procname: val_as_str
360
+ - :default: yellow
361
+ :description: Color of output divider
362
+ :env_var: MDE_OUTPUT_DIVIDER_COLOR
363
+ :opt_name: output_divider_color
364
+ :procname: val_as_str
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # encoding=utf-8
4
+
5
+ # is the value empty?
6
+ #
7
+ class String
8
+ unless defined?(blank?)
9
+ def blank?
10
+ empty? || /\A[[:space:]]*\z/.freeze.match?(self)
11
+ end
12
+ end
13
+ end
14
+
15
+ # is the value non-empty?
16
+ #
17
+ class String
18
+ unless defined?(present?)
19
+ def present?
20
+ !empty?
21
+ end
22
+ end
23
+ end
24
+
25
+
26
+ # is the value a non-empty string or a binary?
27
+ #
28
+ # :reek:ManualDispatch ### temp
29
+ class Object
30
+ unless defined?(present?)
31
+ def present?
32
+ case self.class.to_s
33
+ when 'FalseClass', 'TrueClass'
34
+ true
35
+ else
36
+ self && (!respond_to?(:blank?) || !blank?)
37
+ end
38
+ end
39
+ end
40
+ end
data/lib/shared.rb CHANGED
@@ -6,14 +6,24 @@ require 'shellwords'
6
6
 
7
7
  public
8
8
 
9
- # skip :reek:UtilityFunction
10
- def value_for_cli(value)
11
- case value.class.to_s
12
- when 'String'
13
- Shellwords.escape value
14
- when 'FalseClass', 'TrueClass'
15
- value ? '1' : '0'
16
- else
17
- Shellwords.escape value.to_s
18
- end
9
+ BF = 'bin'
10
+
11
+ # display_level values
12
+ DISPLAY_LEVEL_BASE = 0 # required output
13
+ DISPLAY_LEVEL_ADMIN = 1 # monit
14
+ DISPLAY_LEVEL_DEBUG = 2
15
+ DISPLAY_LEVEL_DUMP = 3
16
+ DISPLAY_LEVEL_DEFAULT = DISPLAY_LEVEL_ADMIN
17
+ DISPLAY_LEVEL_MAX = DISPLAY_LEVEL_DUMP
18
+
19
+ # @execute_files[ind] = @execute_files[ind] + [block]
20
+ EF_STDOUT = 0
21
+ EF_STDERR = 1
22
+ EF_STDIN = 2
23
+
24
+ LOCAL_YML = 'menu.yml'
25
+ MENU_YML = "lib/#{LOCAL_YML}"
26
+
27
+ def menu_from_yaml
28
+ YAML.load File.open(File.join(File.expand_path(__dir__), LOCAL_YML))
19
29
  end
data/lib/tap.rb CHANGED
@@ -6,31 +6,92 @@ require 'json'
6
6
  require 'yaml'
7
7
 
8
8
  require_relative 'env'
9
- include Env # rubocop:disable Style/MixinUsage
9
+ include Env
10
10
 
11
- # add function for in-line tap
11
+ ## application-level debug control
12
12
  #
13
13
  module Tap
14
- $pdebug = env_bool 'MDE_DEBUG'
14
+ DN = 'return'
15
+ NONE = 0x0
16
+ T1 = 1 # RESULT
17
+ T2 = 2 # CONTEXT
18
+ T3 = 4 # MONITOR
19
+ T4 = 8 # DUMP
20
+ ALL2 = 0x77
21
+ ALL = 0xFF
22
+ TDD = 0x11
23
+ TB1 = 0x22
24
+ TB2 = 0x44
25
+ TB3 = 0x88
26
+ TD = 0x0F
27
+ TD0 = 0x01
28
+ TD1 = 0x02
29
+ TD2 = 0x04
30
+ TP = 0xF0
31
+ TP0 = 0x10
32
+ TP1 = 0x20
33
+ TP2 = 0x40
15
34
 
16
- def tap_config(enable)
17
- $pdebug = enable
18
- end
35
+ # cast with message per tap_inspect type
36
+ # type: message
37
+ #
38
+ CVT = {
39
+ json: :to_json,
40
+ string: :to_s,
41
+ yaml: :to_yaml,
42
+ else: :inspect
43
+ }.freeze
44
+
45
+ $tap_enable = false
46
+ $tap_mask = ALL2
19
47
 
20
- def tap_inspect(format: nil, name: 'return')
21
- return self unless $pdebug
48
+ def tap_config(enable: true, envvar: nil, value: nil)
49
+ $tap_enable = false
50
+ if envvar
51
+ $tap_enable = (env_int envvar).positive?
52
+ $tap_mask = ALL2 if $tap_enable
53
+ elsif value
54
+ $tap_mask = value.to_i
55
+ $tap_enable = $tap_mask.positive?
56
+ elsif enable
57
+ $tap_mask = ALL2
58
+ $tap_enable = true
59
+ end
60
+ # puts "$tap_enable: #{$tap_enable}"
61
+ # puts "$tap_mask: #{$tap_mask.to_s(2)}"
62
+ end
22
63
 
23
- cvt = {
24
- json: :to_json,
25
- string: :to_s,
26
- yaml: :to_yaml,
27
- else: :inspect
28
- }
29
- fn = cvt.fetch(format, cvt[:else])
64
+ def tap_inspect(name_ = nil, caller0: nil, mask: TDD, name: DN, source: nil, type: nil)
65
+ return self unless $tap_enable
66
+ return self unless (mask & $tap_mask).positive?
30
67
 
31
- puts "-> #{caller[0].scan(/in `?(\S+)'$/)[0][0]}()" \
32
- " #{name}: #{method(fn).call}"
68
+ fn = CVT.fetch(type, CVT[:else])
69
+ outs = []
70
+ outs.push("#{source}") if source
71
+ outs.push("#{(caller0 || caller[0]).scan(/in `?(\S+)'$/)[0][0]}()") # if (mask & $tap_mask & TP).positive?
72
+ outs.push("#{name_ || name}: #{method(fn).call}") # if (mask & $tap_mask & TD).positive?
73
+ puts outs.join(' ') if outs.length.positive?
33
74
 
34
75
  self
35
76
  end
77
+
78
+ def tap_print(mask: TDD)
79
+ return self unless (mask & $tap_mask).positive?
80
+
81
+ print self
82
+ end
83
+
84
+ def tap_puts(name_ = nil, caller0: nil, mask: TDD, name: nil, type: nil)
85
+ # return self unless (mask & $tap_mask).positive?
86
+
87
+ if (name1 = name_ || name).present?
88
+ puts "#{name1}: #{self}"
89
+ else
90
+ puts self
91
+ end
92
+ end
93
+
94
+ def tap_yaml(name_ = nil, caller0: nil, mask: TDD, name: DN, source: nil)
95
+ tap_inspect name_, caller0: (caller0 || caller[0]), mask: mask, name: name, source: source, type: :yaml
96
+ end
36
97
  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.2.0
4
+ version: 1.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: 2022-06-12 00:00:00.000000000 Z
11
+ date: 2022-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -110,10 +110,15 @@ files:
110
110
  - bin/setup
111
111
  - bin/tab_completion.sh
112
112
  - bin/tab_completion.sh.erb
113
+ - lib/cli.rb
113
114
  - lib/colorize.rb
114
115
  - lib/env.rb
116
+ - lib/environment_opt_parse.rb
117
+ - lib/globfiles.rb
115
118
  - lib/markdown_exec.rb
116
119
  - lib/markdown_exec/version.rb
120
+ - lib/menu.yml
121
+ - lib/object_present.rb
117
122
  - lib/shared.rb
118
123
  - lib/tap.rb
119
124
  homepage: https://rubygems.org/gems/markdown_exec