Sha256: 6a89f0ef43cb1d72be9ebf44860bf05a655acee903b793d52eb920f0dd87fe6e

Contents?: true

Size: 1020 Bytes

Versions: 4

Compression:

Stored size: 1020 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/prepare"
            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.alpha8 lib/hanami/cli/application/cli.rb
hanami-2.0.0.alpha7.1 lib/hanami/cli/application/cli.rb
hanami-2.0.0.alpha7 lib/hanami/cli/application/cli.rb
hanami-2.0.0.alpha6 lib/hanami/cli/application/cli.rb