#!/usr/bin/env ruby # # Created on 2008-3-11. # Copyright (c) 2008. All rights reserved. begin require 'rubygems' rescue LoadError # no rubygems to load, so we fail silently end require 'optparse' # NOTE: the option -p/--path= is given as an example, and should probably be replaced in your application. OPTIONS = {} MANDATORY_OPTIONS = %w( path ) parser = OptionParser.new do |opts| opts.banner = < #{File.basename($0)} [options] Options are: BANNER opts.separator "" opts.on("-s", "--script=PATH", String, "Path to a sprinkle script to run") { |OPTIONS[:path]| } opts.on("-t", "--test", "Process but don't perform any actions") { |OPTIONS[:testing]| } opts.on("-v", "--verbose", "Verbose output") { |OPTIONS[:verbose]| } opts.on("-c", "--cloud", "Show powder cloud, ie. package hierarchy and installation order") { |OPTIONS[:cloud]| } opts.on("-h", "--help", "Show this help message.") { puts opts; exit } opts.parse!(ARGV) if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? } puts opts; exit end end def operation_mode(options) Sprinkle::OPTIONS[:testing] = OPTIONS[:testing] || false end def powder_cloud(options) Sprinkle::OPTIONS[:cloud] = OPTIONS[:cloud] || false end def log_level(options) Object.logger.level = ActiveSupport::BufferedLogger::Severity::DEBUG if options[:verbose] end require 'sprinkle' powder = OPTIONS[:path] raise "Sprinkle script is not readable: #{powder}" unless File.readable?(powder) operation_mode(OPTIONS) powder_cloud(OPTIONS) log_level(OPTIONS) Sprinkle::Script.sprinkle File.read(powder), powder