lib/markdown_exec.rb in markdown_exec-1.8.5 vs lib/markdown_exec.rb in markdown_exec-1.8.6
- old
+ new
@@ -39,10 +39,12 @@
tap_config envvar: MarkdownExec::TAP_DEBUG
$stderr.sync = true
$stdout.sync = true
+ARGV_SEP = '--'
+
# custom error: file specified is missing
#
class FileMissingError < StandardError; end
def dp(str)
@@ -134,14 +136,15 @@
"CachedNestedFileReader.#{name} -- #{message}",
opts
)
end
- # return arguments before `--`
+ # return arguments before ARGV_SEP
+ # arguments after ARGV_SEP are passed to the generatede script
#
def arguments_for_mde(argv = ARGV)
- case ind = argv.find_index('--')
+ case ind = argv.find_index(ARGV_SEP)
when nil
argv
when 0
[]
else
@@ -203,18 +206,17 @@
# end
# Reports and executes block logic
def execute_block_logic(files)
@options[:filename] = select_document_if_multiple(files)
- @options.select_execute_bash_and_special_blocks
+ @options.document_menu_loop
end
## Executes the block specified in the options
#
def execute_block_with_error_handling
finalize_cli_argument_processing
- @options[:input_cli_rest] = @rest
execute_code_block_based_on_options(@options)
rescue FileMissingError
warn "File missing: #{$!}"
rescue StandardError
error_handler('execute_block_with_error_handling')
@@ -291,10 +293,11 @@
## position 1: block name (optional)
#
block_name = rest.shift
@options[:block_name] = block_name if block_name.present?
+ @options[:input_cli_rest] = @rest
rescue FileMissingError
warn_format('finalize_cli_argument_processing',
"File missing -- #{$!}", { abort: true })
# @options[:block_name] = ''
# @options[:filename] = ''
@@ -344,14 +347,15 @@
->(value) { tap_config value: value }
when 'exit'
->(_) { exit }
when 'find'
->(value) {
+ find_path = @options[:find_path].present? ? @options[:find_path] : @options[:path]
@fout.fout 'Searching in: ' \
- "#{HashDelegator.new(@options).string_send_color(@options[:path],
+ "#{HashDelegator.new(@options).string_send_color(find_path,
:menu_chrome_color)}"
- searcher = DirectorySearcher.new(value, [@options[:path]])
+ searcher = DirectorySearcher.new(value, [find_path])
@fout.fout 'In file contents'
hash = searcher.search_in_file_contents
hash.each.with_index do |(key, v2), i1|
@fout.fout format('- %3.d: %s', i1 + 1, key)
@@ -544,11 +548,11 @@
@options[:saved_script_glob])
return unless filename
saved_name_split filename
@options[:save_executed_script] = false
- @options.select_execute_bash_and_special_blocks
+ @options.document_menu_loop
rescue StandardError
error_handler('run_last_script')
end
def saved_name_split(name)
@@ -611,10 +615,10 @@
)
return if filename.nil?
saved_name_split(filename)
- @options.select_execute_bash_and_special_blocks ### ({ save_executed_script: false })
+ @options.document_menu_loop ### ({ save_executed_script: false })
end
public
def tab_completions(data = menu_for_optparse)