Sha256: 3fbb0c33def2e4bd09e6c9f01a5382f5f5ca65ce0363b76f8dbc44ef6c54e372

Contents?: true

Size: 1.31 KB

Versions: 16

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

module Hanami
  module CLI
    # Returns true if the CLI is being called from inside an Hanami app.
    #
    # This is typically used to determine whether to register commands that are applicable either
    # inside or outside an app.
    #
    # @return [Boolean]
    #
    # @api private
    # @since 2.0.0
    def self.within_hanami_app?
      require "hanami"

      !!Hanami.app_path
    rescue LoadError => e
      raise e unless e.path == "hanami"

      # If for any reason the hanami gem isn't installed, make a simple best effort to determine
      # whether we're inside an app.
      File.exist?("config/app.rb") || File.exist?("app.rb")
    end

    # Contains the commands available for the current `hanami` CLI execution, depending on whether
    # the CLI is executed inside or outside an Hanami app.
    #
    # @see .within_hanami_app?
    #
    # @api public
    # @since 2.0.0
    module Commands
    end

    # @api private
    def self.register_commands!(within_hanami_app = within_hanami_app?)
      commands = if within_hanami_app
                   require_relative "commands/app"
                   Commands::App
                 else
                   require_relative "commands/gem"
                   Commands::Gem
                 end

      extend(commands)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
hanami-cli-2.2.1 lib/hanami/cli/commands.rb
hanami-cli-2.2.0 lib/hanami/cli/commands.rb
hanami-cli-2.2.0.rc1 lib/hanami/cli/commands.rb
hanami-cli-2.2.0.beta2 lib/hanami/cli/commands.rb
hanami-cli-2.2.0.beta1 lib/hanami/cli/commands.rb
hanami-cli-2.1.1 lib/hanami/cli/commands.rb
hanami-cli-2.1.0 lib/hanami/cli/commands.rb
hanami-cli-2.1.0.rc3 lib/hanami/cli/commands.rb
hanami-cli-2.1.0.rc2 lib/hanami/cli/commands.rb
hanami-cli-2.1.0.rc1 lib/hanami/cli/commands.rb
hanami-cli-2.1.0.beta2 lib/hanami/cli/commands.rb
hanami-cli-2.1.0.beta1 lib/hanami/cli/commands.rb
hanami-cli-2.0.3 lib/hanami/cli/commands.rb
hanami-cli-2.0.2 lib/hanami/cli/commands.rb
hanami-cli-2.0.1 lib/hanami/cli/commands.rb
hanami-cli-2.0.0 lib/hanami/cli/commands.rb