Module: LokkaSh::Command
- Defined in:
- lib/lokka-sh/command.rb,
lib/lokka-sh/command/define.rb
Class Method Summary collapse
- .[](name) ⇒ Object
- .clear ⇒ Object
- .command_names ⇒ Object
- .commands ⇒ Object
- .completion_proc ⇒ Object
- .completions ⇒ Object
- .completions=(completions) ⇒ Object
- .define(*names, &block) ⇒ Object
- .find(line) ⇒ Object
Class Method Details
.[](name) ⇒ Object
27 28 29 |
# File 'lib/lokka-sh/command.rb', line 27 def [](name) commands[name.to_sym] end |
.clear ⇒ Object
53 54 55 56 |
# File 'lib/lokka-sh/command.rb', line 53 def clear commands.clear completions.clear end |
.command_names ⇒ Object
23 24 25 |
# File 'lib/lokka-sh/command.rb', line 23 def command_names commands.keys end |
.commands ⇒ Object
4 5 6 |
# File 'lib/lokka-sh/command.rb', line 4 def commands @commands ||= {} end |
.completion_proc ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/lokka-sh/command.rb', line 31 def completion_proc lambda { |line| regex = /#{Regexp.quote(line)}/ completions.map { |completion| case completion when String completion if completion.match(regex) when Proc completion.call(line) end }.compact } end |
.completions ⇒ Object
45 46 47 |
# File 'lib/lokka-sh/command.rb', line 45 def completions @completions ||= [] end |
.completions=(completions) ⇒ Object
49 50 51 |
# File 'lib/lokka-sh/command.rb', line 49 def completions=(completions) @completions = completions end |
.define(*names, &block) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/lokka-sh/command.rb', line 8 def define(*names, &block) names.each do |name| commands[name.to_sym] = block completions << name.to_s end end |
.find(line) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/lokka-sh/command.rb', line 15 def find(line) if name = line.split(/\s+/, 2)[0] commands[name.to_sym] else nil end end |