From 333bf612e27ca55af9b6ba034c8518cbfbdc26a2 Mon Sep 17 00:00:00 2001 From: Alexandre Podlewski Date: Tue, 13 Feb 2024 15:14:32 +0100 Subject: [PATCH 01/38] Implement new templating system to provide more customization of templates --- lib/ccios.rb | 116 ++++++++++++++--------- lib/ccios/argument_template_parameter.rb | 12 +++ lib/ccios/code_templater.rb | 32 +++++-- lib/ccios/coordinator_generator.rb | 18 ---- lib/ccios/file_creator.rb | 41 ++++---- lib/ccios/file_template_definition.rb | 66 +++++++++++++ lib/ccios/flag_template_parameter.rb | 13 +++ lib/ccios/group_template_definition.rb | 46 +++++++++ lib/ccios/interactor_generator.rb | 33 ------- lib/ccios/pbxproj_parser.rb | 57 +---------- lib/ccios/presenter_generator.rb | 71 -------------- lib/ccios/repository_generator.rb | 44 --------- lib/ccios/snippet_template_definition.rb | 27 ++++++ lib/ccios/template_definition.rb | 98 +++++++++++++++++++ 14 files changed, 382 insertions(+), 292 deletions(-) create mode 100644 lib/ccios/argument_template_parameter.rb delete mode 100644 lib/ccios/coordinator_generator.rb create mode 100644 lib/ccios/file_template_definition.rb create mode 100644 lib/ccios/flag_template_parameter.rb create mode 100644 lib/ccios/group_template_definition.rb delete mode 100644 lib/ccios/interactor_generator.rb delete mode 100644 lib/ccios/presenter_generator.rb delete mode 100644 lib/ccios/repository_generator.rb create mode 100644 lib/ccios/snippet_template_definition.rb create mode 100644 lib/ccios/template_definition.rb diff --git a/lib/ccios.rb b/lib/ccios.rb index 0f4174c..28cacf5 100644 --- a/lib/ccios.rb +++ b/lib/ccios.rb @@ -2,67 +2,97 @@ require 'xcodeproj' require 'optparse' require 'active_support' -require 'ccios/presenter_generator' -require 'ccios/coordinator_generator' -require 'ccios/interactor_generator' -require 'ccios/repository_generator' require 'ccios/config' +require 'ccios/template_definition' + +config = Config.parse ".ccios.yml" +source_path = Dir.pwd + +default_template_folder = File.join(File.dirname(__FILE__), "ccios", "templates") +default_templates = Dir.children(default_template_folder) + .map { |name| File.join(default_template_folder, name) } + .select { |path| File.directory? path } + .map { |template_path| TemplateDefinition.parse(template_path) } + .compact + +templates = {} +subcommands = {} options = {} -OptionParser.new do |opts| - opts.banner = "Usage: ccios [options]" + +default_templates.each do |template| + templates[template.name] = template + subcommands[template.name] = OptionParser.new do |opts| + + arguments = template.parameters.select { |p| p.is_a?(ArgumentTemplateParameter) } + flags = template.parameters.select { |p| p.is_a?(FlagTemplateParameter) } + + arguments_line = arguments.map { |argument| "<#{argument.name}>" }.join(" ") + + opts.banner = "Usage: ccios #{template.name} [options]" + + flags.each do |flagParameter| + if flagParameter.short_name != nil + opts.on("-#{flagParameter.short_name}", "--#{flagParameter.name}", flagParameter.description) do |v| + options[flagParameter.template_variable_name] = v + end + else + opts.on("--#{flagParameter.name}", flagParameter.description) do |v| + options[flagParameter.template_variable_name] = v + end + end + end + end +end + +global_cli = OptionParser.new do |opts| + opts.banner = "Usage: ccios