Module: Nanoc::Tidy::Spawn

Included in:
Filter
Defined in:
lib/nanoc/tidy/spawn.rb

Instance Method Summary collapse

Instance Method Details

#spawn(exe, argv) ⇒ Integer

Spawns a process

Parameters:

  • exe (String)

    The path to an executable

  • argv (Array<String>)

    An array of command line arguments

Returns:

  • (Integer)

    Returns the exit code of the spawned process



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nanoc/tidy/spawn.rb', line 19

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