Sha256: 1f51db6d4b23e6f37c8ef1218917df5dccee2c29c2ff518bd183fe19072f9db2

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Tocer
  module CLI
    # The main Command Line Interface (CLI) object.
    class Shell
      PROCESSORS = {
        config: Processors::Config.new,
        build: Processors::Build.new
      }.freeze

      def initialize parser: Parsers::Assembler.new, processors: PROCESSORS
        @parser = parser
        @processors = processors
      end

      def call arguments = []
        parse arguments

        case options
          in config: action then process_config action
          in build: path then process_build path
          in version: then puts version
          in help: then usage
          else usage
        end
      end

      private

      attr_reader :parser, :processors

      def parse arguments = []
        parser.call arguments
      rescue StandardError => error
        puts error.message
      end

      def process_config(action) = processors.fetch(:config).call(action)

      def process_build(path) = processors.fetch(:build).call(path, options)

      def options = parser.to_h

      def usage = puts(parser.to_s)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tocer-12.0.1 lib/tocer/cli/shell.rb
tocer-12.0.0 lib/tocer/cli/shell.rb