Missing argument(s) errors fixed. CMD: Methods -> Variables.
This commit is contained in:
parent
41940d3f10
commit
10061b1918
|
@ -7,6 +7,12 @@ class DenCli::CMD
|
|||
def initialize parent, name, description, exe
|
||||
raise "Proc expected, instead of: #{exe.inspect}" unless Proc === exe
|
||||
@parent, @name, @description, @exe = parent, name, description, lambda( &exe)
|
||||
@parameters = @exe.parameters
|
||||
@arguments_required = @exe.parameters.select {|e| :req == e[0] }.map {|e| e[1] }
|
||||
@arguments_additional = @exe.parameters.select {|e| :opt == e[0] }.map {|e| e[1] }
|
||||
@arguments = @exe.parameters.select {|e| :req == e[0] or :opt == e[0] }.map {|e| e[1] }
|
||||
@options_required = @exe.parameters.select {|e| :keyreq == e[0] }.map {|e| e[1] }
|
||||
@options_additional = @exe.parameters.select {|e| :key == e[0] }.map {|e| e[1] }
|
||||
@options = {}
|
||||
completion {|*a| [] }
|
||||
end
|
||||
|
@ -14,14 +20,11 @@ class DenCli::CMD
|
|||
def _full_cmd( post) parent._full_cmd [@name]+post end
|
||||
def full_cmd() _full_cmd [] end
|
||||
|
||||
def parameters() @exe.parameters end
|
||||
def arguments_required() @exe.parameters.select {|e| :req == e[0] }.map {|e| e[1] } end
|
||||
attr_reader :parameters,
|
||||
:arguments_required, :arguments_additional, :arguments,
|
||||
:options_required, :options_additional
|
||||
alias required arguments_required
|
||||
def arguments_additional() @exe.parameters.select {|e| :opt == e[0] }.map {|e| e[1] } end
|
||||
alias additional arguments_additional
|
||||
def arguments() @exe.parameters.select {|e| :req == e[0] or :opt == e[0] }.map {|e| e[1] } end
|
||||
def options_required() @exe.parameters.select {|e| :keyreq == e[0] }.map {|e| e[1] } end
|
||||
def options_additional() @exe.parameters.select {|e| :key == e[0] }.map {|e| e[1] } end
|
||||
|
||||
def complete *pre, str
|
||||
@completion.call *pre, str
|
||||
|
@ -54,7 +57,7 @@ class DenCli::CMD
|
|||
end
|
||||
kr = @options.select {|_, o| o.required? and not os.has_key? o.name }
|
||||
unless kr.empty?
|
||||
raise DenCli::UsageError, "Missing argument(s): #{kr.map {|o| o.long || o.short }.join ', '}"
|
||||
raise DenCli::UsageError, "Missing argument(s): #{kr.map {|_, o| o.long || o.short }.join ', '}"
|
||||
end
|
||||
end
|
||||
@exe.call *as, **os
|
||||
|
|
Loading…
Reference in a new issue