markdown_exec 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/Rakefile +6 -7
- data/bin/mde +2 -4
- data/lib/markdown_exec/version.rb +4 -1
- data/lib/markdown_exec.rb +137 -154
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a4e558c22601546757b3fdd28f0c438ca1419badd2416e8beac4bc35692d6fe
|
4
|
+
data.tar.gz: fdb68f22046be5c9c00b9044330a2891ac047505644defdb493b2795c0852943
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0d32562440fc40f82dd00d189a51f55e0d7f5ca4dcc2f80d3c915622222a3234bafd162abb6931f78ab1d32fc067eba97c0788a6dca0bfaa87ce653001c62e6
|
7
|
+
data.tar.gz: 44de2ffe388333c536512bef6cd6981424ed68f84a157d0b60397ae598a4cf60dae49b413c91d2683da9d544bd6d5c5790bd7f278c6ed5873e1d3f74f30f6f67
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -13,27 +13,26 @@ require 'rubocop/rake_task'
|
|
13
13
|
|
14
14
|
RuboCop::RakeTask.new
|
15
15
|
|
16
|
-
|
16
|
+
require_relative 'lib/markdown_exec/version'
|
17
17
|
|
18
|
-
|
19
|
-
GEM_VERSION = '0.0.6'
|
18
|
+
task default: %i[test rubocop]
|
20
19
|
|
21
20
|
# task :default => :build
|
22
21
|
|
23
22
|
task :build do
|
24
|
-
system "gem build #{GEM_NAME}.gemspec"
|
23
|
+
system "gem build #{MarkdownExec::GEM_NAME}.gemspec"
|
25
24
|
end
|
26
25
|
|
27
26
|
task install: :build do
|
28
|
-
system "gem install #{GEM_NAME}-#{
|
27
|
+
system "gem install #{MarkdownExec::GEM_NAME}-#{MarkdownExec::VERSION}.gem"
|
29
28
|
end
|
30
29
|
|
31
30
|
task publish: :build do
|
32
|
-
system "gem push #{GEM_NAME}-#{
|
31
|
+
system "gem push #{MarkdownExec::GEM_NAME}-#{MarkdownExec::VERSION}.gem"
|
33
32
|
end
|
34
33
|
|
35
34
|
task uninstall: :build do
|
36
|
-
system "gem uninstall #{GEM_NAME}"
|
35
|
+
system "gem uninstall #{MarkdownExec::GEM_NAME}"
|
37
36
|
end
|
38
37
|
|
39
38
|
task :clean do
|
data/bin/mde
CHANGED
data/lib/markdown_exec.rb
CHANGED
@@ -1,38 +1,17 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'markdown_exec/version'
|
4
|
-
|
5
1
|
#!/usr/bin/env ruby
|
6
2
|
# frozen_string_literal: true
|
7
3
|
|
8
4
|
# encoding=utf-8
|
9
|
-
# rubocop:disable Style/GlobalVars
|
10
|
-
|
11
|
-
env_debug = ENV['MARKDOWN_EXEC_DEBUG']
|
12
|
-
$pdebug = !(env_debug || '').empty?
|
13
5
|
|
14
|
-
#
|
15
|
-
|
16
|
-
# VERSION = '0.0.6'
|
17
|
-
|
18
|
-
# require 'markdown_exec'
|
19
|
-
# # puts MarkdownExec::MarkParse.echo(ARGV[0])
|
6
|
+
# rubocop:disable Style/GlobalVars
|
7
|
+
$pdebug = !(ENV['MARKDOWN_EXEC_DEBUG'] || '').empty?
|
20
8
|
|
9
|
+
require 'open3'
|
21
10
|
require 'optparse'
|
22
11
|
require 'pathname'
|
23
12
|
require 'tty-prompt'
|
24
13
|
require 'yaml'
|
25
|
-
|
26
|
-
# require_relative 'mdlib'
|
27
|
-
# #!/usr/bin/env ruby
|
28
|
-
# # frozen_string_literal: true
|
29
|
-
# # encoding=utf-8
|
30
|
-
|
31
|
-
# env_debug = ENV['MARKDOWN_EXEC_DEBUG']
|
32
|
-
# $pdebug = !(env_debug || '').empty?
|
33
|
-
|
34
|
-
require 'open3'
|
35
|
-
# require 'tty-prompt'
|
14
|
+
require_relative 'markdown_exec/version'
|
36
15
|
|
37
16
|
BLOCK_SIZE = 1024
|
38
17
|
SELECT_PAGE_HEIGHT = 12
|
@@ -40,12 +19,6 @@ SELECT_PAGE_HEIGHT = 12
|
|
40
19
|
module MarkdownExec
|
41
20
|
class Error < StandardError; end
|
42
21
|
|
43
|
-
# Markdown Exec
|
44
|
-
# class MarkParse
|
45
|
-
# def self.echo(str = '')
|
46
|
-
# "#{str}#{str}"
|
47
|
-
# end
|
48
|
-
# end
|
49
22
|
##
|
50
23
|
#
|
51
24
|
class MarkParse
|
@@ -183,7 +156,7 @@ module MarkdownExec
|
|
183
156
|
end
|
184
157
|
end
|
185
158
|
blocks.tap { |ret| puts "get_blocks() ret: #{ret.inspect}" if $pdebug }
|
186
|
-
end
|
159
|
+
end # get_blocks
|
187
160
|
|
188
161
|
def make_block_label(block, call_options = {})
|
189
162
|
opts = options.merge(call_options)
|
@@ -303,7 +276,7 @@ module MarkdownExec
|
|
303
276
|
end
|
304
277
|
|
305
278
|
selected[:name]
|
306
|
-
end
|
279
|
+
end # select_block
|
307
280
|
|
308
281
|
def select_md_file
|
309
282
|
opts = options
|
@@ -387,150 +360,160 @@ module MarkdownExec
|
|
387
360
|
end
|
388
361
|
all.tap { |ret| puts "unroll() ret: #{ret.inspect}" if $pdebug }
|
389
362
|
end
|
390
|
-
end
|
391
363
|
|
392
|
-
|
393
|
-
|
364
|
+
# $stderr.sync = true
|
365
|
+
# $stdout.sync = true
|
394
366
|
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
options
|
405
|
-
.transform_keys(&:to_sym))
|
406
|
-
# rubocop:enable Security/YAMLLoad
|
367
|
+
## configuration file
|
368
|
+
#
|
369
|
+
def read_configuration!(options, configuration_path)
|
370
|
+
if Pathname.new(configuration_path).exist?
|
371
|
+
# rubocop:disable Security/YAMLLoad
|
372
|
+
options.merge!((YAML.load(File.open(configuration_path)) || {})
|
373
|
+
.transform_keys(&:to_sym))
|
374
|
+
# rubocop:enable Security/YAMLLoad
|
375
|
+
end
|
376
|
+
options
|
407
377
|
end
|
408
|
-
options
|
409
|
-
end
|
410
378
|
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
379
|
+
def run
|
380
|
+
## default configuration
|
381
|
+
#
|
382
|
+
options = {
|
383
|
+
mdheadings: true,
|
384
|
+
list_blocks: false,
|
385
|
+
list_docs: false,
|
386
|
+
mdfilename: 'README.md',
|
387
|
+
mdfolder: '.'
|
388
|
+
}
|
421
389
|
|
422
|
-
|
390
|
+
def options_finalize!(options); end
|
423
391
|
|
424
|
-
|
425
|
-
#
|
426
|
-
read_configuration! options, ".#{APP_NAME.downcase}.yml"
|
392
|
+
# puts "MDE run() ARGV: #{ARGV.inspect}"
|
427
393
|
|
428
|
-
|
429
|
-
#
|
430
|
-
# load_resources! options
|
431
|
-
# puts "q31 options: #{options.to_yaml}" if $pdebug
|
432
|
-
|
433
|
-
# rubocop:disable Metrics/BlockLength
|
434
|
-
option_parser = OptionParser.new do |opts|
|
435
|
-
executable_name = File.basename($PROGRAM_NAME)
|
436
|
-
opts.banner = [
|
437
|
-
"#{APP_NAME} - #{APP_DESC} (#{VERSION})".freeze,
|
438
|
-
"Usage: #{executable_name} [options]"
|
439
|
-
].join("\n")
|
440
|
-
|
441
|
-
## menu top: on_head appear in reverse order added
|
394
|
+
# read local configuration file
|
442
395
|
#
|
443
|
-
|
444
|
-
read_configuration! options, value
|
445
|
-
end
|
396
|
+
read_configuration! options, ".#{MarkdownExec::APP_NAME.downcase}.yml"
|
446
397
|
|
447
|
-
##
|
398
|
+
## read current details for aws resources from app_data_file
|
448
399
|
#
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
400
|
+
# load_resources! options
|
401
|
+
# puts "q31 options: #{options.to_yaml}" if $pdebug
|
402
|
+
|
403
|
+
# rubocop:disable Metrics/BlockLength
|
404
|
+
option_parser = OptionParser.new do |opts|
|
405
|
+
executable_name = File.basename($PROGRAM_NAME)
|
406
|
+
opts.banner = [
|
407
|
+
"#{MarkdownExec::APP_NAME} - #{MarkdownExec::APP_DESC} (#{MarkdownExec::VERSION})",
|
408
|
+
"Usage: #{executable_name} [options]"
|
409
|
+
].join("\n")
|
410
|
+
|
411
|
+
## menu top: on_head appear in reverse order added
|
412
|
+
#
|
413
|
+
opts.on('--config PATH', 'Read configuration file') do |value|
|
414
|
+
read_configuration! options, value
|
415
|
+
end
|
456
416
|
|
457
|
-
|
458
|
-
|
459
|
-
|
417
|
+
## menu body: items appear in order added
|
418
|
+
#
|
419
|
+
opts.on('-f RELATIVE', '--mdfilename', 'Name of document') do |value|
|
420
|
+
options[:mdfilename] = value
|
421
|
+
end
|
460
422
|
|
461
|
-
|
462
|
-
|
463
|
-
|
423
|
+
opts.on('-p PATH', '--mdfolder', 'Path to documents') do |value|
|
424
|
+
options[:mdfolder] = value
|
425
|
+
end
|
464
426
|
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
puts option_parser.help
|
469
|
-
exit
|
470
|
-
end
|
427
|
+
opts.on('--list-blocks', 'List blocks') do |_value|
|
428
|
+
options[:list_blocks] = true
|
429
|
+
end
|
471
430
|
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
end
|
431
|
+
opts.on('--list-docs', 'List docs in current folder') do |_value|
|
432
|
+
options[:list_docs] = true
|
433
|
+
end
|
476
434
|
|
477
|
-
|
478
|
-
|
479
|
-
|
435
|
+
## menu bottom: items appear in order added
|
436
|
+
#
|
437
|
+
opts.on_tail('-h', '--help', 'App help') do |_value|
|
438
|
+
puts option_parser.help
|
439
|
+
exit
|
440
|
+
end
|
480
441
|
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
end
|
486
|
-
# rubocop:enable Metrics/BlockLength
|
442
|
+
opts.on_tail('-v', '--version', 'App version') do |_value|
|
443
|
+
puts MarkdownExec::VERSION
|
444
|
+
exit
|
445
|
+
end
|
487
446
|
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
options_finalize! options
|
447
|
+
opts.on_tail('-x', '--exit', 'Exit app') do |_value|
|
448
|
+
exit
|
449
|
+
end
|
492
450
|
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
{
|
500
|
-
approve: true,
|
501
|
-
bash: true,
|
502
|
-
display: true,
|
503
|
-
exclude_expect_blocks: true,
|
504
|
-
execute: true,
|
505
|
-
prompt: 'Execute',
|
506
|
-
struct: true
|
507
|
-
}
|
508
|
-
)
|
509
|
-
|
510
|
-
## show
|
511
|
-
#
|
512
|
-
if options[:list_docs]
|
513
|
-
fout mp.find_files
|
514
|
-
break
|
515
|
-
end
|
451
|
+
opts.on_tail('-0', 'Show configuration') do |_v|
|
452
|
+
options_finalize! options
|
453
|
+
puts options.to_yaml
|
454
|
+
end
|
455
|
+
end # OptionParser
|
456
|
+
# rubocop:enable Metrics/BlockLength
|
516
457
|
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
break
|
522
|
-
end
|
458
|
+
option_parser.load # filename defaults to basename of the program without suffix in a directory ~/.options
|
459
|
+
option_parser.environment # env defaults to the basename of the program.
|
460
|
+
option_parser.parse! # (into: options)
|
461
|
+
options_finalize! options
|
523
462
|
|
524
463
|
## process
|
525
464
|
#
|
526
|
-
|
465
|
+
# rubocop:disable Metrics/BlockLength
|
466
|
+
loop do # once
|
467
|
+
mp = MarkParse.new options
|
468
|
+
options.merge!(
|
469
|
+
{
|
470
|
+
approve: true,
|
471
|
+
bash: true,
|
472
|
+
display: true,
|
473
|
+
exclude_expect_blocks: true,
|
474
|
+
execute: true,
|
475
|
+
prompt: 'Execute',
|
476
|
+
struct: true
|
477
|
+
}
|
478
|
+
)
|
479
|
+
|
480
|
+
## show
|
481
|
+
#
|
482
|
+
if options[:list_docs]
|
483
|
+
fout mp.find_files
|
484
|
+
break
|
485
|
+
end
|
527
486
|
|
528
|
-
|
529
|
-
|
487
|
+
if options[:list_blocks]
|
488
|
+
fout (mp.find_files.map do |file|
|
489
|
+
mp.make_block_labels(mdfilename: file, struct: true)
|
490
|
+
end).flatten(1).to_yaml
|
491
|
+
break
|
492
|
+
end
|
493
|
+
|
494
|
+
## process
|
495
|
+
#
|
496
|
+
mp.select_block(bash: true, struct: true) if options[:mdfilename]
|
497
|
+
|
498
|
+
# rubocop:disable Style/BlockComments
|
499
|
+
=begin
|
500
|
+
# rescue ArgumentError => e
|
501
|
+
# puts "User abort: #{e}"
|
502
|
+
|
503
|
+
# rescue StandardError => e
|
504
|
+
# puts "ERROR: #{e}"
|
505
|
+
# raise StandardError, e
|
506
|
+
|
507
|
+
# ensure
|
508
|
+
# exit
|
509
|
+
=end
|
510
|
+
# rubocop:enable Style/BlockComments
|
511
|
+
|
512
|
+
break unless false # rubocop:disable Lint/LiteralAsCondition
|
513
|
+
end # loop
|
514
|
+
end # run
|
515
|
+
end # class MarkParse
|
530
516
|
|
531
|
-
break unless false # rubocop:disable Lint/LiteralAsCondition
|
532
|
-
end
|
533
|
-
end
|
534
517
|
# rubocop:enable Metrics/BlockLength
|
535
518
|
# rubocop:enable Style/GlobalVars
|
536
|
-
end
|
519
|
+
end # module MarkdownExec
|