Missing argument(s) errors fixed. CMD: Methods -> Variables.

This commit is contained in:
Denis Knauf 2021-12-08 00:08:47 +01:00
parent 41940d3f10
commit 10061b1918

View file

@ -7,6 +7,12 @@ class DenCli::CMD
def initialize parent, name, description, exe def initialize parent, name, description, exe
raise "Proc expected, instead of: #{exe.inspect}" unless Proc === exe raise "Proc expected, instead of: #{exe.inspect}" unless Proc === exe
@parent, @name, @description, @exe = parent, name, description, lambda( &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 = {} @options = {}
completion {|*a| [] } completion {|*a| [] }
end end
@ -14,14 +20,11 @@ class DenCli::CMD
def _full_cmd( post) parent._full_cmd [@name]+post end def _full_cmd( post) parent._full_cmd [@name]+post end
def full_cmd() _full_cmd [] end def full_cmd() _full_cmd [] end
def parameters() @exe.parameters end attr_reader :parameters,
def arguments_required() @exe.parameters.select {|e| :req == e[0] }.map {|e| e[1] } end :arguments_required, :arguments_additional, :arguments,
:options_required, :options_additional
alias required arguments_required alias required arguments_required
def arguments_additional() @exe.parameters.select {|e| :opt == e[0] }.map {|e| e[1] } end
alias additional arguments_additional 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 def complete *pre, str
@completion.call *pre, str @completion.call *pre, str
@ -54,7 +57,7 @@ class DenCli::CMD
end end
kr = @options.select {|_, o| o.required? and not os.has_key? o.name } kr = @options.select {|_, o| o.required? and not os.has_key? o.name }
unless kr.empty? 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
end end
@exe.call *as, **os @exe.call *as, **os