From afd7ba7c7bd6a6668b923fe25b4a2bdb7934dc16 Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Tue, 11 Aug 2026 11:53:38 -0500 Subject: [PATCH] Added options to Command.argument macro --- src/cligen/command/argument.cr | 8 ++++++-- src/cligen/command/selection.cr | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/cligen/command/argument.cr b/src/cligen/command/argument.cr index 6879f67..c602dd1 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) + macro argument(variable, description, long = nil, short = nil, validation = nil, on_match = nil, def_setter = 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 %} @@ -32,8 +32,12 @@ module CliGen {% raise "ERROR : CliGen::Command.argument(#{name}) : Provided validation input value must be #{type}. EX: #{example}" %} {% end %} {% end %} + {% if options %} + {% options = options.resolve if options.is_a? Path %} + {% raise "ERROR : CliGen::Command.argument(#{name}) : Provided options must be an ArrayLiteral" unless options.is_a? ArrayLiteral %} + {% end %} - @[CliGen::Argument(short: {{short}}, long: {{long}}, description: {{description}}, validation: {{validation}}, on_match: {{on_match}})] + @[CliGen::Argument(short: {{short}}, long: {{long}}, description: {{description}}, validation: {{validation}}, on_match: {{on_match}}, options: {{options}})] @{{variable}} {% if def_setter %} diff --git a/src/cligen/command/selection.cr b/src/cligen/command/selection.cr index 14cb4d2..6001413 100644 --- a/src/cligen/command/selection.cr +++ b/src/cligen/command/selection.cr @@ -7,8 +7,11 @@ module CliGen {% raise "ERROR : CliGen::Command.selection : You must provide a short or long" unless long || short %} {% raise "ERROR : CliGen::Command.selection : You must provide a description" unless description %} {% raise "ERROR : CliGen::Command.selection : Provided description must be a String" unless description.is_a? StringLiteral %} - {% raise "ERROR : CliGen::Command.selection : You must provide options" unless options %} - {% raise "ERROR : CliGen::Command.selection : Provided options must be " unless options %} + {% raise "ERROR : CliGen::Command.selection : You must provide options" unless options.is_a? ArrayLiteral %} + {% raise "ERROR : CliGen::Command.selection : Provided options must be " unless options. %} + + @[CliGen::Argument(short: {{short}}, long: {{long}}, description: {{description}}, validation: {{validation}}, on_match: {{on_match}})] + @{{variable}} end end end