Truffle uses lerna to manage multi-package repositories. Each Truffle module is defined in its own npm package in the packages/ directory.
The entry point of these modules is truffle-core. This is where the command line parser is setup.
Install lerna:
$ npm install -g lerna
$ npm install -g yarn$ lerna create truffle-mycmd$ lerna add truffle-mycmd --scope=truffle-coreCreate a new file in packages/truffle-core/lib/commands/, let's call it mycmd.js.
$ cat << EOF > truffle-core/lib/commands/mycmd.js
const command = {
command: "mycmd",
description: "Run mycmd",
builder: {},
help: {
usage: "truffle mycmd",
options: []
},
run: function(options, done) {
const mycmd = require("truffle-mycmd");
// TODO: write the run command here, something like:
// mycmd(options, done)
}
};
module.exports = command;
EOF--- packages/truffle-core/lib/commands/index.js
+++ packages/truffle-core/lib/commands/index.js
@@ -1,4 +1,5 @@
module.exports = {
+ mycmd: require("./mycmd"),From there, you should see it in the help screen:
$ cd packages/truffle-core
$ node cli.js
Truffle v5.0.0-beta.1 - a development framework for Ethereum
Usage: truffle <command> [options]
Commands:
mycmd Run mycmd
build Execute build pipeline (if configuration present)
[...]The setup is done, you can now write your command and organize your module as you want in: packages/truffle-mycmd/. You can have a look at packages/truffle-box/ which is a good starting example to follow.