Sha256: eb9bc4bab808e37e987670d0203a24f72046c0fc0538d591210a56520f16ce6f

Contents?: true

Size: 856 Bytes

Versions: 3

Compression:

Stored size: 856 Bytes

Contents

# encoding: UTF-8
require 'simulacrum/cli/parser'

module Simulacrum
  # Command-line interface for driving Simulacrum
  module CLI
    def execute!(argv)
      Command.new(argv).run_and_exit
    end
    module_function :execute!

    # Class for wrappin up logic for running the process and handling exit
    class Command
      def initialize(argv, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = Kernel)
        @argv, @stdin, @stdout, @stderr, @kernel = argv, stdin, stdout, stderr, kernel
      end

      def run_and_exit
        @exit_code = run
        @kernel.exit(@exit_code)
      end

      private

      def run
        if parsed_argv == true
          0
        else
          Simulacrum.run(parsed_argv)
        end
      end

      def parsed_argv
        @parsed_argv ||= CLI::Parser.parse(@argv)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
simulacrum-0.3.2 lib/simulacrum/cli.rb
simulacrum-0.3.1 lib/simulacrum/cli.rb
simulacrum-0.3.0 lib/simulacrum/cli.rb