Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Add --url option to the truffle migrate command #5739

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from
18 changes: 16 additions & 2 deletions packages/core/lib/commands/migrate/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ module.exports = {
type: "boolean",
default: true,
hidden: true
},
"url": {
describe: "Use specified URL for provider",
lsqproduction marked this conversation as resolved.
Show resolved Hide resolved
type: "string"
}
},
help: {
Expand All @@ -62,7 +66,7 @@ module.exports = {
" " + // spacing to align with previous line
"[--compile-all] [--compile-none] [--verbose-rpc] [--interactive]\n" +
" " + // spacing to align with previous line
"[--skip-dry-run] [--describe-json] [--dry-run]",
"[--skip-dry-run] [--describe-json] [--dry-run] [--network <network>|--url <provider_url>]",
lsqproduction marked this conversation as resolved.
Show resolved Hide resolved
options: [
{
option: "--reset",
Expand Down Expand Up @@ -118,8 +122,18 @@ module.exports = {
option: "--save",
description: "Specify whether the migration will save on chain",
hidden: true
},
{
option: "--url",
description:
"Creates a provider using the given url and connects to the network."
},
{
option: "--network",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about why you prefer --network lives here vs with the other global options.

Actually, can url be a global option as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global options generally appends the options at the end of the usage. The reason behind keeping --network and --url options here rather than in the global options, is to show that they are mutually exclusive.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okie. thank you for the explanation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add a note in each of these letting the user know that these options are mutually exclusive? do you think that would be helpful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usage section shows that they are mutually exclusive but if adding a note in the descriptions is preferable, then we can add it here too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whatever you think, I don't feel strongly about it :)

description:
"The network to connect to, as specified in the Truffle config."
}
],
allowedGlobalOptions: ["network", "config", "quiet"]
allowedGlobalOptions: ["config", "quiet"]
}
};
18 changes: 16 additions & 2 deletions packages/core/lib/commands/migrate/run.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
module.exports = async function (options) {
const WorkflowCompile = require("@truffle/workflow-compile").default;
const { Environment } = require("@truffle/environment");
const Config = require("@truffle/config");
const determineDryRunSettings = require("./determineDryRunSettings");
const prepareConfigForRealMigrations = require("./prepareConfigForRealMigrations");
const runMigrations = require("./runMigrations");
const setUpDryRunEnvironmentThenRunMigrations = require("./setUpDryRunEnvironmentThenRunMigrations");
const loadConfig = require("../../loadConfig");
const OS = require("os");
const TruffleError = require("@truffle/error");
const tmp = require("tmp");
tmp.setGracefulCleanup();

const config = Config.detect(options);
if (options.url && options.network) {
const message =
"" +
"Mutually exclusive options, --url and --network detected!" +
OS.EOL +
"Please use either --url or --network and try again." +
OS.EOL +
"See: https://trufflesuite.com/docs/truffle/reference/truffle-commands/#migrate" +
OS.EOL;
throw new TruffleError(message);
}
cds-amal marked this conversation as resolved.
Show resolved Hide resolved

let config = loadConfig(options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use const here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Yes, we can use const here.

if (config.compileNone || config["compile-none"]) {
config.compiler = "none";
}
Expand Down
10 changes: 10 additions & 0 deletions packages/truffle/test/scenarios/commands/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,15 @@ describe("truffle migrate", () => {
assert.fail();
}
}).timeout(20000);

it("doesn't throw when --url option is passed", async () => {
try {
await CommandRunner.run("migrate --url http://127.0.0.1:8545", config);
} catch (error) {
console.log("the logger contents -- %o", config.logger.loggedStuff);
console.log("the following error occurred -- %o", error.message);
assert.fail();
}
}).timeout(20000);
});
});