Added options
This commit is contained in:
@@ -28,7 +28,8 @@ module CliGen
|
||||
description: {{ anno[:description] }},
|
||||
default: {% unless var.default_value.nil? %} {{var.default_value}} {% else %} nil {% end %},
|
||||
validate: {% if anno[:validation] %} {{anno[:validation]}} {% else %} nil {% end %},
|
||||
on_match: {% if anno[:on_match] %} {{anno[:on_match]}} {% else %} nil {% end %}
|
||||
on_match: {% if anno[:on_match] %} {{anno[:on_match]}} {% else %} nil {% end %},
|
||||
options: {% if anno[:options] %} {{anno[:options]}} {% else %} nil {% end %}
|
||||
)
|
||||
{% debug if env("DEBUG") %}
|
||||
{% end %}
|
||||
|
||||
@@ -1,17 +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 %}
|
||||
{% options = options.resolve if options.is_a? Path %}
|
||||
{% raise "ERROR : CliGen::Command.selection : Provided options must be an ArrayLiteral" unless options.is_a? ArrayLiteral %}
|
||||
{% raise "ERROR : CliGen::Command.selection : Provided options must be of the same type as the variable" unless options.of == variable.type %}
|
||||
|
||||
@[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
|
||||
|
||||
Reference in New Issue
Block a user