Added def_getter

This commit is contained in:
Tristan Ancelet
2026-08-12 11:00:56 -05:00
parent ea8ca62a63
commit 976ed10f75
+7 -1
View File
@@ -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: '<var> : <type> [= 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? %}