Sha256: c0589b9f301e8e41f3048428aa277306b10485bc7545ad31833dd5dbb05b5deb

Contents?: true

Size: 1.42 KB

Versions: 15

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require "refinements/structs"

module Gemsmith
  module CLI
    module Parsers
      # Handles parsing of Command Line Interface (CLI) build options.
      class Build
        include Import[:colorizer]

        using Refinements::Structs

        def self.call(...) = new(...).call

        def initialize configuration = Container[:configuration],
                       client: Parser::CLIENT,
                       **dependencies

          super(**dependencies)

          @configuration = configuration
          @client = client
        end

        def call arguments = []
          add_cli
          client.parse arguments
          configuration
        end

        private

        attr_reader :configuration, :client

        def add_cli
          client.on(
            "--[no-]cli",
            "Add command line interface. #{default __method__}."
          ) do |value|
            configuration.merge! build_refinements: value, build_zeitwerk: value if value
            configuration.merge! build_cli: value
          end
        end

        def default option
          option.to_s
                .sub("add_", "build_")
                .then { |attribute| configuration.public_send attribute }
                .then { |boolean| boolean ? colorizer.green(boolean) : colorizer.red(boolean) }
                .then { |colored_boolean| "Default: #{colored_boolean}" }
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
gemsmith-19.1.0 lib/gemsmith/cli/parsers/build.rb
gemsmith-19.0.0 lib/gemsmith/cli/parsers/build.rb
gemsmith-18.9.0 lib/gemsmith/cli/parsers/build.rb
gemsmith-18.8.0 lib/gemsmith/cli/parsers/build.rb
gemsmith-18.7.0 lib/gemsmith/cli/parsers/build.rb
gemsmith-18.6.0 lib/gemsmith/cli/parsers/build.rb
gemsmith-18.5.0 lib/gemsmith/cli/parsers/build.rb
gemsmith-18.4.0 lib/gemsmith/cli/parsers/build.rb
gemsmith-18.3.0 lib/gemsmith/cli/parsers/build.rb
gemsmith-18.2.0 lib/gemsmith/cli/parsers/build.rb
gemsmith-18.1.1 lib/gemsmith/cli/parsers/build.rb
gemsmith-18.1.0 lib/gemsmith/cli/parsers/build.rb
gemsmith-18.0.2 lib/gemsmith/cli/parsers/build.rb
gemsmith-18.0.1 lib/gemsmith/cli/parsers/build.rb
gemsmith-18.0.0 lib/gemsmith/cli/parsers/build.rb