Class: KXI::CLI::NamedArgument
- Inherits:
-
ExplicitArgument
- Object
- Argument
- ExplicitArgument
- KXI::CLI::NamedArgument
- Defined in:
- lib/kxi/cli/named_argument.rb
Overview
Represents named argument (eg.: -a VALUE, –argument VALUE)
Instance Method Summary collapse
-
#default ⇒ Object
Gets default value of argument.
-
#headline ⇒ String
Gets full descriptive name of argument.
-
#initialize(nm, vn, desc, sh = nil, rq = true, df = nil, var = false, &validator) ⇒ NamedArgument
constructor
Instantiates the NamedArgument class.
-
#syntax ⇒ String
Gets syntax of argument.
-
#validate(val) ⇒ Object
Validates value of argument.
-
#value_name ⇒ String
Gets name of argument value.
-
#variadic? ⇒ Bool
Gets whether argument is variadic.
Methods inherited from ExplicitArgument
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
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
#default ⇒ Object
Gets default value of argument
9 10 11 |
# File 'lib/kxi/cli/named_argument.rb', line 9 def default @def end |
#headline ⇒ String
Gets full descriptive name of argument
27 28 29 |
# File 'lib/kxi/cli/named_argument.rb', line 27 def headline "#{super} #{@var ? '...' : ''}#{@vnm.upcase}" end |
#syntax ⇒ String
Gets 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
55 56 57 |
# File 'lib/kxi/cli/named_argument.rb', line 55 def validate(val) @val.call(val) if @val != nil end |
#value_name ⇒ String
Gets 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
15 16 17 |
# File 'lib/kxi/cli/named_argument.rb', line 15 def variadic? @var end |