feat: adds plugin feature for extending cli with new commands #435
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Updates the CLI to allow adding new commands.
New commands are discovered simply by being present on the path. This implementation is similar to other cli tools that support plugins: any executable that is found on the path that is named “ask-” is considered a plugin. Guard rails are in place to ensure that a plugin cannot override an internal command. Plugins with the same names are also detected and a warning given to the user.
You can test the feature with a sample plugin. This plugin can generate a new Intent and handler on a skill created with "ask new".
Install the beta CLI based on ask-cli 2.27.0:
npm install git+https://github.com/rmauge/ask-cli.git\#plugin-feature-qa -g
The executable "ask_plugin" should now available to be used as a drop-in replacement for "ask".
Install a sample plugin for generating skill artifacts:
npm install git+https://github.com/rmauge/ask-generate.git -g
The ask-generate command should now be available. Verify by running "ask_plugin" and look for the "generate" command.
Generate a new Intent:
Navigate to a new skill that follows the same layout as created by "ask new".
ask_plugin generate intent StartOrder "begin my order" "place Order" "start order" "new order"
Your skill IM model should now have a new Intent added and a new Handler under lambda/handlers.
To uninstall:
npm uninstall --location=global ask-cli-plugin
npm uninstall --location=global ask-generate
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.