Skip to content
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

[Feature] Custom CLI plugin commands #6901

Open
wants to merge 47 commits into
base: master
Choose a base branch
from

Conversation

bonaccorsop
Copy link

@bonaccorsop bonaccorsop commented Oct 31, 2018

With this feature, plugins can register their own cli commands (according to the 6th point of @Radiergummi feature request #5734).

You can call the plugin command by executing:

./nodebb cmd <plugin-name>:<custom-command> [options]

You can register your plugin command in plugin.json with the commands block

plugin.json

...
"commands": [
  {
    "cmd": "custom-command",
    "library": "./cmd.js",
    "method": "callMyCommand",
    "description": "This is a command example",
    "options": [
	{ "flags": "-m, --myoption1", "description": "Option 1"},
	{ "flags": "-n, --myoption2", "description": "Option 2"}
     ]
  }
 ]

In this scenario, NodeBB will call your cmd.js script and will call the callMyMethod function.
The script file will be like this:

cmd.js

"use strict";

module.exports = {

  callMyMethod: function (options, done) {
    // ... do my stuff
    console.log('Command executed!');
    done();
  },

}

This feature uses the NodeBB embedded commander.js for registering custom command.
You can have the plugin commands list executing:

./nodebb cmd --help

@julianlam
Copy link
Member

Interesting... any reason why you have to define lib and not assume the same library value defined in parent?

@bonaccorsop
Copy link
Author

You're absolutely right...
Library should be optional and the same library should be the default script.
I'll update this feature with this specification

@bonaccorsop
Copy link
Author

bonaccorsop commented Oct 31, 2018

Ok, now the field library is optional.
The default script file is the plugin library (the easiest way)
ef1859e

src/cmd/init.js Outdated Show resolved Hide resolved
nodebb Outdated Show resolved Hide resolved
src/cmd/bootstrap.js Outdated Show resolved Hide resolved
src/cmd/init.js Outdated Show resolved Hide resolved
src/cli/cmd.js Outdated Show resolved Hide resolved
src/cli/cmd.js Outdated Show resolved Hide resolved
src/cli/cmd.js Outdated Show resolved Hide resolved
src/cli/cmd.js Outdated Show resolved Hide resolved
src/cli/cmd.js Outdated Show resolved Hide resolved
src/cli/cmd.js Outdated Show resolved Hide resolved
@bonaccorsop
Copy link
Author

bonaccorsop commented Nov 5, 2018

Seems like that build for commit b351997 fails for a misconfiguration
https://travis-ci.org/NodeBB/NodeBB/jobs/450856577

src/cli/cmd.js Outdated Show resolved Hide resolved
src/cli/cmd.js Outdated Show resolved Hide resolved
@pitaj
Copy link
Contributor

pitaj commented Nov 5, 2018

Nothing sticks out to me now. When I get home I'm going to take one last look and try it out, then we'll merge it tomorrow probably.

Thanks for sticking through all of my nit-picking!

@bonaccorsop
Copy link
Author

Nothing sticks out to me now. When I get home I'm going to take one last look and try it out, then we'll merge it tomorrow probably.

Thanks for sticking through all of my nit-picking!

Has been a great pleasure.
I can write docs about this feature if you want

@bonaccorsop
Copy link
Author

bonaccorsop commented Nov 6, 2018

Suddenly with git style subcommands options are not parsed...
Tomorrow I'll search a solution.

@pitaj
Copy link
Contributor

pitaj commented Dec 14, 2018

Did you ever discover what if anything was wrong with the subcommands?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants