Sha256: 1bdb5563ea815c3bac8aaf3fe05554fa664b25236222d047488c83c4d87b9f1b

Contents?: true

Size: 1.41 KB

Versions: 34

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require 'avm/registry'
require 'eac_cli/core_ext'

module Avm
  module SourceGenerators
    class Runner
      OPTION_NAME_VALUE_SEPARATOR = ':'

      runner_with :help do
        arg_opt '-o', '--option', 'Option for generator.', repeat: true, optional: true
        pos_arg :stereotype_name
        pos_arg :target_path
      end

      def run
        start_banner
        generate
      end

      def generate
        infom 'Generating...'
        generator.perform
        success "Source generated in \"#{generator.target_path}\""
      end

      # @return [String]
      def help_extra_text
        help_list_section('Stereotypes', ::Avm::Registry.source_generators.available
          .map(&:application_stereotype_name))
      end

      def start_banner
        infov 'Stereotype', stereotype_name
        infov 'Target path', target_path
        infov 'Generator', generator.class
      end

      def generator_uncached
        ::Avm::Registry.source_generators
          .detect_optional(stereotype_name, target_path, options) ||
          fatal_error("No generator found for stereotype \"#{stereotype_name}\"")
      end

      delegate :stereotype_name, to: :parsed

      # @return [Hash<String, String>]
      def options
        parsed.option.to_h { |v| v.split(OPTION_NAME_VALUE_SEPARATOR) }
      end

      def target_path
        parsed.target_path.to_pathname
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
avm-0.94.1 lib/avm/source_generators/runner.rb
eac_tools-0.98.0 sub/avm/lib/avm/source_generators/runner.rb
avm-0.94.0 lib/avm/source_generators/runner.rb
eac_tools-0.94.0 sub/avm/lib/avm/source_generators/runner.rb
avm-0.93.0 lib/avm/source_generators/runner.rb
eac_tools-0.92.0 sub/avm/lib/avm/source_generators/runner.rb
avm-0.92.0 lib/avm/source_generators/runner.rb
eac_tools-0.91.0 sub/avm/lib/avm/source_generators/runner.rb
avm-0.90.1 lib/avm/source_generators/runner.rb
eac_tools-0.87.1 sub/avm/lib/avm/source_generators/runner.rb
avm-0.90.0 lib/avm/source_generators/runner.rb
eac_tools-0.87.0 sub/avm/lib/avm/source_generators/runner.rb
avm-0.89.0 lib/avm/source_generators/runner.rb
eac_tools-0.86.12 sub/avm/lib/avm/source_generators/runner.rb
avm-0.88.0 lib/avm/source_generators/runner.rb
eac_tools-0.86.11 sub/avm/lib/avm/source_generators/runner.rb
avm-0.87.0 lib/avm/source_generators/runner.rb
eac_tools-0.86.8 sub/avm/lib/avm/source_generators/runner.rb
avm-0.86.2 lib/avm/source_generators/runner.rb
eac_tools-0.86.7 sub/avm/lib/avm/source_generators/runner.rb