Sha256: 2e03775dbed07699438dfa4355d1d04326097cc5588130b87793baaecd7c1851

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require "dry/inflector"
require "dry/files"
require "shellwords"

module Hanami
  module CLI
    module Commands
      module App
        module Generate
          # @since 2.1.0
          # @api private
          class Part < App::Command
            argument :name, required: true, desc: "Part name"
            option :slice, required: false, desc: "Slice name"

            example [
              %(book               (MyApp::Views::Parts::Book)),
              %(book --slice=admin (Admin::Views::Parts::Book)),
            ]
            attr_reader :generator
            private :generator

            # @since 2.0.0
            # @api private
            def initialize(
              fs: Hanami::CLI::Files.new,
              inflector: Dry::Inflector.new,
              generator: Generators::App::Part.new(fs: fs, inflector: inflector),
              **
            )
              @generator = generator
              super(fs: fs)
            end

            # @since 2.0.0
            # @api private
            def call(name:, slice: nil, **)
              slice = inflector.underscore(Shellwords.shellescape(slice)) if slice

              generator.call(app.namespace, name, slice)
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hanami-cli-2.1.0.rc1 lib/hanami/cli/commands/app/generate/part.rb