Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created June 18, 2009 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkerbot/131720 to your computer and use it in GitHub Desktop.
Save thinkerbot/131720 to your computer and use it in GitHub Desktop.
A stand-alone Task executable
#! /usr/bin/env ruby
require 'rubygems'
require 'tap/task'
# Sample::task a sample task
#
# This is a sample of a task used as an executable. This is a sample of a
# task used as an executable. This is a sample of a task used as an
# executable.
#
# sample code
#
# This is a sample of a task used as an executable. This is a sample of a
# task used as an executable. This is a sample of a task used as an
# executable.
class Sample < Tap::Task
config :message, "hello" # A configurable message
def process(input)
puts "#{message} #{input}"
end
end
#
# In most cases I think it's better to do this:
#
parser = ConfigParser.new do |opts|
opts.separator "configurations"
opts.add Sample.configurations
opts.on "--help", "Print this help" do
puts "usage: sample INPUT"
puts
puts Sample::desc.wrap
puts
puts opts
exit(0)
end
end
parser.parse!(ARGV)
Sample.new(parser.config).execute(ARGV)
#
# I added functionality to do this, but I think I will remove it
# because, while it would be a little more compact it mixes the
# original use of parse! (to instantiate from a schema) with the
# use of Tasks here. It also adds to the parse! API, which I am
# eager to do.
#
# Maybe there is a way to set the banner correctly and in a
# general way. Perhaps that would be sufficient?
#
# Sample.parse!(ARGV) do |opts|
# opts.on! "--help", "Print this help" do
# puts "usage: sample INPUT"
# puts
# puts Sample::desc.wrap
# puts
# puts opts
# exit(0)
# end
# end.execute(ARGV)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment