GithubHelp home page GithubHelp logo

scallop's Introduction

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.

scallop's People

Contributors

dependabot[bot] avatar erebusbat avatar reneklacan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.