Documentation
¶
Overview ¶
Package mount hangs the commands modules contribute on tt's root command.
Every command lands where its mount says, whatever order the modules were listed in: mounts are hung shallowest first, so the group a module provides is in place before the commands other modules mount under it, and a group nobody provides is created as a placeholder. A group that is not itself a command is shared: any module may mount under it. What the tree cannot hold - two commands answering to one name, a command under another module's runnable command, a flag tt reserves - is refused with an error naming the modules involved.
The commands of a module are also prepared for the core: their hooks are wrapped so that the error they return is reported by the core, once, and not by cobra. Legacy commands - the ones tt built before modules - are hung as they are.
Once hung, the tree can still change at the root: Replace puts a module's command in place of a command there, or adds it there, checked and prepared as Hang would. It is what lets a command found only after the modules are hung, such as an external module, take over a top-level command.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
// Module is the name of the module the command comes from.
Module string
// Path names the command's parent by command names from the root down,
// separated by spaces; "" is the root.
Path string
// Cmd is the command, with no parent.
Cmd *cobra.Command
// Legacy marks a command tt built before modules. It is hung without the
// checks and the hook wrapping a module command gets.
Legacy bool
}
Entry is one command a module mounts.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry records which module each command in the tree comes from.
func Hang ¶
Hang adds the commands of entries to root and returns who owns what. It refuses what the tree cannot hold and returns every such problem, joined; the tree is then incomplete and must not be run.
func (*Registry) Owner ¶
Owner returns the module cmd comes from: the module that mounted it or the command it is under, and for a placeholder group the module whose mount created it. It reports false for a command neither Hang nor Replace hung, and for one Replace took out of the tree.
func (*Registry) Replace ¶
Replace hangs cmd, a command of module, at the root in place of old, a command at the root, or adds cmd at the root when old is nil. old and its subtree leave the tree and the registry; cmd and its subtree are recorded as module's and prepared like the commands of any module. old's aliases leave with it: cmd answers to its own name and aliases only, so a caller that means cmd to answer to old's aliases gives them to cmd.
cmd is refused where Hang would refuse it mounted at the root with old gone, and so is an old that is not at the root or is named other than cmd. A refusal leaves the tree and the registry as they were.
type Reserved ¶
type Reserved struct {
// Names are the command names no command may have, or have as an alias,
// at the root.
Names []string
// Flags are the flags no module command may declare, by name or by
// shorthand. The flags of the root and the persistent flags of the
// groups a command is mounted under are reserved as well.
Flags *pflag.FlagSet
}
Reserved is what no module may take.