Skip to content

Commit

Permalink
Add the console to easily create the module and types for dev.
Browse files Browse the repository at this point in the history
  • Loading branch information
tamdaz committed Jan 26, 2025
1 parent 462732a commit 5897d3b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/console.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "./crygen"

begin
command_name = ARGV[0]
if command_name
case command_name
when "make:module"
ARGV[1] ? make_module(ARGV[1]) : puts "Class name is required. Please retry."
when "make:type"
ARGV[1] ? make_type(ARGV[1]) : puts "Class name is required. Please retry."
else
puts "Command not found. Please retry."
exit 1
end
end
rescue IndexError
puts "No command specified. Please retry."
exit 1
end

def make_module(module_name : String) : Nil
module_type = CGT::Module.new("Crygen::Types::#{module_name}")
module_type.add_comment("TODO : Write the documentation about the `#{module_name}` class.")

path = __FILE__.gsub("console.cr", nil) + "modules/#{module_name.downcase.gsub(' ', '_')}.cr"

File.write(path, module_type.generate)
end

def make_type(class_name : String) : Nil
method_generate = CGT::Method.new("generate", "String")
method_generate.add_body("# Put the code...")
class_type = CGT::Class.new("Crygen::Types::#{class_name} < Crygen::Abstract::GeneratorInterface")
class_type.add_comment("TODO : Write the documentation about the `#{class_name}` class.")
class_type.add_method(method_generate)

path = __FILE__.gsub("console.cr", nil) + "types/#{class_name.downcase.gsub(' ', '_')}.cr"

File.write(path, class_type.generate)
end

0 comments on commit 5897d3b

Please sign in to comment.