Version subcommand.

This commit is contained in:
Chris Eppstein 2009-10-04 22:17:56 -07:00
parent 515cdb316e
commit b8d380d68c
2 changed files with 74 additions and 5 deletions

View File

@ -5,6 +5,7 @@ require 'compass/commands/registry'
%w(base generate_grid_background help list_frameworks project_base
update_project watch_project create_project installer_command
print_version stamp_pattern validate_project write_configuration).each do |lib|
print_version stamp_pattern validate_project
write_configuration).each do |lib|
require "compass/commands/#{lib}"
end

View File

@ -1,14 +1,82 @@
module Compass
module Commands
class PrintVersion
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
end
attr_accessor :options
def initialize(working_path, options)
self.options = options
end
def execute
if options[:quiet]
# The quiet option may make scripting easier
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
lines = []