markdown_exec 1.1.0 → 1.3.0

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,293 @@
1
+ # MDE - Markdown Executor (1.3.0)
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
+ :proc1: val_as_str
11
+ - :arg_name: PATH
12
+ :default: "."
13
+ :description: Read configuration file
14
+ :long_name: config
15
+ :proc1: 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
+ :proc1: 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
+ :proc1: val_as_str
31
+ - :description: App help
32
+ :long_name: help
33
+ :short_name: h
34
+ :proc1: 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
+ :proc1: 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
+ :proc1: val_as_bool
51
+ - :description: Print the gem's version
52
+ :long_name: version
53
+ :short_name: v
54
+ :proc1: version
55
+ - :description: Exit app
56
+ :long_name: exit
57
+ :short_name: x
58
+ :proc1: exit
59
+ - :description: Show current configuration values
60
+ :short_name: '0'
61
+ :proc1: show_config
62
+ - :description: List blocks
63
+ :long_name: list-blocks
64
+ :opt_name: list_blocks
65
+ :proc1: 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
+ :proc1: val_as_bool
76
+ - :description: List recent saved output
77
+ :long_name: list-recent-output
78
+ :opt_name: list_recent_output
79
+ :proc1: val_as_bool
80
+ - :description: List recent saved scripts
81
+ :long_name: list-recent-scripts
82
+ :opt_name: list_recent_scripts
83
+ :proc1: 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
+ :proc1: 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
+ :proc1: val_as_bool
92
+ - :description: List tab completions
93
+ :long_name: tab-completions
94
+ :opt_name: tab_completions
95
+ :proc1: val_as_bool
96
+ - :description: Run most recently saved script
97
+ :long_name: run-last-script
98
+ :opt_name: run_last_script
99
+ :proc1: val_as_bool
100
+ - :description: Gem home folder
101
+ :long_name: pwd
102
+ :opt_name: pwd
103
+ :proc1: val_as_bool
104
+ - :arg_name: INT.0-2
105
+ :default: 1
106
+ :description: Output display level (0 to 2 [data, +context, +info])
107
+ :env_var: MDE_DISPLAY_LEVEL
108
+ :long_name: display-level
109
+ :opt_name: display_level
110
+ :proc1: 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
+ :proc1: 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
+ :proc1: 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
+ :proc1: 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
+ :proc1: 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
+ :proc1: 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
+ :proc1: 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
+ :proc1: 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
+ :proc1: 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
+ :proc1: 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
+ :proc1: 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
+ :proc1: 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
+ :proc1: 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
+ :proc1: 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
+ :proc1: 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
+ :proc1: val_as_str
209
+ - :default: "^[\\(\\[].*[\\)\\]]$"
210
+ :description: Pattern for blocks to hide from user-selection
211
+ :env_var: MDE_BLOCK_NAME_EXCLUDED_MATCH
212
+ :opt_name: block_name_excluded_match
213
+ :proc1: val_as_str
214
+ - :default: ":(?<title>\\S+)( |$)"
215
+ :env_var: MDE_BLOCK_NAME_MATCH
216
+ :opt_name: block_name_match
217
+ :proc1: val_as_str
218
+ - :default: "%\\([^\\)]+\\)"
219
+ :env_var: MDE_BLOCK_CALLS_SCAN
220
+ :opt_name: block_calls_scan
221
+ :proc1: val_as_str
222
+ - :default: "\\+\\S+"
223
+ :env_var: MDE_BLOCK_REQUIRED_SCAN
224
+ :opt_name: block_required_scan
225
+ :proc1: 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
+ :proc1: 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
+ :proc1: val_as_str
234
+ - :default: "> "
235
+ :env_var: MDE_DISPLAY_LEVEL_XBASE_PREFIX
236
+ :opt_name: display_level_xbase_prefix
237
+ :proc1: val_as_str
238
+ - :default: "^`{3,}"
239
+ :env_var: MDE_FENCED_START_AND_END_MATCH
240
+ :opt_name: fenced_start_and_end_match
241
+ :proc1: 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
+ :proc1: val_as_str
246
+ - :default: "^# *(?<name>[^#]*?) *$"
247
+ :env_var: MDE_HEADING1_MATCH
248
+ :opt_name: heading1_match
249
+ :proc1: val_as_str
250
+ - :default: "^## *(?<name>[^#]*?) *$"
251
+ :env_var: MDE_HEADING2_MATCH
252
+ :opt_name: heading2_match
253
+ :proc1: val_as_str
254
+ - :default: "^### *(?<name>.+?) *$"
255
+ :env_var: MDE_HEADING3_MATCH
256
+ :opt_name: heading3_match
257
+ :proc1: val_as_str
258
+ - :default: "*.[Mm][Dd]"
259
+ :env_var: MDE_MD_FILENAME_GLOB
260
+ :opt_name: md_filename_glob
261
+ :proc1: val_as_str
262
+ - :default: ".+\\.md"
263
+ :env_var: MDE_MD_FILENAME_MATCH
264
+ :opt_name: md_filename_match
265
+ :proc1: val_as_str
266
+ - :default: "^::: +(?<name>.+?)$"
267
+ :description: Pattern for topics/dividers in block selection menu
268
+ :env_var: MDE_MENU_DIVIDER_MATCH
269
+ :opt_name: menu_divider_match
270
+ :proc1: val_as_str
271
+ - :description: Options for viewing saved output file
272
+ :env_var: MDE_OUTPUT_VIEWER_OPTIONS
273
+ :opt_name: output_viewer_options
274
+ :proc1: val_as_str
275
+ - :default: 24
276
+ :description: 'Maximum # of rows in select list'
277
+ :env_var: MDE_SELECT_PAGE_HEIGHT
278
+ :opt_name: select_page_height
279
+ :proc1: val_as_int
280
+ - :default: "#!/usr/bin/env"
281
+ :description: Shebang for saved scripts
282
+ :env_var: MDE_SHEBANG
283
+ :opt_name: shebang
284
+ :proc1: val_as_str
285
+ - :default: bash
286
+ :description: Shell for launched scripts
287
+ :env_var: MDE_SHELL
288
+ :opt_name: shell
289
+ :proc1: val_as_str
290
+ - :default: "- - %s - -"
291
+ :env_var: MDE_MENU_DIVIDER_FORMAT
292
+ :opt_name: menu_divider_format
293
+ :proc1: val_as_str
data/lib/shared.rb CHANGED
@@ -3,110 +3,31 @@
3
3
  # encoding=utf-8
