Help command as a univeral way to access help information. With help for other commands so far.

This commit is contained in:
Chris Eppstein 2009-10-04 15:58:05 -07:00
parent dedff936b8
commit 515cdb316e
4 changed files with 74 additions and 1 deletions

View File

@ -3,7 +3,7 @@ end
require 'compass/commands/registry' require 'compass/commands/registry'
%w(base generate_grid_background list_frameworks project_base %w(base generate_grid_background help list_frameworks project_base
update_project watch_project create_project installer_command 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}" require "compass/commands/#{lib}"

View File

@ -56,6 +56,14 @@ module Compass
option_parser([]).to_s option_parser([]).to_s
end end
def description(command)
if command.to_sym == :create
"Create a new compass project"
else
"Initialize an existing project"
end
end
def parse!(arguments) def parse!(arguments)
parser = option_parser(arguments) parser = option_parser(arguments)
parse_options!(parser, arguments) parse_options!(parser, arguments)

View File

@ -0,0 +1,62 @@
module Compass
module Commands
module HelpOptionsParser
def set_options(opts)
banner = %Q{Usage: compass help [command]
Description:
The Compass Stylesheet Authoring Framework helps you
build and maintain your stylesheets and makes it easy
for you to use stylesheet libraries provided by others.
To get help on a particular command please specify the command.
Available commands:
}
Compass::Commands.all.sort_by{|c| c.to_s}.each do |command|
banner << " * #{command}"
if Compass::Commands[command].respond_to? :description
banner << " - #{Compass::Commands[command].description(command)}"
end
banner << "\n"
end
opts.banner = banner
super
end
end
class Help < Base
register :help
class << self
def option_parser(arguments)
parser = Compass::Exec::CommandOptionParser.new(arguments)
parser.extend(HelpOptionsParser)
end
def usage
option_parser([]).to_s
end
def description(command)
"Get help on a compass command or extension"
end
def parse!(arguments)
parser = option_parser(arguments)
parser.parse!
parser.options[:help_command] = arguments.shift || 'help'
parser.options
end
end
def execute
if Compass::Commands.command_exists? options[:help_command]
$command = options[:help_command]
puts Compass::Commands[options[:help_command]].usage
$command = "help"
else
raise OptionParser::ParseError, "No such command: #{options[:help_command]}"
end
end
end
end
end

View File

@ -12,6 +12,9 @@ module Compass::Commands
@commands ||= Hash.new @commands ||= Hash.new
@commands.has_key?(name.to_sym) @commands.has_key?(name.to_sym)
end end
def all
@commands.keys
end
alias_method :[], :get alias_method :[], :get
alias_method :[]=, :register alias_method :[]=, :register
end end