diff --git a/src/cligen/command/argument.cr b/src/cligen/command/argument.cr index fe5b18f..d5734da 100644 --- a/src/cligen/command/argument.cr +++ b/src/cligen/command/argument.cr @@ -1,6 +1,6 @@ module CliGen class Command - macro argument(variable, description, long = nil, short = nil, validation = nil, on_match = nil, def_setter = false, options = nil) + macro argument(variable, description, long = nil, short = nil, validation = nil, on_match = nil, def_setter = false, def_getter = false, options = nil) {% raise "ERROR : CliGen::Command.argument : def_setter must be a Bool" unless def_setter.is_a? BoolLiteral %} {% raise "ERROR : CliGen::Command.argument : First argument (#{variable}) must be a TypeDeclaration (ex: ' : [= val]')" unless variable.is_a? TypeDeclaration %} {% name = variable.var %} @@ -40,6 +40,12 @@ module CliGen @[CliGen::Argument(short: {{short}}, long: {{long}}, description: {{description}}, validation: {{validation}}, on_match: {{on_match}}, options: {{options}})] @{{variable}} + {% if def_getter %} + def {{variable.var}} + @{{name}} + end + {% end %} + {% if def_setter %} def {{variable.var}}= (value : {{type}}) {% unless validation.nil? %}