1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
module Compass
module Commands
module VersionOptionsParser
def set_options(opts)
opts.banner = %Q{Usage: compass version [options]
Options:
}
opts.on_tail("-?", "-h", "--help", "Print out this message.") do
puts opts
exit
end
opts.on("-q", "--quiet", "Just print the version string.") do
self.options[:quiet] = true
end
opts.on("--major", "Print the major version number") do
self.options[:major] = true
self.options[:custom] = true
end
opts.on("--minor", "Print up to the minor version number") do
self.options[:major] = true
self.options[:minor] = true
self.options[:custom] = true
end
opts.on("--patch", "Print up to the patch version number") do
self.options[:major] = true
self.options[:minor] = true
self.options[:patch] = true
self.options[:custom] = true
end
opts.on("--revision", "Include the source control revision") do
self.options[:revision] = true
self.options[:custom] = true
end
end
end
class PrintVersion < Base
register :version
class << self
def option_parser(arguments)
parser = Compass::Exec::CommandOptionParser.new(arguments)
parser.extend(VersionOptionsParser)
end
def usage
option_parser([]).to_s
end
def description(command)
"Print out version information"
end
def parse!(arguments)
parser = option_parser(arguments)
parser.parse!
parser.options
end
def long_output_string
lines = []
lines << "Compass #{::Compass.version[:string]}"
if name = ::Compass.version[:name]
lines.last << " (#{name})"
end
lines << "Copyright (c) 2008-#{Time.now.year} Chris Eppstein"
lines << "Released under the MIT License."
lines << "Compass is charityware."
lines << "Please make a tax deductable donation for a worthy cause: http://umdf.org/compass"
lines.join("\n")
end
end
attr_accessor :options
def initialize(working_path, options)
self.options = options
end
def execute
if options[:custom]
version = ""
version << "#{Compass.version[:major]}" if options[:major]
version << ".#{Compass.version[:minor]}" if options[:minor]
version << ".#{Compass.version[:teeny]}" if options[:patch]
if options[:revision]
if version.size > 0
version << " [#{Compass.version[:rev][0..6]}]"
else
version << Compass.version[:rev]
end
end
puts version
elsif options[:quiet]
puts ::Compass.version[:string]
else
puts self.class.long_output_string
end
end
end
end
end
|