[CLI] Enable command abbreviations.

This commit is contained in:
Chris Eppstein 2010-05-07 10:03:42 -07:00
parent a938f90fbc
commit 2c6028a163
2 changed files with 20 additions and 2 deletions

View File

@ -12,6 +12,11 @@ COMPASS CHANGELOG
* [Compass Core] The configuration constant `$firefox2-ellipsis` has been
renamed to `$use-mozilla-ellipsis-binding` to reflect the fact that
it must be used for any version of mozilla less than 3.6.
* [CLI] The the new Sub-command based CLI will now recognize abbreviated
commands as long as the abbreviation is unambiguous.
For instance, `compass w` is a shortcut for `compass watch` and
`compass com` for `compass compile` but `compas co` will not work
for compile because it also matches `compass config`.
0.10.0.rc5 (May 2, 2010)
------------------------

View File

@ -6,11 +6,24 @@ module Compass::Commands
end
def get(name)
@commands ||= Hash.new
@commands[name.to_sym]
@commands[name.to_sym] || @commands[abbreviation_of(name)]
end
def abbreviation_of(name)
re = /^#{Regexp.escape(name)}/
matching = @commands.keys.select{|k| k.to_s =~ re}
if matching.size == 1
matching.first
else
raise Compass::Error, "Ambiguous abbreviation '#{name}'. Did you mean one of: #{matching.join(", ")}"
end
end
def abbreviation?(name)
re = /^#{Regexp.escape(name)}/
@commands.keys.detect{|k| k.to_s =~ re}
end
def command_exists?(name)
@commands ||= Hash.new
name && @commands.has_key?(name.to_sym)
name && (@commands.has_key?(name.to_sym) || abbreviation?(name))
end
def all
@commands.keys