To use Section 10.3, “MySQL Shell Plugins” with the
command-line integration, the functions must be explicitly
defined for CLI support. When an object defined in a
MySQL Shell Plugin is enabled for command-line integration,
only the specific functions that were
enabled are available for CLI calls. From MySQL Shell version
8.0.24, when you add function members to an object, they
support the cli boolean option. When
cli is set to true, the
function is available from the command-line integration. The
cli option defaults to false, therefore
functions are not available from the command-line integration
unless specifically enabled. Any object with a function that
has the cli option enabled causes its
parent objects to be available in the command-line integration
as well.
To make a function available through the command-line
integration, set the cli option to
true when you add the extension object
member. For example:
shell.addExtensionObjectMember(object, "exampleFunction", exampleFunction,
{
brief:"Retrieves brief information",
details: ["Retrieves detailed information"],
cli: true,
parameters:
[
{
name: "param_a",
type: "string",
brief: "param_a brief"
}
]
});
You could then use the exampleFunction()
function from the command-line integration as follows:
mysqlsh -- customObj exampleFunction 1
If you have added an extension object member using a
MySQL Shell version earlier than 8.0.24, and you want to use
it with the command-line integration, you must enable the
cli option. Use the
addExtensionObjectMember method as
illustrated here to add the object member again, this time
enabling the cli option.