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
|
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.
Donating:
Compass is charityware. If you find it useful please make
a tax deductable donation: http://umdf.org/compass
To get help on a particular command please specify the command.
}
primary_commands = Compass::Commands.all.select do |c|
cmd = Compass::Commands[c]
cmd.respond_to?(:primary) && cmd.primary
end
other_commands = Compass::Commands.all - primary_commands
banner << command_list("Primary Commands:", primary_commands)
banner << command_list("Other Commands:", other_commands)
banner << "\nAvailable Frameworks & Patterns:\n\n"
banner << Compass::Frameworks.pretty_print
banner << "\nGlobal Options:\n"
opts.banner = banner
super
end
def command_list(header, commands)
list = "#{header}\n"
commands.sort_by{|c| c.to_s}.each do |command|
list << " * #{command}"
if Compass::Commands[command].respond_to? :description
list << "\t- #{Compass::Commands[command].description(command)}"
end
list << "\n"
end
list
end
end
class Help < Base
register :help
class << self
def option_parser(arguments)
parser = Compass::Exec::CommandOptionParser.new(arguments)
parser.extend(Compass::Exec::GlobalOptionsParser)
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"
elsif Compass::Frameworks.template_exists? options[:help_command]
puts Compass::Frameworks.template_usage(options[:help_command])
else
raise OptionParser::ParseError, "No such command: #{options[:help_command]}"
end
end
end
end
end
|