Sha256: 399995c84f965cf049d434922402788fa86b564e44fedc1921b6384949f9bc0c

Contents?: true

Size: 1 KB

Versions: 14

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module EacCli
  class Parser
    class Alternative
      module LongOptions
        LONG_OPTION_PREFIX = '--'
        OPTION_WITH_ARGUMENT_PATTERN = /\A([^=]+)(?:=(.*))\z/.freeze

        private

        def argv_current_long_option?
          phase == PHASE_ANY && argv_enum.peek.start_with?(LONG_OPTION_PREFIX) &&
            !argv_current_double_dash?
        end

        def long_option_collect_argv_value
          option_long, value = parse_option_current_argv
          alternative.options.any? do |option|
            next false unless option.long == option_long

            if value.nil?
              option_collect_option(option)
            else
              option_argument_collect(option, value)
            end
          end || any_option_collect_option
        end

        def parse_option_current_argv
          m = OPTION_WITH_ARGUMENT_PATTERN.match(argv_enum.peek)
          m ? [m[1], m[2].if_present('')] : [argv_enum.peek, nil]
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
eac_cli-0.42.0 lib/eac_cli/parser/alternative/long_options.rb
eac_cli-0.40.1 lib/eac_cli/parser/alternative/long_options.rb
eac_cli-0.40.0 lib/eac_cli/parser/alternative/long_options.rb
eac_cli-0.39.0 lib/eac_cli/parser/alternative/long_options.rb
eac_cli-0.38.1 lib/eac_cli/parser/alternative/long_options.rb
eac_tools-0.82.0 sub/eac_cli/lib/eac_cli/parser/alternative/long_options.rb
eac_tools-0.81.0 sub/eac_cli/lib/eac_cli/parser/alternative/long_options.rb
eac_tools-0.80.0 sub/eac_cli/lib/eac_cli/parser/alternative/long_options.rb
eac_tools-0.79.0 sub/eac_cli/lib/eac_cli/parser/alternative/long_options.rb
eac_tools-0.78.0 sub/eac_cli/lib/eac_cli/parser/alternative/long_options.rb
eac_tools-0.77.1 sub/eac_cli/lib/eac_cli/parser/alternative/long_options.rb
eac_tools-0.77.0 sub/eac_cli/lib/eac_cli/parser/alternative/long_options.rb
eac_cli-0.38.0 lib/eac_cli/parser/alternative/long_options.rb
eac_tools-0.76.1 sub/eac_cli/lib/eac_cli/parser/alternative/long_options.rb