Sha256: b7911189f68cd8a3c6a953b1f2a6f008ed86290a50cb3ca4aadb7455e45aa055

Contents?: true

Size: 1.3 KB

Versions: 11

Compression:

Stored size: 1.3 KB

Contents

require "gli/dsl"
require "gli/command_line_option"
require "gli/option_parser_factory"

module GLI
  module DSL
    def extract_options(names)
      options = {}
      options = names.pop if names.last.kind_of? Hash
      options = {
        :desc => @next_desc,
        :long_desc => @next_long_desc,
        :default_value => @next_default_value,
        :ignore_default => @ignore_default,
        :arg_name => @next_arg_name
      }.merge(options)
    end
  end

  class CommandLineOption
    def initialize(names, options = {})
      # Disable returning a default for this option (needed for boolean updates)
      # which should NOT be sent unless added by the user
      @ignore_default = !!options[:ignore_default]

      super(names, options[:desc], options[:long_desc])
      @default_value = options[:default_value]
    end

    def ignore_default?
      @ignore_default
    end
  end

  class OptionParserFactory
    private

    def set_defaults(options_by_name,options_hash)
      options_by_name.values.each do |option|
        option.names_and_aliases.each do |option_name|
          [option_name,option_name.to_sym].each do |name|
            next if option.ignore_default?

            options_hash[name] = option.default_value if options_hash[name].nil?
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
brightbox-cli-5.0.0 lib/gli_patches.rb
brightbox-cli-5.0.0.rc2 lib/gli_patches.rb
brightbox-cli-5.0.0.rc1 lib/gli_patches.rb
brightbox-cli-5.0.0.alpha lib/gli_patches.rb
brightbox-cli-4.8.0 lib/gli_patches.rb
brightbox-cli-4.7.0 lib/gli_patches.rb
brightbox-cli-4.6.0 lib/gli_patches.rb
brightbox-cli-4.5.0 lib/gli_patches.rb
brightbox-cli-4.5.0.rc1 lib/gli_patches.rb
brightbox-cli-4.4.0 lib/gli_patches.rb
brightbox-cli-4.3.2 lib/gli_patches.rb