Script
The Script is everything you need to make the most of Ruby - a fabulous scripting language. The one started with idea of having nicely formatted output, but ended up in much more...
Table of contents
Setup
Install gem:
gem install script
Or add it as dependency to your Gemfile:
gem 'script'
Then simply require it in your script file:
require 'script'
And you're good to go.
Usage
Steps
Steps encourages you to split commands into higher level constructs which are essential for more complex scripts.
Use Script to define the steps:
#!/usr/bin/env ruby
require "script"
Script.define do |s|
s.step("step 1") do
# Commands
end
s.step("step 2") do
# Commands
end
end
Once you've run the ruby script, it will execute each of the steps in the order they were defined.
Error handling
In case of an error in one of the steps, the script is stopped right away without executing further steps.
Output
Nicely formatted output is the primary motivation behind the Script. Most of the time you want to separate your commands output , in order to help investigation or debugging later.
Let's take for an example the following script:
#!/usr/bin/env ruby
require "script"
Script.define do |s|
s.step("setup") do
system("bundle install")
end
s.step("build") do
system("bundle exec rake spec")
end
s.step("deploy") do
system("gem push script-*")
end
end
Shareables
In case you need to share data between steps, you can pass hash of shareables to the step block:
script.step("Step 1") do |shareables|
shareables["environment"] = "production"
end
script.step("Step 2") do |shareables|
environment = shareables["environment"]
puts "Deploying on #{environment} environment"
end
Contributing
# Clone the repo
git clone git@github.com:bmarkons/script.git
# Install
bundle install
# Run tests
bundle exec rspec
Pull requests are always welcome. In case you notice any bug or simply want to propose an improvement, please feel free to open an issue.
Code of Conduct
Please be nice.
License
The gem is available as open source under the terms of the MIT License.