4
4
 
5
5
  require 'shellwords'
6
- require 'yaml'
7
-
8
- # │0 │ to restore default │
9
- # │ │ color │
10
- # ├───┼───────────────────────┤
11
- # │ │ │
12
- # │1 │ for brighter colors │
13
- # ├───┼───────────────────────┤
14
- # │ │ │
15
- # │4 │ for underlined text │
16
- # ├───┼───────────────────────┤
17
- # │ │ │
18
- # │5 │ for flashing text
19
- class String
20
- def black
21
- "\033[30m#{self}\033[0m"
22
- end
23
-
24
- def red
25
- "\033[31m#{self}\033[0m"
26
- end
27
-
28
- def bred
29
- "\033[1;31m#{self}\033[0m"
30
- end
31
-
32
- def green
33
- "\033[32m#{self}\033[0m"
34
- end
35
-
36
- def bgreen
37
- "\033[1;32m#{self}\033[0m"
38
- end
39
-
40
- def yellow
41
- "\033[33m#{self}\033[0m"
42
- end
43
-
44
- def byellow
45
- "\033[1;33m#{self}\033[0m"
46
- end
47
-
48
- def blue
49
- "\033[34m#{self}\033[0m"
50
- end
51
-
52
- def magenta
53
- "\033[35m#{self}\033[0m"
54
- end
55
-
56
- def cyan
57
- "\033[36m#{self}\033[0m"
58
- end
59
-
60
- def white
61
- "\033[37m#{self}\033[0m"
62
- end
63
-
64
- def bwhite
65
- "\033[1;37m#{self}\033[0m"
66
- end
67
- end
68
6
 
69
7
  public
70
8
 
71
- def env_bool(name, default: false)
72
- return default if name.nil? || (val = ENV[name]).nil?
73
- return false if val.empty? || val == '0'
9
+ BF = 'bin'
74
10
 
75
- true
76
- end
11
+ # display_level values
12
+ DISPLAY_LEVEL_BASE = 0 # required output
13
+ DISPLAY_LEVEL_ADMIN = 1
14
+ DISPLAY_LEVEL_DEBUG = 2
15
+ DISPLAY_LEVEL_DEFAULT = DISPLAY_LEVEL_ADMIN
16
+ DISPLAY_LEVEL_MAX = DISPLAY_LEVEL_DEBUG
77
17
 
78
- def env_int(name, default: 0)
79
- return default if name.nil? || (val = ENV[name]).nil?
80
- return default if val.empty?
18
+ # @execute_files[ind] = @execute_files[ind] + [block]
19
+ EF_STDOUT = 0
20
+ EF_STDERR = 1
21
+ EF_STDIN = 2
81
22
 
