lib/org-converge/command.rb in org-converge-0.0.4 vs lib/org-converge/command.rb in org-converge-0.0.5
- old
+ new
@@ -35,26 +35,36 @@
false
end
def converge!
tangle!
- case @options['--runmode']
+ if @options['--runmode']
+ dispatch_runmode(@options['--runmode'])
+ else
+ # Try to find one in the buffer
+ runmode = ob.in_buffer_settings['RUNMODE']
+ dispatch_runmode(runmode)
+ end
+ end
+
+ def dispatch_runmode(runmode)
+ case runmode
when 'parallel'
run_blocks_in_parallel!
when 'sequential'
run_blocks_sequentially!
when 'runlist'
# TODO
- else
+ else # parallel by default
run_blocks_in_parallel!
end
end
def tangle!
results = babel.tangle!
rescue Orgmode::Babel::TangleError
- logger.error "Cannot converge because there were errors during tangle step".red
+ logger.error "Cannot converge because there were errors during tangle step".fg 'red'
end
def run_blocks_sequentially!
@engine = OrgConverge::Engine.new(:logger => @logger, :babel => @babel)
babel.tangle_runnable_blocks!(@run_dir)
@@ -64,34 +74,42 @@
runlist_stack << [key, script]
end
while not runlist_stack.empty?
key, script = runlist_stack.shift
+
+ # Decision: Only run blocks which have a name
+ next unless script[:header][:name]
+
+ display_name = script[:header][:name]
with_running_engine do |engine|
file = File.expand_path("#{@run_dir}/#{key}")
cmd = "#{script[:lang]} #{file}"
- display_name = script[:header][:name] || script[:lang]
engine.register display_name, cmd, { :cwd => @root_dir, :logger => logger }
end
end
- logger.info "Run has completed successfully.".green
+ logger.info "Run has completed successfully.".fg 'green'
end
# TODO: Too much foreman has made this running blocks in parallel the default behavior.
# We should actually be supporting run lists instead, but liking this experiment so far.
def run_blocks_in_parallel!
@engine = OrgConverge::Engine.new(:logger => @logger, :babel => @babel)
babel.tangle_runnable_blocks!(@run_dir)
babel.ob.scripts.each do |key, script|
file = File.expand_path("#{@run_dir}/#{key}")
cmd = "#{script[:lang]} #{file}"
- display_name = script[:header][:name] || script[:lang]
+
+ # Decision: Only run blocks which have a name
+ next unless script[:header][:name]
+
+ display_name = script[:header][:name]
@engine.register display_name, cmd, { :cwd => @root_dir, :logger => logger }
end
logger.info "Running code blocks now! (#{babel.ob.scripts.count} runnable blocks found in total)"
@engine.start
- logger.info "Run has completed successfully.".green
+ logger.info "Run has completed successfully.".fg 'green'
end
def with_running_engine
engine = OrgConverge::Engine.new(:logger => @logger, :babel => @babel)
yield engine
@@ -102,15 +120,15 @@
@babel ||= Orgmode::Babel.new(ob, { :logger => @logger, :root_dir => @root_dir })
end
def showfiles
ob.tangle.each do |file, block|
- puts "---------- #{file} --------------".green
+ puts "---------- #{file} --------------".fg 'green'
puts block[:lines]
end
ob.scripts.each do |index, block|
- puts "---------- script: #{index} to be run with: #{block[:header][:shebang]} --------------".green
+ puts "---------- script: #{index} to be run with: #{block[:header][:shebang]} --------------".fg 'green'
puts block[:lines]
end
end
end
end