Class: Semverve::DocsPublisher::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/semverve/docs_publisher.rb

Overview

Small command runner used by the publisher.

Instance Method Summary collapse

Instance Method Details

#capture(command, chdir: nil) ⇒ String

Captures a command's standard output and raises when it fails.

Parameters:

  • command (Array<String>)
  • chdir (String, nil) (defaults to: nil)

Returns:

  • (String)


40
41
42
# File 'lib/semverve/docs_publisher.rb', line 40

def capture(command, chdir: nil)
  run(command, chdir: chdir)
end

#run(command, chdir: nil) ⇒ String

Runs a command and raises when it fails.

Parameters:

  • command (Array<String>)
  • chdir (String, nil) (defaults to: nil)

Returns:

  • (String)

Raises:



26
27
28
29
30
31
# File 'lib/semverve/docs_publisher.rb', line 26

def run(command, chdir: nil)
  stdout, stderr, status = capture_command(command, chdir: chdir)
  return stdout if status.success?

  raise Error, "Command failed: #{command.join(" ")}\n#{stderr}"
end

#success?(command, chdir: nil) ⇒ Boolean

Whether a command exits successfully.

Parameters:

  • command (Array<String>)
  • chdir (String, nil) (defaults to: nil)

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/semverve/docs_publisher.rb', line 51

def success?(command, chdir: nil)
  _stdout, _stderr, status = capture_command(command, chdir: chdir)
  status.success?
end