piotrmurach/tty

View on GitHub
lib/tty/templates/add/command.rb.tt

Summary

Maintainability
Test Coverage
# frozen_string_literal: true

require_relative "<%= cmd_file_path %>"

<%- app_constantinized_parts.each_with_index do |const, i| -%>
<%= "  " * i %>module <%= const %>
<%- end -%>
<%= app_indent %>module Commands
<%- cmd_constantinized_parts.each_with_index do |const, i| -%>
<%- if cmd_constantinized_parts.size == (i + 1) -%>
<%= app_indent %><%= "  " * i %>  class <%= const %> < <%= app_constantinized_parts.join("::") %>::Command
<%- else -%>
<%= app_indent %><%= "  " * i %>  class <%= const %>
<%- end -%>
<%- end -%>
<%= app_indent %><%= cmd_indent %>  def initialize(<%= cmd_options.join(", ") %>)
                     <%- cmd_options.each do |option| -%>
<%= app_indent %><%= cmd_indent %>    <%= "@#{option} = #{option}" %>
                     <%- end -%>
<%= app_indent %><%= cmd_indent %>  end

<%= app_indent %><%= cmd_indent %>  def execute(input: $stdin, output: $stdout)
<%= app_indent %><%= cmd_indent %>    # Command logic goes here ...
<%= app_indent %><%= cmd_indent %>    output.puts "OK"
<%= app_indent %><%= cmd_indent %>  end
<%- (cmd_constantinized_parts.size).downto(1) do |i| -%>
<%= app_indent + ("  " * i) %>end
<%- end -%>
<%- (app_constantinized_parts.size).downto(0) do |i| -%>
<%= "  " * i %>end
<%- end -%>