Class: KXI::CLI::NamedArgument

Inherits:
ExplicitArgument show all
Defined in:
lib/kxi/cli/named_argument.rb

Overview

Represents named argument (eg.: -a VALUE, –argument VALUE)

Instance Method Summary collapse

Methods inherited from ExplicitArgument

#shortcut

Methods inherited from Argument

#description, #name, #order, #required?

Constructor Details

#initialize(nm, vn, desc, sh = nil, rq = true, df = nil, var = false, &validator) ⇒ NamedArgument

Instantiates the KXI::CLI::NamedArgument class

Parameters:

  • nm (String)

    Name of argument

  • vn (String)

    Name of value

  • desc (String)

    Description of argument

  • sh (String) (defaults to: nil)

    Shortcut of argument

  • rq (Bool) (defaults to: true)

    Indicates whether argument is required

  • df (defaults to: nil)

    Default value of argument

  • var (Bool) (defaults to: false)

    Indicates whether argument is variadic



45
46
47
48
49
50
51
# File 'lib/kxi/cli/named_argument.rb', line 45

def initialize(nm, vn, desc, sh = nil, rq = true, df = nil, var = false, &validator)
	super(nm, desc, sh, rq)
	@def = df
	@vnm = vn
	@var = var
	@val = validator
end

Instance Method Details

#defaultObject

Gets default value of argument

Returns:

  • (Object)

    Default value of argument



9
10
11
# File 'lib/kxi/cli/named_argument.rb', line 9

def default
	@def
end

#headlineString

Gets full descriptive name of argument

Returns:

  • (String)

    Full name of argument



27
28
29
# File 'lib/kxi/cli/named_argument.rb', line 27

def headline
	"#{super} #{@var ? '...' : ''}#{@vnm.upcase}"
end

#syntaxString

Gets syntax of argument

Returns:

  • (String)

    Syntax of argument



33
34
35
# File 'lib/kxi/cli/named_argument.rb', line 33

def syntax
	"-#{(shortcut != nil ? shortcut : "-#{name}")} #{required? ? '<' : '['}#{@var ? '...' : ''}#{@vnm}#{required? ? '>' : ']'}"
end

#validate(val) ⇒ Object

Validates value of argument

Parameters:

  • val (String, Array<String>)

    Value of argument



55
56
57
# File 'lib/kxi/cli/named_argument.rb', line 55

def validate(val)
	@val.call(val) if @val != nil
end

#value_nameString

Gets name of argument value

Returns:

  • (String)

    Name of argument value



21
22
23
# File 'lib/kxi/cli/named_argument.rb', line 21

def value_name
	@vnm
end

#variadic?Bool

Gets whether argument is variadic

Returns:

  • (Bool)

    True if argument is variadic; false otherwise



15
16
17
# File 'lib/kxi/cli/named_argument.rb', line 15

def variadic?
	@var
end