Class: RVC::Command
- Inherits:
-
Object
- Object
- RVC::Command
- Defined in:
- lib/rvc/command.rb
Instance Attribute Summary collapse
-
#completor ⇒ Object
Returns the value of attribute completor.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ns ⇒ Object
readonly
Returns the value of attribute ns.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
Instance Method Summary collapse
- #complete(word, args) ⇒ Object
-
#initialize(ns, name, summary, parser) ⇒ Command
constructor
A new instance of Command.
- #inspect ⇒ Object
- #invoke(*args) ⇒ Object
- #long_option_candidates(word) ⇒ Object
Constructor Details
#initialize(ns, name, summary, parser) ⇒ Command
Returns a new instance of Command.
29 30 31 32 33 34 35 |
# File 'lib/rvc/command.rb', line 29 def initialize ns, name, summary, parser @ns = ns @name = name @summary = summary @parser = parser @completor = nil end |
Instance Attribute Details
#completor ⇒ Object
Returns the value of attribute completor.
27 28 29 |
# File 'lib/rvc/command.rb', line 27 def completor @completor end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
26 27 28 |
# File 'lib/rvc/command.rb', line 26 def name @name end |
#ns ⇒ Object (readonly)
Returns the value of attribute ns.
26 27 28 |
# File 'lib/rvc/command.rb', line 26 def ns @ns end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
26 27 28 |
# File 'lib/rvc/command.rb', line 26 def parser @parser end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
26 27 28 |
# File 'lib/rvc/command.rb', line 26 def summary @summary end |
Instance Method Details
#complete(word, args) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rvc/command.rb', line 45 def complete word, args if @completor candidates = @completor.call word, args prefix_regex = /^#{Regexp.escape word}/ candidates.select { |x,a| x =~ prefix_regex } else return @ns.shell.completion.fs_candidates(word) + long_option_candidates(word) end end |
#inspect ⇒ Object
37 38 39 |
# File 'lib/rvc/command.rb', line 37 def inspect "#<RVC::Command:#{name}>" end |
#invoke(*args) ⇒ Object
41 42 43 |
# File 'lib/rvc/command.rb', line 41 def invoke *args @ns.slate.send @name, *args end |
#long_option_candidates(word) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/rvc/command.rb', line 56 def long_option_candidates word return [] unless parser.is_a? RVC::OptionParser prefix_regex = /^#{Regexp.escape(word)}/ parser.specs.map { |k,v| "--#{v[:long]}" }. grep(prefix_regex).sort. map { |x| [x, ' '] } end |