Location
Sometimes you may need a reference to a currently registered command. You can do so using the CommandRepository of your command manager.
const = .().();
.locateBy- locateByNameTree
- locateByClassTree
Location by name
Use the locateByNameTree() method to find a command by its name tree, which is a string representation of the command's hierarchy, e.g. parent sub-command.
const topLevel = .('top-level-command');
const subCommandOrGroup = .('parent', 'sub-command-or-group');
const subCommand = .('parent', 'sub-command-group', 'sub-command');This however only returns the generic base types, not a specific class instance. If you need a specific type, use the following method.
Location by class
The locateByClassTree() method allows you to find a command by its class hierarchy, which is useful if you want to get a specific command type.
const standalone = .();
const subCommand = .(, );
const subCommandGroup = .(, );Notice how the return type of each call is the respective instance (or null), not the generic types.
Getting commands
Alternatively, you can get all top level commands with the getCommands() method, which returns a ReadonlyCollection of them, keyed by name.
const topLevels = .();