Sha256: bb6f48371f970f4792c71cf13e818c870f1d2a42513beb04853b6c08f6e60df6

Contents?: true

Size: 1.08 KB

Versions: 28

Compression:

Stored size: 1.08 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

    def required?
      false
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
gli-2.22.0 lib/gli/switch.rb
gli-2.21.5 lib/gli/switch.rb
gli-2.21.4 lib/gli/switch.rb
gli-2.21.3 lib/gli/switch.rb
gli-2.21.2 lib/gli/switch.rb
gli-2.21.1 lib/gli/switch.rb
gli-2.21.0 lib/gli/switch.rb
gli-2.20.1 lib/gli/switch.rb
gli-2.20.0 lib/gli/switch.rb
gli-2.19.2 lib/gli/switch.rb
gli-2.19.1 lib/gli/switch.rb
gli-2.19.0 lib/gli/switch.rb
gli-2.18.2 lib/gli/switch.rb
gli-2.18.1 lib/gli/switch.rb
gli-2.18.0 lib/gli/switch.rb
gli-2.17.2 lib/gli/switch.rb
gli-2.17.1 lib/gli/switch.rb
gli-2.17.0 lib/gli/switch.rb
gli-2.16.1 lib/gli/switch.rb
gli-2.16.0 lib/gli/switch.rb