Sha256: a58f0f0b671988ca10f575aa2757babbed29b228719fa28f126cc515c7b4842b

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 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

1 entries across 1 versions & 1 rubygems

Version Path
tocer-12.0.2 lib/tocer/cli/shell.rb