Changing to cligen
This commit is contained in:
@@ -3,7 +3,7 @@ require "time"
|
||||
|
||||
require "./command/parser"
|
||||
|
||||
module CliGenerator
|
||||
module CliGen
|
||||
|
||||
annotation CommandPreRun
|
||||
end
|
||||
@@ -19,7 +19,7 @@ module CliGenerator
|
||||
|
||||
|
||||
class Command
|
||||
extend CliGenerator::Parser
|
||||
extend CliGen::Parser
|
||||
|
||||
@@action : String = ""
|
||||
|
||||
@@ -33,12 +33,12 @@ module CliGenerator
|
||||
end
|
||||
|
||||
macro define_actions
|
||||
ACTIONS = {{@type.class.methods.select(&.annotation(::CliGenerator::SubCommand)).map(&.name.stringify)}} of String
|
||||
ACTIONS = {{@type.class.methods.select(&.annotation(::CliGen::SubCommand)).map(&.name.stringify)}} of String
|
||||
end
|
||||
|
||||
macro define_header
|
||||
{% name = @type.name.split("::").last.downcase.id %}
|
||||
{% info_annos = @type.class.methods.select(&.annotation(::CliGenerator::SubCommand)).map(&.annotation(::CliGenerator::SubCommand)) %}
|
||||
{% info_annos = @type.class.methods.select(&.annotation(::CliGen::SubCommand)).map(&.annotation(::CliGen::SubCommand)) %}
|
||||
{% examples = [] of StringLiteral %}
|
||||
{% info_annos.select(&.[](:examples)).map(&.[](:examples).resolve).each(&.each{|example| examples << example}) %}
|
||||
HEADER = [
|
||||
@@ -78,7 +78,7 @@ module CliGenerator
|
||||
end
|
||||
{% end %}
|
||||
|
||||
@[::CliGenerator::CommandArgument(type: {{type}}, short: {{short}}, long: {{long}}, description: {{description}})]
|
||||
@[::CliGen::CommandArgument(type: {{type}}, short: {{short}}, long: {{long}}, description: {{description}})]
|
||||
def self.{{arg_name}}(var : String) : Nil
|
||||
{% if check %}
|
||||
## If the check exists go ahead and call it
|
||||
@@ -94,14 +94,14 @@ module CliGenerator
|
||||
{% end %}
|
||||
{% if _type == "Time" %}
|
||||
formats = [
|
||||
CliGenerator::Regex::INPUT_DATETIME_REGEX,
|
||||
CliGenerator::Regex::INPUT_DATE_REGEX
|
||||
CliGen::Regex::INPUT_DATETIME_REGEX,
|
||||
CliGen::Regex::INPUT_DATE_REGEX
|
||||
]
|
||||
abort "ERROR : Command : {{arg_name}} : Incorrect format for provided data #{var}" unless formats.any?{|f| var.match(f)}
|
||||
if var =~ formats[0]
|
||||
@@{{variable}} = Time.parse_local(var, CliGenerator::Format::INPUT_DATETIME_FORMAT)
|
||||
@@{{variable}} = Time.parse_local(var, CliGen::Format::INPUT_DATETIME_FORMAT)
|
||||
elsif var =~ formats[1]
|
||||
@@{{variable}} = Time.parse_local(var, CliGenerator::Format::INPUT_DATE_FORMAT)
|
||||
@@{{variable}} = Time.parse_local(var, CliGen::Format::INPUT_DATE_FORMAT)
|
||||
end
|
||||
{% elsif _type == "Array" %}
|
||||
{% if _subtype == "Int32" %}
|
||||
@@ -123,7 +123,7 @@ module CliGenerator
|
||||
|
||||
macro define_runner
|
||||
def self.run
|
||||
{% pre_run_commands = @type.class.methods.select(&.annotation(::CliGenerator::CommandPreRun)) %}
|
||||
{% pre_run_commands = @type.class.methods.select(&.annotation(::CliGen::CommandPreRun)) %}
|
||||
{% unless pre_run_commands.empty? %}
|
||||
## Ensuring that all runs that are tagged with the the CommandPreRun annotation are run
|
||||
{% for method in pre_run_commands %}
|
||||
@@ -131,7 +131,7 @@ module CliGenerator
|
||||
{% end %}
|
||||
{% end %}
|
||||
|
||||
{% methods = @type.class.methods.select(&.annotation(::CliGenerator::SubCommand)) %}
|
||||
{% methods = @type.class.methods.select(&.annotation(::CliGen::SubCommand)) %}
|
||||
{% raise "ERROR : No commands defined for #{@type.name}" if methods.empty? %}
|
||||
{% begin %}
|
||||
case @@action
|
||||
|
||||
Reference in New Issue
Block a user