lib/cl/runner/default.rb in cl-1.0.5 vs lib/cl/runner/default.rb in cl-1.1.0
- old
+ new
@@ -6,11 +6,11 @@
module Runner
class Default
Runner.register :default, self
extend Forwardable
- include Merge
+ include Merge, Suggest
def_delegators :ctx, :abort
attr_reader :ctx, :const, :args, :opts
@@ -29,10 +29,15 @@
def help
Help.new(ctx, [cmd.registry_key])
end
+ def suggestions(args)
+ keys = args.inject([]) { |keys, arg| keys << [keys.last, arg].compact.join(':') }
+ keys.map { |key| suggest(providers.map(&:to_s), key) }.flatten
+ end
+
private
# Finds a command class to run for the given arguments.
#
# Stopping at any arg that starts with a dash, find the command
@@ -61,12 +66,16 @@
keys[0] << [Cmd[keys[1].join(':')], keys[1].dup] if Cmd.registered?(keys[1].join(':'))
keys
end
cmd, keys = keys[0].last
- cmd || raise(UnknownCmd.new(args))
+ raise UnknownCmd.new(self, args) unless cmd
keys.each { |key| args.delete_at(args.index(key)) }
[cmd, args]
end
+
+ def providers
+ Cmd.registry.keys
+ end
end
end
end