Sha256: 0763c3e0674b30fa173460ce8e1c4387713db5c347ccd98787b136dc503b1aa6

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require "refinements/structs"

module Tocer
  module CLI
    module Parsers
      # Handles parsing of Command Line Interface (CLI) flags.
      class Flag
        using Refinements::Structs

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

        def initialize configuration = Configuration::Loader.call, client: Parser::CLIENT
          @configuration = configuration
          @client = client
        end

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

        private

        attr_reader :configuration, :client

        def add_label
          client.on(
            "--label [LABEL]",
            %(Add label. Default: "#{configuration.label}".)
          ) do |value|
            configuration.merge! label: value if value
          end
        end

        def add_include
          client.on(
            "--includes [a,b,c]",
            Array,
            %(Add include patterns. Default: #{configuration.includes}.)
          ) do |items|
            configuration.merge! includes: items if items
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tocer-13.3.1 lib/tocer/cli/parsers/flag.rb
tocer-13.3.0 lib/tocer/cli/parsers/flag.rb
tocer-13.2.0 lib/tocer/cli/parsers/flag.rb
tocer-13.1.0 lib/tocer/cli/parsers/flag.rb
tocer-13.0.2 lib/tocer/cli/parsers/flag.rb
tocer-13.0.1 lib/tocer/cli/parsers/flag.rb
tocer-13.0.0 lib/tocer/cli/parsers/flag.rb