From a04c593f311a00525b0abed50138c684ccdfcada Mon Sep 17 00:00:00 2001 From: Pim Otte Date: Tue, 8 Aug 2017 17:36:23 +0200 Subject: [PATCH 1/5] Adding help flag to allow users to discover options in cli --- lib/command.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/command.js b/lib/command.js index 81be0a3..86867bc 100644 --- a/lib/command.js +++ b/lib/command.js @@ -11,6 +11,7 @@ function Command(commands) { args = args.command(commands[command]); }); + args = args.help(); this.args = args; }; From 72366e1b1a5a288b18dafc71991a7996941b8dec Mon Sep 17 00:00:00 2001 From: Pim Otte Date: Sat, 12 Aug 2017 19:16:41 +0200 Subject: [PATCH 2/5] Create's --all flag doesn't seem to do anything. --- lib/commands/create.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/commands/create.js b/lib/commands/create.js index 4e1772a..a9764c3 100644 --- a/lib/commands/create.js +++ b/lib/commands/create.js @@ -1,12 +1,7 @@ var command = { command: 'create', description: 'Helper to create new contracts, migrations and tests', - builder: { - all: { - type: "boolean", - default: false - } - }, + builder: {}, run: function (options, done) { var Config = require("truffle-config"); var ConfigurationError = require("../errors/configurationerror"); From 92f70f46d9db60f4a08a8e3e59217db8f0e083ca Mon Sep 17 00:00:00 2001 From: Pim Otte Date: Sat, 12 Aug 2017 19:35:31 +0200 Subject: [PATCH 3/5] Documenting options in yargs structure to show in help --- lib/commands/compile.js | 6 ++++++ lib/commands/console.js | 12 +++++++++++- lib/commands/create.js | 2 +- lib/commands/exec.js | 12 +++++------- lib/commands/migrate.js | 12 +++++++++++- lib/commands/serve.js | 5 +++++ lib/commands/test.js | 18 +++++++++++++++++- package.json | 2 +- 8 files changed, 57 insertions(+), 12 deletions(-) diff --git a/lib/commands/compile.js b/lib/commands/compile.js index 9ec3b39..15adc42 100644 --- a/lib/commands/compile.js +++ b/lib/commands/compile.js @@ -5,6 +5,11 @@ var command = { all: { type: "boolean", default: false + }, + network: { + type: 'string', + description: 'Specify the network to use, saving artifacts specific to that network', + default: 'development' } }, run: function (options, done) { @@ -13,6 +18,7 @@ var command = { var config = Config.detect(options); Contracts.compile(config, done); + console.log(config.network()) } } diff --git a/lib/commands/console.js b/lib/commands/console.js index 9a9f03c..2681ad2 100644 --- a/lib/commands/console.js +++ b/lib/commands/console.js @@ -1,7 +1,17 @@ var command = { command: 'console', description: 'Run a console with contract abstractions and commands available', - builder: {}, + builder: { + 'verbose-rpc' : { + type: 'boolean', + default: false + }, + 'network' : { + type: 'string', + description: 'Specify the network to use, saving artifacts specific to that network', + default: 'development' + } + }, run: function (options, done) { var Config = require("truffle-config"); var Console = require("../console"); diff --git a/lib/commands/create.js b/lib/commands/create.js index a9764c3..8ce8fa4 100644 --- a/lib/commands/create.js +++ b/lib/commands/create.js @@ -1,5 +1,5 @@ var command = { - command: 'create', + command: 'create ', description: 'Helper to create new contracts, migrations and tests', builder: {}, run: function (options, done) { diff --git a/lib/commands/exec.js b/lib/commands/exec.js index 8882913..7cf81a4 100644 --- a/lib/commands/exec.js +++ b/lib/commands/exec.js @@ -1,9 +1,11 @@ var command = { - command: 'exec', + command: 'exec ', description: 'Execute a JS module within this Truffle environment', builder: { - file: { - type: "string" + network: { + description: 'Specify the network to use, using artifacts specific to that network.', + type: 'string', + default: 'development' } }, run: function (options, done) { @@ -18,10 +20,6 @@ var command = { var file = options.file; - if (file == null && options._.length > 0) { - file = options._[0]; - } - if (file == null) { done(new ConfigurationError("Please specify a file, passing the path of the script you'd like the run. Note that all scripts *must* call process.exit() when finished.")); return; diff --git a/lib/commands/migrate.js b/lib/commands/migrate.js index c76c914..276e5ee 100644 --- a/lib/commands/migrate.js +++ b/lib/commands/migrate.js @@ -4,10 +4,11 @@ var command = { builder: { reset: { type: "boolean", + describe: 'Run all migrations from the beginning, instead of running from the last completed migration', default: false }, "compile-all": { - describe: "recompile all contracts", + describe: "Recompile all contracts", type: "boolean", default: false }, @@ -19,6 +20,15 @@ var command = { f: { describe: "Specify a migration number to run from", type: "number" + }, + network: { + describe: "Network to deploy to", + type: "string" + }, + 'verbose-rpc': { + describe: 'Log communication between Truffle and the RPC.', + type: "boolean", + default: false } }, run: function (options, done) { diff --git a/lib/commands/serve.js b/lib/commands/serve.js index 010d923..45c8546 100644 --- a/lib/commands/serve.js +++ b/lib/commands/serve.js @@ -5,6 +5,11 @@ var command = { port: { alias: "p", default: "8080" + }, + network: { + type: 'string', + description: 'Specify the network to use, using artifacts specific to that network', + default: 'development' } }, run: function (options, done) { diff --git a/lib/commands/test.js b/lib/commands/test.js index d2da0a2..8f5b808 100644 --- a/lib/commands/test.js +++ b/lib/commands/test.js @@ -1,7 +1,23 @@ var command = { command: 'test', description: 'Run Mocha and Solidity tests', - builder: {}, + builder: { + 'compile-all': { + type: 'boolean', + description: 'Compile all contracts instead of intelligently choosing', + default: false + }, + 'verbose-rpc': { + type: 'boolean', + description: 'Log communication between Truffle and the RPC', + default: false + }, + network: { + type: 'string', + description: 'Specify the network to use, using artifacts specific to that network', + default: 'development' + } + }, run: function (options, done) { var OS = require("os"); var dir = require("node-dir"); diff --git a/package.json b/package.json index ddf67e1..e719dfa 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "truffle-resolver": "^4.0.0", "truffle-solidity-utils": "^1.1.0", "web3": "^0.20.1", - "yargs": "^6.6.0" + "yargs": "^8.0.0" }, "bin": { "truffle": "./cli.js", From 217ecb53223c6f3a96600a907050fd794a64e666 Mon Sep 17 00:00:00 2001 From: Pim Otte Date: Sat, 14 Oct 2017 12:46:33 +0200 Subject: [PATCH 4/5] Documenting new commands --- lib/commands/debug.js | 9 +++++---- lib/commands/install.js | 6 +----- lib/commands/opcode.js | 17 ++++------------- lib/commands/unbox.js | 4 ++-- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/lib/commands/debug.js b/lib/commands/debug.js index 4511895..bfeffb5 100644 --- a/lib/commands/debug.js +++ b/lib/commands/debug.js @@ -2,8 +2,9 @@ var command = { command: 'debug', description: 'Interactively debug any transaction on the blockchain (experimental)', builder: { - _: { - type: "string" + "transaction": { + type: "string", + describe: "Hash of transaction to be debugged" } }, run: function (options, done) { @@ -19,11 +20,11 @@ var command = { Environment.detect(config, function(err) { if (err) return done(err); - if (config._.length == 0) { + if (!config.transaction) { return done(new Error("Please specify a transaction hash as the first parameter in order to debug that transaction. i.e., truffle debug 0x1234...")); } - var tx_hash = config._[0]; + var tx_hash = config.transaction; var bugger = new Debugger(config); var lastCommand = "n"; diff --git a/lib/commands/install.js b/lib/commands/install.js index 603ba37..e9ca19d 100644 --- a/lib/commands/install.js +++ b/lib/commands/install.js @@ -1,15 +1,11 @@ var command = { - command: 'install', + command: 'install [packages...]', description: 'Install a package from the Ethereum Package Registry', builder: {}, run: function (options, done) { var Config = require("truffle-config"); var Package = require("../package"); - if (options._ && options._.length > 0) { - options.packages = options._; - } - var config = Config.detect(options); Package.install(config, done); } diff --git a/lib/commands/opcode.js b/lib/commands/opcode.js index 40c78d4..d82b504 100644 --- a/lib/commands/opcode.js +++ b/lib/commands/opcode.js @@ -1,27 +1,18 @@ var command = { - command: 'opcode', - description: 'Print the compiled opcodes for a given contract', - builder: { - all: { - type: "boolean", - default: false - } - }, + command: 'opcode ', + description: 'Print the compiled opcodes for the given contract', + builder: {}, run: function (options, done) { var Config = require("truffle-config"); var TruffleError = require("truffle-error"); var Contracts = require("../contracts"); var CodeUtils = require("truffle-code-utils"); - if (options._.length == 0) { - return done(new TruffleError("Please specify a contract name.")); - } - var config = Config.detect(options); Contracts.compile(config, function(err) { if (err) return done(err); - var contractName = options._[0]; + var contractName = options.contract; var Contract; try { Contract = config.resolver.require(contractName); diff --git a/lib/commands/unbox.js b/lib/commands/unbox.js index 974a33a..3bbbb4c 100644 --- a/lib/commands/unbox.js +++ b/lib/commands/unbox.js @@ -48,7 +48,7 @@ function formatCommands(commands) { } var command = { - command: 'unbox', + command: 'unbox ', description: 'Unbox Truffle project', builder: {}, run: function(options, done) { @@ -60,7 +60,7 @@ var command = { logger: console }); - var url = normalizeURL(options._[0]); + var url = normalizeURL(options.box); Box.unbox(url, config.working_directory, {logger: config.logger}) .then(function(boxConfig) { From 7aadd7931523fe6f9dbb3fb7bdb5ad701c55e154 Mon Sep 17 00:00:00 2001 From: Pim Otte Date: Sat, 14 Oct 2017 16:54:32 +0200 Subject: [PATCH 5/5] Remove debug line that broke stuff --- lib/commands/compile.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/commands/compile.js b/lib/commands/compile.js index 15adc42..28d6dd2 100644 --- a/lib/commands/compile.js +++ b/lib/commands/compile.js @@ -18,7 +18,6 @@ var command = { var config = Config.detect(options); Contracts.compile(config, done); - console.log(config.network()) } }