Sha256: c5bbf0a6198b4e8652508e15ee17e75beb3aa228920637203dba2c3f2588070b

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Nanoc::Tidy
  module Spawn
    require "fileutils"
    require "test-cmd"

    ##
    # Spawns a process
    #
    # @param [String] exe
    #  The path to an executable
    #
    # @param [Array<String>] argv
    #  An array of command line arguments
    #
    # @return [Integer]
    #  Returns the exit code of the spawned process
    def spawn(exe, argv)
      r = cmd(exe, *argv)
      ##
      # tidy-html5 exit codes
      #  * 0: no warnings, no errors
      #  * 1: has warnings
      #  * 2: has errors
      if r.not_found?
        raise Nanoc::Tidy::Error, "The tidy executable was not found"
      elsif [0, 1].include?(r.exit_status)
        r.exit_status
      else
        raise Nanoc::Tidy::Error,
              "#{File.basename(exe)} exited unsuccessfully\n" \
              "(item: #{item.identifier})\n" \
              "(exit code: #{r.exit_status})\n" \
              "(stdout: #{r.stdout&.chomp})\n" \
              "(stderr: #{r.stderr&.chomp})\n",
              []
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nanoc-tidy.rb-0.8.5 lib/nanoc/tidy/spawn.rb