Hardhat
...
Installation
...
CLI
...
Documentation
Hardhat is essentially a collection of helper classes and modules for performing actions common to a build. Things like installing dependencies, downloading code from version control, moving files into place, patching files, running daemons, and even making images.
Installing Dependencies
Projects have a collection of dependencies, some are for a single purpose, and some a required for many purposes. By grouping these dependencies up by what they are required for it make managing them easier.
Dependency lists should look like this:
breakfast_deps = [
Dependency.new "milk",
Dependency.new "cereal",
Dependency.new "bowl",
Dependency.new "spoon",
]
Then to install the dependencies:
meal_installer = Installer.new "mealer"
meal_installer.install breakfast_deps
By default this translates to:
mealer install milk
mealer install cereal
mealer install bowl
mealer install spoon
Hardhat::Dependency
Class for defining dependencies for the project. The first argument is the
name of the dependency, and is used to tell the package manager how to install.
The second argument is an optional hash, where you can define :installer
to
limit what installers can deal with this dependency, :sudo
to define if
this needs to be run as sudo to install, and :flags
to pass command line
flags to the package manager.
Examples:
# must install with gem
@rails = Dependency.new("rails", :installer => "gem")
@highline = Dependency.new("highline", :sudo => false, :installer => "gem")
@bundler = Dependency.new("bundler", :sudo => true, :installer => "gem")
# doesn't care what you install with
@foo = Dependency.new('foo', :flags => "-noop")
@bar = Dependency.new('bar', :sudo => false, :flags => "--verbose -q")
@baz = Dependency.new('baz', :sudo => true, :flags => "-qweF=1")
# can install with array of installer names
@git = Dependency.new("git", :installer => ["apt-get", "yum"])
@ack = Dependency.new("ack", :sudo => false, :installer => ["apt-get", "yum"])
@curl = Dependency.new("curl", :sudo => true, :installer => ["apt-get", "yum"])
Hardhat::Installer
Class for defining system programs to install dependencies. The first argument
is the name of the program to run, apt-get
for example. The second argument
is an optional hash much like for Dependency
. You can specify :sudo
to
make all dependencies handled by this installer done so as root. :flags
to
pass command line flags to the program for all dependencies.
Installers have 3 main methods, install
, uninstall
and remove
. By
default Installer.new('gem').install ...
will call gem install ...
.
Custom commands
Installer.new('apt-get', :uninstall => :remove).uninstall ...
apt-get remove ...
Installer.new('foo', :update => :bar).update ...
foo bar ...
Getting Code from Version Control
When building on a new system often times the code will not be there yet,
Hardhat::Repository
defines the how to pull code down from VC. It is a
module currently with 2 classes the include it, Hardhat::Repository::Git
and Hardhat::Repository::Svn
.
Classes that include Hardhat::Repository
must define a get
and a branch
method.
Hardhat::Repository::Git
repo = Repository::Git.new "https://gist.github.com/4772101.git", "/tmp/hh"
repo.get # downloads the repo to /tmp/hh
Hardhat::Repository::Svn
repo = Repository::Svn.new "http://svn.apache.org/repos/asf/spamassassin/trunk", "/tmp/hh"
repo.get # downloads the repo to /tmp/hh
Other Useful Code
Miscellaneous helper methods and classes.
main
How to print to the user from Hardhat:
inform "something to tell the user"
warn "a thing to be weary of"
error "oh god something broke"
Hardhat::System
Helper module for interacting with the operating system.
::has? -> boolean
Hardhat::System.has?('git') => true
Hardhat::System.has?(['git', 'svn']) => false