|
|
|
@@ -1,16 +1,20 @@
|
|
|
|
|
module CliGen
|
|
|
|
|
class Command
|
|
|
|
|
macro selection(variable, short, long, description, options)
|
|
|
|
|
macro selection(variable, description, options, short = nil, long = nil, validation = nil, on_match = nil)
|
|
|
|
|
{% raise "ERROR : CliGen::Command.selection : First selection must be a TypeDeclaration (ex: '<var> : <type> [= val]')" unless variable.is_a? TypeDeclaration %}
|
|
|
|
|
{% raise "ERROR : CliGen::Command.selection : Provided short must be a string" unless short.is_a? StringLiteral || string == nil %}
|
|
|
|
|
{% raise "ERROR : CliGen::Command.selection : Provided long must be a string" unless long.is_a? StringLiteral || long == nil %}
|
|
|
|
|
{% if short %}
|
|
|
|
|
{% raise "ERROR : CliGen::Command.selection : Provided short must be a string" unless short.is_a? StringLiteral %}
|
|
|
|
|
{% end %}
|
|
|
|
|
{% long = "--#{variable.var}" if long.nil? %}
|
|
|
|
|
{% raise "ERROR : CliGen::Command.selection : Provided long must be a flag format" unless long =~ /^--[a-zA-Z0-9-_]+/ %}
|
|
|
|
|
{% raise "ERROR : CliGen::Command.selection : Provided long must be a string" unless long.is_a? StringLiteral %}
|
|
|
|
|
{% 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.is_a? ArrayLiteral %}
|
|
|
|
|
{% raise "ERROR : CliGen::Command.selection : Provided options must be " unless options. %}
|
|
|
|
|
{% options = options.resolve if options.is_a? Path %}
|
|
|
|
|
{% raise "ERROR : CliGen::Command.selection : Provided options must be an ArrayLiteral" unless options.is_a? ArrayLiteral %}
|
|
|
|
|
|
|
|
|
|
@[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}}
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|