added def_init
This commit is contained in:
@@ -6,12 +6,18 @@ require "./command/argument"
|
|||||||
require "./command/selection"
|
require "./command/selection"
|
||||||
require "./command/help_template"
|
require "./command/help_template"
|
||||||
require "./command/subcommand"
|
require "./command/subcommand"
|
||||||
|
require "./command/def_init"
|
||||||
|
|
||||||
module CliGen
|
module CliGen
|
||||||
class Command
|
class Command
|
||||||
macro inherited
|
macro inherited
|
||||||
{% verbatim do %}
|
{% verbatim do %}
|
||||||
macro finished
|
macro finished
|
||||||
|
{% anno = @type.annotation(CliGen::CommandInfo) %}
|
||||||
|
{% raise "" unless anno %}
|
||||||
|
{% if anno[:def_init] %}
|
||||||
|
def_init
|
||||||
|
{% end %}
|
||||||
def initialize(*, handler : CliGen::BaseCommandNode)
|
def initialize(*, handler : CliGen::BaseCommandNode)
|
||||||
{% verbatim do %}
|
{% verbatim do %}
|
||||||
{% for var in @type.instance_vars %}
|
{% for var in @type.instance_vars %}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
module CliGen
|
||||||
|
class Command
|
||||||
|
macro def_init
|
||||||
|
def initialize
|
||||||
|
{% verbatim do %}
|
||||||
|
{% for var in @type.instance_vars %}
|
||||||
|
{% raise "ERROR : Can't define a default initializer if #{var.name} doesn't have a default" if var.default_value.nil? && !var.type.nilable? %}
|
||||||
|
@{{var.name}} = {{var.default_value}}
|
||||||
|
{% end %}
|
||||||
|
{% end %}
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_initialize
|
||||||
|
@@instance = self
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.get
|
||||||
|
@@instance ||= new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user