mirror of https://github.com/embarklabs/embark.git
warn of contract typos
This commit is contained in:
parent
c63c9b8728
commit
535340794b
|
@ -1,6 +1,6 @@
|
|||
const program = require('commander');
|
||||
const promptly = require('promptly');
|
||||
const propose = require('propose');
|
||||
const utils = require('./utils/utils.js');
|
||||
const Embark = require('../lib/index');
|
||||
let embark = new Embark;
|
||||
|
||||
|
@ -173,7 +173,7 @@ class Cmd {
|
|||
.action(function (cmd) {
|
||||
console.log('unknown command "%s"'.red, cmd);
|
||||
let dictionary = ['new', 'demo', 'build', 'run', 'blockchain', 'simulator', 'test', 'upload', 'version' ];
|
||||
let suggestion = propose(cmd, dictionary, {threshold: 0.3});
|
||||
let suggestion = utils.proposeAlternative(cmd, dictionary);
|
||||
if (suggestion) {
|
||||
console.log('did you mean "%s"?'.green, suggestion);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ let toposort = require('toposort');
|
|||
let async = require('async');
|
||||
|
||||
let Compiler = require('./compiler.js');
|
||||
let utils = require('../utils/utils.js');
|
||||
|
||||
// TODO: create a contract object
|
||||
|
||||
|
@ -80,6 +81,7 @@ class ContractsManager {
|
|||
/*eslint complexity: ["error", 11]*/
|
||||
function dealWithSpecialConfigs(callback) {
|
||||
let className, contract, parentContractName, parentContract;
|
||||
let dictionary = Object.keys(self.contracts);
|
||||
|
||||
for (className in self.contracts) {
|
||||
contract = self.contracts[className];
|
||||
|
@ -98,6 +100,10 @@ class ContractsManager {
|
|||
|
||||
if (parentContract === undefined) {
|
||||
self.logger.error(className + ": couldn't find instanceOf contract " + parentContractName);
|
||||
let suggestion = utils.proposeAlternative(className, dictionary, [className, parentContractName]);
|
||||
if (suggestion) {
|
||||
self.logger.warn('did you mean "' + suggestion + '"?');
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -124,11 +130,16 @@ class ContractsManager {
|
|||
},
|
||||
function removeContractsWithNoCode(callback) {
|
||||
let className, contract;
|
||||
let dictionary = Object.keys(self.contracts);
|
||||
for (className in self.contracts) {
|
||||
contract = self.contracts[className];
|
||||
|
||||
if (contract.code === undefined) {
|
||||
self.logger.error(className + " has no code associated");
|
||||
let suggestion = utils.proposeAlternative(className, dictionary, [className]);
|
||||
if (suggestion) {
|
||||
self.logger.warn('did you mean "' + suggestion + '"?');
|
||||
}
|
||||
delete self.contracts[className];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ let http = require('follow-redirects').http;
|
|||
let https = require('follow-redirects').https;
|
||||
let shelljs = require('shelljs');
|
||||
var tar = require('tar');
|
||||
var propose = require('propose');
|
||||
|
||||
//let fs = require('../core/fs.js');
|
||||
let o_fs = require('fs-extra');
|
||||
|
@ -103,6 +104,14 @@ function extractTar(filename, packageDirectory, cb) {
|
|||
);
|
||||
}
|
||||
|
||||
function proposeAlternative(word, _dictionary, _exceptions) {
|
||||
let exceptions = _exceptions || [];
|
||||
let dictionary = _dictionary.filter((entry) => {
|
||||
return exceptions.indexOf(entry) < 0;
|
||||
});
|
||||
return propose(word, dictionary, {threshold: 0.3});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
joinPath: joinPath,
|
||||
filesMatchingPattern: filesMatchingPattern,
|
||||
|
@ -116,5 +125,6 @@ module.exports = {
|
|||
sed: sed,
|
||||
exit: exit,
|
||||
downloadFile: downloadFile,
|
||||
extractTar: extractTar
|
||||
extractTar: extractTar,
|
||||
proposeAlternative: proposeAlternative
|
||||
};
|
||||
|
|
|
@ -44,6 +44,9 @@
|
|||
"AlreadyDeployedToken": {
|
||||
"address": "0xece374063fe5cc7efbaca0a498477cada94e5ad6",
|
||||
"instanceOf": "Token"
|
||||
},
|
||||
"MyToken3": {
|
||||
"instanceOf": "Tokn"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue