Bindep

A simple way to manage binary dependencies for multiple platforms.

Gem Version Build Status Coverage Status Code Climate

Example

To install git and complile some less code:


require "bindep"
require "bindep/library"

# prompt user to install git if it is not available, do nothing otherwise
Bindep.check :git

# prompt to install less compiler if it is not available, 
# then run it with given parameters
css_code, stderr = Bindep.run :less, "-x -", less_code

Installation

Install the gem:

gem install bindep

Usage

Load the gem:

require "bindep"  # core module
require "bindep/library"  # predefined packages (optional)

Check if a package is available and prompt the user to install it otherwise:

Bindep.check :git

Run commands (run calls check automatically):

# syntax
stdout, stderr, exitcode = Bindep.run :package, stdin, raise_on_error

# no exception on failure
css_code, stderr, exitcode = Bindep.run :less, "-x -", less_code, false
css_code = "" unless exitcode.zero?

# raise on failure
begin
  output, stderr = Bindep.run :git, "status"
  puts output
rescue RuntimeError
  puts "Git failed!"
end

Define new packages and check/install them:

Bindep.define(:npm) do |i|
  i.command = "npm"
  i.apt = [ "nodejs", "npm" ]
  i.brew = "node"
end

Bindep.define(:lessc) do |i|
  i.command = "lessc"        
  i.npm = "lessc"
  i.depends = [ :npm ] 
end 

Bindep.check :lessc

Combine define and check:

Bindep.check(:git) do |i|
  i.command = "npm"
  i.apt = "git-core"
  i.brew = "git"
  i.yum = "git-core"
end

Command Line Usage

Create a Bindepfile in your project root using the same syntax:

check :less

check(:git) do |i|
  i.command = "npm"
  i.apt = "git-core"
  i.brew = "git"
  i.yum = "git-core"
end

and execute it by running bindep in your shell.

You can also parse a Bindepfile from your code using:

Bindep.load_file 'MyBindepfile'

Configuration

Add any of the following lines to your code before running any bindep commands.

# Abort if command is not found, do not try to install.
Bindep.no_install = true

# Do not ask user for confirmation before installing.
Bindep.no_confirm_before_install = true

# Do not output error messages and exit process but raise exceptions instead.
Bindep.silent_exceptions = true

You can also set these in your Bindepfile by adding any of the following before the commands:

@no_install = true
@no_confirm_before_install = true
@silent_exceptions = true

Contributing

I really appreciate any input, either code or new library entries, so please:

  1. Fork it ( https://github.com/dziemba/bindep/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am "Add some feature")
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request