Class: Command::Named

Inherits:
ArgumentDecoration show all
Defined in:
lib/command-set/arguments.rb

Overview

Indicated that the name of the argument has to appear on the command line before it will be recognized. Useful for optional or alternating arguments

Instance Attribute Summary

Attributes inherited from Argument

#name

Instance Method Summary collapse

Methods inherited from ArgumentDecoration

#decorated, #initialize, #pretty_print_instance_variables, register

Methods inherited from Argument

#basis, #check_present, #consume_hash, #initialize, #names, #omittable?, #parse, register, #required?, #subject_requirements

Constructor Details

This class inherits a constructor from Command::ArgumentDecoration

Instance Method Details

#complete(terms, prefix, subject) ⇒ Object



454
455
456
457
458
459
460
# File 'lib/command-set/arguments.rb', line 454

def complete(terms, prefix, subject)
  if %r{^#{prefix.to_s}.*} =~ name.to_s
    return [name.to_s]
  else
    return []
  end
end

#consume(subject, arguments) ⇒ Object



435
436
437
438
439
440
441
442
# File 'lib/command-set/arguments.rb', line 435

def consume(subject, arguments)
  if arguments.first == name
    arguments.shift
    return decorated.consume(subject,arguments)
  else
    raise ArgumentInvalidException, "Name \"#{name}\" required."
  end
end

#match_terms(subject, terms, arguments) ⇒ Object



444
445
446
447
448
449
450
451
452
# File 'lib/command-set/arguments.rb', line 444

def match_terms(subject, terms, arguments)
  if terms.first == name.to_s
    terms.shift
    arguments.shift
    arguments.unshift(decorated)
  else
    arguments.shift
  end
end

#validate(term, subject) ⇒ Object



462
463
464
# File 'lib/command-set/arguments.rb', line 462

def validate(term, subject)
  return term == name || super
end