Class: Cliqr::Parser::TokenFactory Private

Inherits:
Object
  • Object
show all
Defined in:
lib/cliqr/parser/token_factory.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A factory class to get a instance of CLI::Parser::Token based on the argument

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Cliqr::CLI::Parser::TokenFactory

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new token factory instance

Parameters:

  • config (Cliqr::CLI::Config)

    Command line interface configuration



20
21
22
# File 'lib/cliqr/parser/token_factory.rb', line 20

def initialize(config)
  @config = config
end

Instance Method Details

#get_token(arg = nil) ⇒ Cliqr::CLI::Parser::Token

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get a new instance of CLI::Parser::Token based on the argument

Parameters:

  • arg (String) (defaults to: nil)

    The argument used to get a token instance (default nil)

Returns:

  • (Cliqr::CLI::Parser::Token)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cliqr/parser/token_factory.rb', line 29

def get_token(arg = nil)
  if arg.nil?
    Token.new
  else
    case arg
    when /^--(no-)?([a-zA-Z][a-zA-Z0-9\-_]*)$/, /^(-)([a-zA-Z])$/
      option_config = get_option_config(Regexp.last_match(2), arg)
      build_token(option_config, arg)
    else
      fail Cliqr::Error::IllegalArgumentError, "invalid command argument \"#{arg}\"" \
        unless @config.arguments?
      ArgumentToken.new(arg)
    end
  end
end