Sha256: 316c81d9c58f676ab862a43e2bb3810a5965dc466f335a0db15fff3bfcd6f6f7

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

<% namespace do %>
  module CLI
    # The main Command Line Interface (CLI) object.
    class Shell
      ACTIONS = {config: Actions::Config.new}.freeze

      def initialize parser: Parser.new, actions: ACTIONS, container: Container
        @parser = parser
        @actions = actions
        @container = container
      end

      def call arguments = []
        perform parser.call(arguments)
      rescue OptionParser::ParseError => error
        logger.error { error.message }
      end

      private

      attr_reader :parser, :actions, :container

      def perform configuration
        case configuration
          in action_config: Symbol => action then config action
          in action_version: true then logger.info { "<%= configuration.project_label %> <%= configuration.project_version %>" }
          else usage
        end
      end

      def config(action) = actions.fetch(__method__).call(action)

      def usage = logger.unknown(parser.to_s)

      def logger = container[__method__]
    end
  end
<% end %>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gemsmith-16.0.0 lib/gemsmith/templates/%project_name%/lib/%project_path%/cli/shell.rb.erb