Sha256: b926d7105bb4bd802276aa08663c316eb6078da5ee01b0a8e779f0336f767de7

Contents?: true

Size: 1.52 KB

Versions: 7

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module Tocer
  module CLI
    module Parsers
      # Handles parsing of Command Line Interface (CLI) build options.
      class Build
        def self.call options: {}, configuration: Configuration::Loader.call, client: CLIENT
          new(options: options, configuration: configuration, client: client).call
        end

        def initialize options: {}, configuration: Configuration::Loader.call, client: CLIENT
          @options = options
          @configuration = configuration
          @client = client
        end

        def call arguments = []
          client.separator "\nBUILD OPTIONS:\n"
          private_methods.sort.grep(/add_/).each { |method| __send__ method }
          arguments.empty? ? arguments : client.parse!(arguments)
        end

        private

        attr_reader :options, :configuration, :client

        def add_label
          client.on(
            "-l",
            "--label [LABEL]",
            %(Label. Default: "#{CLI::Configuration::Loader.call.label}".)
          ) do |value|
            options[:label] = value || configuration.to_h.fetch(:label)
          end
        end

        def add_include
          client.on(
            "-i",
            "--includes [a,b,c]",
            Array,
            %(Include pattern list. Default: #{CLI::Configuration::Loader.call.includes}.)
          ) do |value|
            list = Array value
            options[:includes] = list.empty? ? configuration.to_h.fetch(:includes) : list
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tocer-12.2.0 lib/tocer/cli/parsers/build.rb
tocer-12.1.0 lib/tocer/cli/parsers/build.rb
tocer-12.0.4 lib/tocer/cli/parsers/build.rb
tocer-12.0.3 lib/tocer/cli/parsers/build.rb
tocer-12.0.2 lib/tocer/cli/parsers/build.rb
tocer-12.0.1 lib/tocer/cli/parsers/build.rb
tocer-12.0.0 lib/tocer/cli/parsers/build.rb