Sha256: ea40e585d08fde9fbdc3d7f6a2f2a5dae2a414b719e6d107fdbe50d7214ce125

Contents?: true

Size: 1.05 KB

Versions: 16

Compression:

Stored size: 1.05 KB

Contents

require 'gli/command_line_option.rb'

module GLI
  # Defines a command line switch
  class Switch < CommandLineOption #:nodoc:

    attr_accessor :default_value
    attr_reader :negatable

    # Creates a new switch
    #
    # names - Array of symbols or strings representing the names of this switch
    # options - hash of options:
    #           :desc - the short description
    #           :long_desc - the long description
    #           :negatable - true or false if this switch is negatable; defaults to true
    #           :default_value - default value if the switch is omitted
    def initialize(names,options = {})
      super(names,options)
      @default_value = false if options[:default_value].nil?
      @negatable = options[:negatable].nil? ? true : options[:negatable]
      if @default_value != false && @negatable == false
        raise "A switch with default #{@default_value} that isn't negatable is useless"
      end
    end

    def arguments_for_option_parser
      all_forms_a
    end

    def negatable?
      @negatable
    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
gli-2.12.2 lib/gli/switch.rb
gli-2.12.1 lib/gli/switch.rb
gli-2.12.0 lib/gli/switch.rb
gli-2.11.0 lib/gli/switch.rb
gli-2.10.0 lib/gli/switch.rb
gli-2.9.0 lib/gli/switch.rb
gli_aziz_light-2.8.1 lib/gli/switch.rb
gli-2.8.1 lib/gli/switch.rb
gli-2.8.0 lib/gli/switch.rb
gli-2.7.0 lib/gli/switch.rb
gli-2.6.2 lib/gli/switch.rb
gli-2.6.1 lib/gli/switch.rb
gli-2.6.0 lib/gli/switch.rb
gli-2.6.0.rc1 lib/gli/switch.rb
gli-2.5.6 lib/gli/switch.rb
gli-2.5.5 lib/gli/switch.rb