Sha256: ff8ae98359ac3e5ed1d3a5a7bbc764115fad5e5d6ed7ba1037b27a4626302e85

Contents?: true

Size: 875 Bytes

Versions: 6

Compression:

Stored size: 875 Bytes

Contents

# frozen_string_literal: true

require "hanami/cli"
require_relative "../snowpack"
require_relative "cli/command"
require_relative "cli/commands"

module Snowpack
  class ApplicationCLI < Hanami::CLI
    def self.application
      if Snowpack.application?
        Snowpack.application
      else
        nil
      end
    end

    attr_reader :application

    def initialize(application: self.class.application, 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)
        application.config.env = arguments[:env] if arguments[:env]
        [command.with_application(application), arguments]
      else
        [command, arguments]
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
snowpack-1.0.0.alpha7 lib/snowpack/application_cli.rb
snowpack-1.0.0.alpha6 lib/snowpack/application_cli.rb
snowpack-1.0.0.alpha5 lib/snowpack/application_cli.rb
snowpack-1.0.0.alpha4 lib/snowpack/application_cli.rb
snowpack-1.0.0.alpha3 lib/snowpack/application_cli.rb
snowpack-1.0.0.alpha2 lib/snowpack/application_cli.rb