Sha256: 1fec2bf34e3c51fcf0330363e2588a2d1dc8fb0ea289c016cc5a49ed6f38b026

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require "dry/inflector"
require "hanami/cli/command"
require "hanami/utils/files"

module Hanami
  class CLI
    # Base class for Hanami application CLI commands
    class BaseCommand < Hanami::CLI::Command
      attr_reader :out
      attr_reader :inflector
      attr_reader :files

      def initialize(
        command_name:,
        out: $stdout,
        inflector: Dry::Inflector.new,
        files: Hanami::Utils::Files
      )
        super(command_name: command_name)

        @out = out
        @inflector = inflector
        @files = files
      end

      private

      def run_command(klass, *args)
        klass.new(
          command_name: klass.name,
          application: application,
          out: out,
          files: files,
        ).call(*args)
      end

      def measure(desc)
        start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
        yield
        stop = Process.clock_gettime(Process::CLOCK_MONOTONIC)

        out.puts "=> #{desc} in #{(stop - start).round(1)}s"
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
hanami-2.0.0.alpha8 lib/hanami/cli/base_command.rb
hanami-2.0.0.alpha7.1 lib/hanami/cli/base_command.rb
hanami-2.0.0.alpha7 lib/hanami/cli/base_command.rb
hanami-2.0.0.alpha6 lib/hanami/cli/base_command.rb
hanami-2.0.0.alpha5 lib/hanami/cli/base_command.rb
hanami-2.0.0.alpha4 lib/hanami/cli/base_command.rb
hanami-2.0.0.alpha3 lib/hanami/cli/base_command.rb
hanami-2.0.0.alpha2 lib/hanami/cli/base_command.rb