[Command Line] Primary commands get special status in the initial help output.

This commit is contained in:
Chris Eppstein 2009-11-15 12:28:03 -08:00
parent 46ccb5b6e1
commit a281dc1d5f
6 changed files with 63 additions and 18 deletions

View File

@ -129,16 +129,23 @@ Feature: Command Line
And an image file images/buttons/tick.png is created
And a css file tmp/buttons.css is created
@now
Scenario: Basic help
When I run: compass help
Then I should be shown a list of available commands
And the list of commands should describe the compile command
And the list of commands should describe the create command
And the list of commands should describe the grid-img command
And the list of commands should describe the help command
And the list of commands should describe the init command
And the list of commands should describe the install command
And the list of commands should describe the version command
Then I should see the following "primary" commands:
| compile |
| create |
| init |
| watch |
And I should see the following "other" commands:
| config |
| grid-img |
| help |
| install |
| interactive |
| stats |
| validate |
| version |
Scenario: Recompiling a project with no material changes
Given I am using the existing project in test/fixtures/stylesheets/compass

View File

@ -160,8 +160,21 @@ Then /^I am told how to compile my sass stylesheets$/ do
@last_result.should =~ /You must compile your sass stylesheets into CSS when they change.\nThis can be done in one of the following ways:/
end
Then /^I should be shown a list of available commands$/ do
@last_result.should =~ /^Available commands:$/
Then /^I should be shown a list of "([^"]+)" commands$/ do |kind|
@last_result.should =~ /^#{kind.capitalize} Commands:$/
@last_command_list = []
found = false
indent = nil
@last_result.split("\n").each do |line|
if line =~ /^#{kind.capitalize} Commands:$/
found = true
elsif found && line =~ /^\s+/
@last_command_list << line
elsif found && line =~ /^$|^\w/
break
end
end
end
Then /^the list of commands should describe the ([^ ]+) command$/ do |command|
@ -196,4 +209,11 @@ Then /^I am told statistics for each file:$/ do |table|
end
end
Then /^I should see the following "([^"]+)" commands:$/ do |kind, table|
Then %Q{I should be shown a list of "#{kind}" commands}
commands = @last_command_list.map{|c| c =~ /^\s+\* ([^ ]+)\s+- [A-Z].+$/; [$1]}
table.diff!(commands)
end

View File

@ -68,6 +68,8 @@ module Compass
end
end
def primary; true; end
def parse!(arguments)
parser = option_parser(arguments)
parse_options!(parser, arguments)

View File

@ -11,16 +11,16 @@ Description:
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 << "\t- #{Compass::Commands[command].description(command)}"
end
banner << "\n"
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"
Compass::Frameworks::ALL.each do |framework|
@ -38,6 +38,18 @@ Available commands:
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

View File

@ -136,6 +136,8 @@ module Compass
"Report statistics about your stylesheets"
end
def primary; false; end
def parse!(arguments)
parser = option_parser(arguments)
parser.parse!

View File

@ -62,6 +62,8 @@ module Compass
option_parser([]).to_s
end
def primary; true; end
def description(command)
"Compile Sass stylesheets to CSS"
end