Sha256: dc7410736dcacbde20e35fcc4d3cfb0ab57cd25f2c284311a3187d1793771b81

Contents?: true

Size: 1017 Bytes

Versions: 4

Compression:

Stored size: 1017 Bytes

Contents

# frozen_string_literal: true

require "hanami/cli"
require_relative "commands"

module Hanami
  class CLI
    module Application
      # Hanami application CLI
      class CLI < Hanami::CLI
        attr_reader :application

        def initialize(application: nil, commands: Commands)
          super(commands)
          @application = application
        end

        private

        # TODO: we should make a prepare_command method upstream
        def parse(result, out)
          command, arguments = super

          if command.respond_to?(:with_application)
            # Set HANAMI_ENV before the application inits to ensure all aspects
            # of the boot process respect the provided env
            ENV["HANAMI_ENV"] = arguments[:env] if arguments[:env]

            require "hanami/init"
            application = Hanami.application

            [command.with_application(application), arguments]
          else
            [command, arguments]
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hanami-2.0.0.alpha5 lib/hanami/cli/application/cli.rb
hanami-2.0.0.alpha4 lib/hanami/cli/application/cli.rb
hanami-2.0.0.alpha3 lib/hanami/cli/application/cli.rb
hanami-2.0.0.alpha2 lib/hanami/cli/application/cli.rb