Scriptster is a small Ruby gem that will help you write scripts in Ruby. It only consists of two functions and it's especially useful for apps which depend on many external tools.
This library focuses on these two basic things:
- Running shell commands
- Providing nice logs and status messages about what happened
See the examples bellow.
require 'scriptster'
It's not necessary to configure scriptster before using it, if you're happy
with the default settings. But chances are you won't be, in which case the
configure
method is exactly what you're after. Bellow is a quick example
(for the full list of options, please refer to the
docs):
Scriptster::configure do |conf|
conf.name = "my-script"
conf.verbosity = :verbose
conf.file = nil
conf.colours = :dark
conf.log_format = "%{timestamp} %{name} %{type} %{message}"
end
The following snippet demonstrates how can you use scriptster in practice:
Scriptster::log :info, "Checking branches"
git_cmd = Scriptster::cmd "git branch",
:show_out => true,
:show_err => true
branch = "develop"
branch_exists = git_cmd.out.split("\n").grep(/#{branch}/).length > 0
Scriptster::log(:warn, "Branch '#{branch}' not found") unless branch_exists
The first log
method will format and print a status message to stdout.
The latter cmd
method executes the given git
command, prints it's
output, but it also keeps it for processing. You will find more about
the options and parameters of these functions in the
documentation.
Add this line to your application's Gemfile:
gem 'scriptster'
And then execute:
$ bundle
Or install it yourself as:
$ gem install scriptster
- Fork it ( https://github.com/[my-github-username]/scriptster/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request