[CLI] Enable command abbreviations.
This commit is contained in:
parent
a938f90fbc
commit
2c6028a163
@ -12,6 +12,11 @@ COMPASS CHANGELOG
|
|||||||
* [Compass Core] The configuration constant `$firefox2-ellipsis` has been
|
* [Compass Core] The configuration constant `$firefox2-ellipsis` has been
|
||||||
renamed to `$use-mozilla-ellipsis-binding` to reflect the fact that
|
renamed to `$use-mozilla-ellipsis-binding` to reflect the fact that
|
||||||
it must be used for any version of mozilla less than 3.6.
|
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)
|
0.10.0.rc5 (May 2, 2010)
|
||||||
------------------------
|
------------------------
|
||||||
|
@ -6,11 +6,24 @@ module Compass::Commands
|
|||||||
end
|
end
|
||||||
def get(name)
|
def get(name)
|
||||||
@commands ||= Hash.new
|
@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
|
end
|
||||||
def command_exists?(name)
|
def command_exists?(name)
|
||||||
@commands ||= Hash.new
|
@commands ||= Hash.new
|
||||||
name && @commands.has_key?(name.to_sym)
|
name && (@commands.has_key?(name.to_sym) || abbreviation?(name))
|
||||||
end
|
end
|
||||||
def all
|
def all
|
||||||
@commands.keys
|
@commands.keys
|
||||||
|
Loading…
Reference in New Issue
Block a user