Sha256: d4967c3e334475cb3d1d33ebdac134a0a55604c6a77fbea4b1fd2c78248cfe86

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require_relative '../lib/conductor'
require 'optparse'

# raise 'No input on STDIN' unless Conductor.stdin

include Conductor

config = Config.new

stdin = Conductor.stdin

def conduct(tracks, res = nil, condition = nil)
  tracks.each do |track|
    cond = Condition.new(track[:condition])

    next unless cond.true?

    if track[:tracks]
      ts = track[:tracks].symbolize_keys

      res, condition = conduct(ts, res, condition)

      next if res.nil?
    end

    condition = condition.nil? ? track[:condition] : "#{track[:condition]} > #{condition}"

    if track[:script]
      script = Script.new(track[:script])

      res = script.run
    elsif track[:command]
      command = Command.new(track[:command])

      res = command.run
    end

    break
  end

  [res, condition]
end

options = {}
optparse = OptionParser.new do|opts|
  opts.banner = "Called from Marked 2 as a Custom Pre/Processor"

  opts.on('-v', '--version', 'Show version number') do
    puts "conductor v#{Conductor::VERSION}"
    Process.exit 0
  end

  opts.on('-h', '--help', 'Display this screen') do
    puts opts
    exit
  end
end

optparse.parse!

tracks = config.tracks
res, condition = conduct(tracks)

if res.nil?
  $stderr.puts('No conditions satisfied')
  puts 'NOCUSTOM'
else
  $stderr.puts("Met condition: #{condition}")
  puts res
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
marked-conductor-1.0.7 bin/conductor
marked-conductor-1.0.6 bin/conductor