82
- val.to_i
83
- end
84
-
85
- def env_str(name, default: '')
86
- return default if name.nil? || (val = ENV[name]).nil?
87
-
88
- val || default
89
- end
23
+ LOCAL_YML = 'menu.yml'
24
+ MENU_YML = "lib/#{LOCAL_YML}"
90
25
 
91
- # debug output
92
- #
93
- def tap_inspect(format: nil, name: 'return')
94
- return self unless $pdebug
95
-
96
- cvt = {
97
- json: :to_json,
98
- string: :to_s,
99
- yaml: :to_yaml,
100
- else: :inspect
101
- }
102
- fn = cvt.fetch(format, cvt[:else])
103
-
104
- puts "-> #{caller[0].scan(/in `?(\S+)'$/)[0][0]}()" \
105
- " #{name}: #{method(fn).call}"
106
-
107
- self
26
+ def menu_from_yaml
27
+ YAML.load File.open(File.join(File.expand_path(__dir__), LOCAL_YML))
108
28
  end
109
29
 
30
+ # skip :reek:UtilityFunction
110
31
  def value_for_cli(value)
111
32
  case value.class.to_s
112
33
  when 'String'
@@ -117,5 +38,3 @@ def value_for_cli(value)
117
38
  Shellwords.escape value.to_s
118
39
  end
119
40
  end
120
-
121
- $pdebug = env_bool 'MDE_DEBUG'
data/lib/tap.rb ADDED
@@ -0,0 +1,42 @@
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
+ ## application-level debug control
12
+ #
13
+ module Tap
14
+ $tap_enable = env_bool 'TAP_DEBUG'
15
+
16
+ def tap_config(enable: nil, envvar: nil, value: nil)
17
+ $tap_enable = if envvar
18
+ env_bool envvar
19
+ elsif value
20
+ value.to_i != 0
21
+ elsif enable
22
+ enable
23
+ end
24
+ end
25
+
26
+ def tap_inspect(format: nil, name: 'return')
27
+ return self unless $tap_enable
28
+
29
+ cvt = {
30
+ json: :to_json,
31
+ string: :to_s,
32
+ yaml: :to_yaml,
33
+ else: :inspect
34
+ }
35
+ fn = cvt.fetch(format, cvt[:else])
36
+
37
+ puts "-> #{caller[0].scan(/in `?(\S+)'$/)[0][0]}()" \
38
+ " #{name}: #{method(fn).call}"
39
+
40
+ self
41
+ end
42
+ 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.1.0
4
+ version: 1.3.0
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-05-21 00:00:00.000000000 Z
11
+ date: 2022-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -91,6 +91,7 @@ executables:
91
91
  extensions: []
92
92
  extra_rdoc_files: []
93
93
  files:
94
+ - ".reek"
94
95
  - ".rubocop.yml"
95
96
  - CHANGELOG.md
96
97
  - CODE_OF_CONDUCT.md
@@ -109,9 +110,14 @@ files:
109
110
  - bin/setup
110
111
  - bin/tab_completion.sh
111
112
  - bin/tab_completion.sh.erb
113
+ - lib/colorize.rb
114
+ - lib/env.rb
115
+ - lib/globfiles.rb
112
116
  - lib/markdown_exec.rb
113
117
  - lib/markdown_exec/version.rb
118
+ - lib/menu.yml
114
119
  - lib/shared.rb
120
+ - lib/tap.rb
115
121
  homepage: https://rubygems.org/gems/markdown_exec
116
122
  licenses:
117
123
  - MIT
@@ -120,7 +126,14 @@ metadata:
120
126
  homepage_uri: https://rubygems.org/gems/markdown_exec
121
127
  rubygems_mfa_required: 'true'
122
128
  source_code_uri: https://github.com/fareedst/markdown_exec
123
- post_install_message:
129
+ post_install_message: |2+
130
+
131
+ To install tab completion:
132
+ - Append a command to load the completion script to your shell configuration file.
133
+ - This gem must be installed and executable for the command to be composed correctly.
134
+
135
+ echo "source $(mde --pwd)/bin/tab_completion.sh" >> ~/.bash_profile
136
+
124
137
  rdoc_options: []
125
138
  require_paths:
126
139
  - lib
@@ -140,3 +153,4 @@ signing_key:
140
153
  specification_version: 4
141
154
  summary: Interactively select and execute fenced code blocks in markdown files.
142
155
  test_files: []
156
+ ...