Sha256: ac02761d1e56c5e018c5c7238ca1331bdc4e8598121828a1f2e46cd42197bf4a

Contents?: true

Size: 1.14 KB

Versions: 7

Compression:

Stored size: 1.14 KB

Contents

module CommandLine
  
  # Argument flag handling.
  class Flag
    
    attr_reader :name
    attr_reader :alias
    attr_reader :argument
    
    # Initialize new Flag
    # <tt>name</tt> The name of the flag
    # <tt>definition</tt> The definition of the flag.
    def initialize(name, definition)
      @name     = name.to_s.gsub(/_/, '-').to_sym
      @alias    = definition[:alias].to_sym if definition[:alias]
      @required = definition.has_key?(:required) && definition[:required] == true
      @argument = definition[:expects] if definition[:expects]
    end
    
    # Argument representation of the flag (--fast)
    def to_argument
      "--#{@name}"
    end
    
    # Argument alias representation of the flag (-f)
    def to_alias
      "-#{@alias}"
    end
        
    # Check if flag has an alias
    def has_alias?
      !@alias.nil?
    end
    
    # Check if flag is optional
    def optional?
      !@required
    end
    
    # Check if flag is required
    def required?
      @required
    end
    
    # Check if flag expects an argument (Are you talking to me?)
    def expects_argument?
      !@argument.nil?
    end
  end  
  
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
lackac-request-log-analyzer-0.1.3 lib/command_line/flag.rb
wvanbergen-request-log-analyzer-0.1.0 lib/command_line/flag.rb
wvanbergen-request-log-analyzer-0.1.1 lib/command_line/flag.rb
wvanbergen-request-log-analyzer-0.1.2 lib/command_line/flag.rb
wvanbergen-request-log-analyzer-0.2.2 lib/command_line/flag.rb
wvanbergen-request-log-analyzer-0.3.4 lib/command_line/flag.rb
wvanbergen-request-log-analyzer-1.0.0 lib/command_line/flag.rb