-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Remove help verbose 8497 #8532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove help verbose 8497 #8532
Conversation
…r.loadCommands() Added isExternal feild to plugins and commands Passing isExternal: true for all plugins resolved via resolveServicePlugins() method pluginManager.loadAllPlugins()
Changed logging for help, now help will output all the OOTB commands in a single list, while commands form external pluging will be listed as group by plugin Plugins section in help will list only external plugin
Codecov Report
@@ Coverage Diff @@
## master #8532 +/- ##
==========================================
+ Coverage 87.24% 87.26% +0.01%
==========================================
Files 255 255
Lines 9503 9509 +6
==========================================
+ Hits 8291 8298 +7
+ Misses 1212 1211 -1
Continue to review full report at Codecov.
|
|
@medikoo pls review this |
medikoo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @vinod-tahelyani ! It looks very good. I've proposed few improvements. Let me know what you think
lib/classes/PluginManager.js
Outdated
| } | ||
|
|
||
| addPlugin(Plugin) { | ||
| addPlugin(Plugin, isExternal = false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use options object ({ isExternal } instead of isExternal).
This makes a better API (see: https://ariya.io/2011/08/hall-of-api-shame-boolean-trap)
lib/classes/PluginManager.js
Outdated
| } | ||
|
|
||
| loadCommands(pluginInstance) { | ||
| loadCommands(pluginInstance, isExternal) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
lib/classes/PluginManager.js
Outdated
| return event; | ||
| }); | ||
| this.commands[key] = _.merge({}, this.commands[key], command); | ||
| Object.assign(this.commands[key], { isExternal }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add it to above _.merge call, no need for extra Object.assign
lib/classes/PluginManager.js
Outdated
| addPlugin(Plugin, isExternal = false) { | ||
| const pluginInstance = new Plugin(this.serverless, this.cliOptions); | ||
| // isExternal differentiates plugin as OOTB or not | ||
| Object.assign(pluginInstance, { isExternal }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll be more transparent to create this.externalPlugins collection (as set instance), and just group all the plugins there.
Assigning a property to a plugin instance, while should in most cases be harmless, it's destructive, note that we're interferring into plugin API, we can't be sure if we won't break things
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u mean keeping this.plugins as it is and adding this.externalPlugins, right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly
lib/classes/CLI.js
Outdated
| this.consoleLog(externalSortedPlugins.map(plugin => plugin.constructor.name).join(', ')); | ||
|
|
||
| this.consoleLog(''); | ||
| this.consoleLog(chalk.yellow.underline('Commands by plugin')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's show this section, only if we have any commands added by plugins
lib/classes/CLI.js
Outdated
| this.consoleLog(''); | ||
| }); | ||
| } else { | ||
| this.consoleLog('No plugins added yet'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is to be displayed, when no external plugins are configured (?)
I think we can skip this message (In current implementation it was never shown, as there were always some internal plugins)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but in this case under 'Plugin', we do not list internal plugins, So this can be seen right ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and we don't want to be seen. Message is weird "No plugins added yet" (why yet?).
I think best way is to not show "Plugins" section at all
|
@medikoo done with all the changes, pls tell me what do u think |
medikoo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great thanks @vinod-tahelyani! It looks way better, we're close, Please see my final suggestions
lib/classes/CLI.js
Outdated
| this.serverless = serverless; | ||
| this.inputArray = inputArray || null; | ||
| this.loadedPlugins = []; | ||
| this.loadedExternalPlugins = new Set(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not introduce this collection (we can simply access the external plugins from plugin manager via this.serverless.pluginManager.externalPlugins)
I understand that you've tried to maintain the existing convention, however some of the conventions as found in the code-base are old, unnecessarily verbose (imply maintenance cost, which could be avoided), and we try to not follow them with new code.
lib/classes/CLI.js
Outdated
| this.loadedPlugins = plugins; | ||
| } | ||
|
|
||
| setLoadedExternalPlugins(externalPlugins) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not define this method
lib/classes/CLI.js
Outdated
| if (Object.keys(this.loadedCommands).length) { | ||
| Object.entries(this.loadedCommands).forEach(([command, details]) => { | ||
| const internalCommands = Object.entries(this.loadedCommands).filter( | ||
| command => command && !command.isExternal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this doesn't filter as expected, as in Object.entries result, each item is a [key, value] array, so command here is an array.
Simple fix would be to use Object.values instead, which is also more appriopriate in this case
lib/classes/CLI.js
Outdated
| this.consoleLog(''); | ||
| this.consoleLog(chalk.yellow.underline('General Commands')); | ||
| this.consoleLog(''); | ||
| if (Object.keys(this.loadedCommands).length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this if clause (in all cases there'll be some commands)
lib/classes/CLI.js
Outdated
|
|
||
| // print all the installed plugins | ||
| this.consoleLog(chalk.yellow.underline('Plugins')); | ||
| const externalSortedPlugins = this.loadedPlugins |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just name it externalPlugins (externalSortedPlugins would make sense if we would also host unsorted collection, but here it's not the case)
lib/classes/PluginManager.js
Outdated
| const internalPluginOptions = { isExternal: false }; | ||
| const externalPluginOptions = { isExternal: true }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not create this variables, we can simply hardcode { isExternal: true } as second argument when adding external plugins and in other cases do not pass any options at all (as options are optional)
lib/classes/PluginManager.js
Outdated
| } | ||
|
|
||
| loadCommands(pluginInstance) { | ||
| loadCommands(pluginInstance, options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's mark options as optional argument, by assigning a default value
lib/classes/PluginManager.js
Outdated
| return event; | ||
| }); | ||
| this.commands[key] = _.merge({}, this.commands[key], command); | ||
| this.commands[key] = _.merge({}, this.commands[key], command, options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll be more future proof, to specifically pass { isExternal: options.isExternal } (by design options are loadCommands operation options, and not command extension, and here we treat it as if it's command extension)
lib/classes/PluginManager.js
Outdated
| return this.plugins; | ||
| } | ||
|
|
||
| getExternalPlugins() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for that method
Removed unnecessary constants
Renamed externalSortedPlugins -> externalPlugins
Passing { isExternal: options.isExternal } in _.merge in line 289
|
@medikoo done |
medikoo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @vinod-tahelyani ! That looks great
Closes: #8497
The new output looks something like-
Commands
Interactive Quickstart
of functionalities related to given service or current environment
Serverless Components
Framework
Environment Variables
General Commands
config ........................ Configure Serverless
config credentials ............ Configures a new provider profile for the Serverless Framework
config tabcompletion install .. Install a completion for chosen shell
config tabcompletion uninstall Uninstall a completion for chosen shell
create ........................ Create new Serverless service
dashboard ..................... Open the Serverless dashboard
deploy ........................ Deploy a Serverless service
deploy function ............... Deploy a single function from the service
deploy list ................... List deployed version of your Serverless Service
deploy list functions ......... List all the deployed functions and their versions
generate-event ................ Generate event
info .......................... Display information about the service
install ....................... Install a Serverless service from GitHub or a plugin from the Serverless registry
invoke ........................ Invoke a deployed function
invoke local .................. Invoke function locally
login ......................... Login or sign up for Serverless
logout ........................ Logout from Serverless
logs .......................... Output the logs of a deployed function
metrics ....................... Show metrics for a specific function
output ........................
output get .................... Get value of dashboard deployment profile parameter
output list ................... List all dashboard deployment profile parameters
package ....................... Packages a Serverless service
param .........................
param get ..................... Get value of dashboard service output
param list .................... List all dashboard service outputs
plugin ........................ Plugin management for Serverless
plugin install ................ Install and add a plugin to your service
plugin uninstall .............. Uninstall and remove a plugin from your service
plugin list ................... Lists all available plugins
plugin search ................. Search for plugins
print ......................... Print your compiled and resolved config file
remove ........................ Remove Serverless service and all resources
rollback ...................... Rollback the Serverless service to a specific deployment
rollback function ............. Rollback the function to a specific version
ses-template .................. Manage AWS SES templates
ses-template deploy ........... Sync email templates to AWS SES
ses-template delete ........... Delete email template from AWS SES by given name
ses-template list ............. List email templates from AWS SES
slstats ....................... Enable or disable stats
studio ........................ Develop a Serverless application in the cloud.
test .......................... Run HTTP tests
Plugins
DynamoDBAutoscaling, ServerlessSesTemplate
Commands by plugin
ServerlessSesTemplate
ses-template .................. Manage AWS SES templates
ses-template deploy ........... Sync email templates to AWS SES
ses-template delete ........... Delete email template from AWS SES by given name
ses-template list ............. List email templates from AWS SES