Sha256: 1518a14c679b0dc4220d8c48477a64f4bca1765c0edbf551db9dd6de5ea9dc23

Contents?: true

Size: 1003 Bytes

Versions: 65

Compression:

Stored size: 1003 Bytes

Contents

require 'gli/command_line_token.rb'

module GLI
  # An option, not a command or argument, on the command line
  class CommandLineOption < CommandLineToken #:nodoc:

    attr_accessor :default_value
    # Command to which this option "belongs", nil if it's a global option
    attr_accessor :associated_command

    # Creates a new option
    #
    # 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
    #           :default_value - the default value of this option
    def initialize(names,options = {})
      super(names,options[:desc],options[:long_desc])
      @default_value = options[:default_value]
    end

    def self.name_as_string(name,negatable=true)
      string = name.to_s
      if string.length == 1 
        "-#{string}" 
      elsif negatable
        "--[no-]#{string}"
      else
        "--#{string}"
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 2 rubygems

Version Path
gli-2.0.0.rc7 lib/gli/command_line_option.rb
gli-2.0.0.rc6 lib/gli/command_line_option.rb
gli-2.0.0.rc5 lib/gli/command_line_option.rb
gli-2.0.0.rc4 lib/gli/command_line_option.rb
gli-2.0.0.rc3 lib/gli/command_line_option.rb