Project

scallop

0.06
No release in over 3 years
Low commit activity in last 3 years
Ergonomic shell wrapper.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.17
~> 0.12
~> 10.0
~> 3.0
~> 0.71
~> 0.16
 Project Readme

Gem Version CircleCI Maintainability Test Coverage

Scallop

Ergonomic shell wrapper.

Features:

  • Easy access to command's output (stdout & stderr)
  • Failure handling
  • Parameterization
  • Measuring execution time
  • Built-in string escaping
  • No dependencies

Installation

Add this line to your application's Gemfile:

gem 'scallop'

And then execute:

$ bundle

Or install it yourself as:

$ gem install scallop

Usage

To run sudo -u chuck grep -R /home/chuck

result = Scallop.sudo(:chuck).cmd(:grep, '-R', '/home/chuck').run

You can then check whether command succeeded

result.success?

See its output

result.stdout
result.stderr
result.output # STDOUT and STDERR combined

You can also access information about command execution time

result.timing.real # Elapsed real time
result.timing.stime # System CPU time
result.timing.utime # User CPU time
result.timing.total # Total time, that is utime + stime + cutime + cstime

Handling failures with exceptions

If you replace run with run!, exception will be raised in case command fails

begin
  Scallop.cmd(some_command).run!
rescue Scallop::Errors::CommandFailed => error
  # you can access result right on the error itself
  error.result.stderr
end

Piping

To run cat /some/file | grep something

command = Scallop.cmd(:cat, '/some/file') | Scallop.cmd(:grep, 'something')
command.run

Parameterization

stored_command = Scallop.cmd(:rm, '-rf', Scallop::Param[:path])

stored_command.set(path: '/foo').run # rm -rf /foo
stored_command.set(path: '/bar').run # rm -rf /bar

You can also check specs for examples.