lib/markdown_exec.rb in markdown_exec-1.4 vs lib/markdown_exec.rb in markdown_exec-1.4.1
- old
+ new
@@ -7,10 +7,11 @@
require 'clipboard'
require 'fileutils'
require 'open3'
require 'optparse'
require 'shellwords'
+require 'tmpdir'
require 'tty-prompt'
require 'yaml'
require_relative 'block_label'
require_relative 'cached_nested_file_reader'
@@ -503,17 +504,18 @@
## Executes the block specified in the options
#
def execute_block_with_error_handling(rest)
finalize_cli_argument_processing(rest)
- execute_code_block_based_on_options(@options, @options[:block_name])
+ @options[:cli_rest] = rest
+ execute_code_block_based_on_options(@options)
rescue FileMissingError => err
puts "File missing: #{err}"
end
# Main method to execute a block based on options and block_name
- def execute_code_block_based_on_options(options, _block_name = '')
+ def execute_code_block_based_on_options(options)
options = calculated_options.merge(options)
update_options(options, over: false)
simple_commands = {
doc_glob: -> { fout options[:md_filename_glob] },
@@ -1086,10 +1088,19 @@
end
}
].compact)
end
+ def next_block_name_from_command_line_arguments(opts)
+ if opts[:cli_rest].present?
+ opts[:block_name] = opts[:cli_rest].pop
+ false # repeat_menu
+ else
+ true # repeat_menu
+ end
+ end
+
# :reek:ControlParameter
def optsmerge(call_options = {}, options_block = nil)
class_call_options = @options.merge(call_options || {})
if options_block
options_block.call class_call_options
@@ -1335,15 +1346,16 @@
end
load_file, next_block_name = approve_and_execute_block(opts, mdoc)
default = load_file == LOAD_FILE ? 1 : opts[:block_name]
opts[:block_name] = next_block_name
-
break if state == :continue && load_file == LOAD_FILE
break unless repeat_menu
end
break if load_file != LOAD_FILE
+
+ repeat_menu = next_block_name_from_command_line_arguments(opts)
end
rescue StandardError => err
warn(error = "ERROR ** MarkParse.select_approve_and_execute_block(); #{err.inspect}")
warn err.backtrace
binding.pry if $tap_enable
@@ -1623,10 +1635,9 @@
block_name,
opts: opts
)[:code]).join("\n")
Dir::Tmpname.create(self.class.to_s) do |path|
- pp path
File.write(path, code_blocks)
ENV['MDE_LINK_REQUIRED_FILE'] = path
end
end
end # class MarkParse