Class: Dry::CLI::CommandRegistry Private
- Inherits:
-
Object
- Object
- Dry::CLI::CommandRegistry
- Defined in:
- lib/dry/cli/command_registry.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Command registry
Defined Under Namespace
Classes: Chain, LookupResult, Node
Instance Method Summary collapse
-
#get(arguments) ⇒ Object
private
rubocop:disable Metrics/AbcSize.
-
#initialize ⇒ CommandRegistry
constructor
private
A new instance of CommandRegistry.
- #set(name, command, aliases, hidden) ⇒ Object private
Constructor Details
#initialize ⇒ CommandRegistry
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of CommandRegistry.
14 15 16 17 |
# File 'lib/dry/cli/command_registry.rb', line 14 def initialize @_mutex = Mutex.new @root = Node.new end |
Instance Method Details
#get(arguments) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Metrics/AbcSize
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/dry/cli/command_registry.rb', line 42 def get(arguments) @_mutex.synchronize do node = @root args = [] names = [] valid_leaf = nil result = LookupResult.new(node, args, names, node.leaf?) arguments.each_with_index do |token, i| tmp = node.lookup(token) if tmp.nil? && valid_leaf result = valid_leaf break elsif tmp.nil? result = LookupResult.new(node, args, names, false) break elsif tmp.leaf? args = arguments[i + 1..] names = arguments[0..i] node = tmp result = LookupResult.new(node, args, names, true) valid_leaf = result break unless tmp.children? else names = arguments[0..i] node = tmp result = LookupResult.new(node, args, names, node.leaf?) end end result end end |
#set(name, command, aliases, hidden) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dry/cli/command_registry.rb', line 21 def set(name, command, aliases, hidden) @_mutex.synchronize do node = @root name.split(/[[:space:]]/).each do |token| node = node.put(node, token) end node.aliases!(aliases) node.hidden!(hidden) if command node.leaf!(command) node.subcommands!(command) end nil end end |