class KXI::CLI::NamedArgument

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

Public Class Methods

new(nm, vn, desc, sh = nil, rq = true, df = nil, var = false, &validator) click to toggle source

Instantiates the {KXI::CLI::NamedArgument} class @param nm [String] Name of argument @param vn [String] Name of value @param desc [String] Description of argument @param sh [String] Shortcut of argument @param rq [Bool] Indicates whether argument is required @param df Default value of argument @param var [Bool] Indicates whether argument is variadic

Calls superclass method KXI::CLI::ExplicitArgument::new
# 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

Public Instance Methods

default() click to toggle source

Gets default value of argument @return [Object] Default value of argument

# File lib/kxi/cli/named_argument.rb, line 9
def default
        @def
end
headline() click to toggle source

Gets full descriptive name of argument @return [String] Full name of argument

# File lib/kxi/cli/named_argument.rb, line 27
def headline
        "#{super} #{@var ? '...' : ''}#{@vnm.upcase}"
end
syntax() click to toggle source

Gets syntax of argument @return [String] Syntax of argument

# File lib/kxi/cli/named_argument.rb, line 33
def syntax
        "-#{(shortcut != nil ? shortcut : "-#{name}")} #{required? ? '<' : '['}#{@var ? '...' : ''}#{@vnm}#{required? ? '>' : ']'}"
end
validate(val) click to toggle source

Validates value of argument @param val [String, Array<String>] Value of argument

# File lib/kxi/cli/named_argument.rb, line 55
def validate(val)
        @val.call(val) if @val != nil
end
value_name() click to toggle source

Gets name of argument value @return [String] Name of argument value

# File lib/kxi/cli/named_argument.rb, line 21
def value_name
        @vnm
end
variadic?() click to toggle source

Gets whether argument is variadic @return [Bool] True if argument is variadic; false otherwise

# File lib/kxi/cli/named_argument.rb, line 15
def variadic?
        @var
end