Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Avoid showing variable name on prompt message if not available #1224

Merged
merged 3 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ function getCommandProps(): InquirerQuestions {
name: {
message: 'Welcome to the OpenZeppelin SDK! Choose a name for your project',
type: 'input',
validate: notEmpty
validate: notEmpty,
},
version: {
message: 'Initial project version',
type: 'input',
validate: input => {
if (semver.parse(input)) return true;
return `Invalid semantic version: ${input}`;
}
},
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ class SolidityContractsCompiler {
const output = solcOutput.contracts[fileName][contractName];
const source = solcOutput.sources[fileName];
fileName = path.basename(fileName);
const contract = this.contracts.find(
aContract => aContract.fileName === fileName,
);
const contract = this.contracts.find(aContract => aContract.fileName === fileName);

return {
fileName,
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/models/dependency/Dependency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export default class Dependency {
const hasDependenciesForDeploy = dependencies.find(
(depNameAndVersion): any => {
const dependency = Dependency.fromNameWithVersion(depNameAndVersion);
return !(dependency.isDeployedOnNetwork(network) || networkFile.dependencyHasMatchingCustomDeploy(dependency.name));
return !(
dependency.isDeployedOnNetwork(network) || networkFile.dependencyHasMatchingCustomDeploy(dependency.name)
);
},
);

Expand Down
9 changes: 7 additions & 2 deletions packages/cli/src/models/local/KitController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import child from '../../utils/child';
const simpleGit = patch('simple-git/promise');

export default class KitController {
public async unpack(url: string, branchName: string = 'stable', workingDirPath: string = '', config: KitFile): Promise<void | never> {
public async unpack(
url: string,
branchName: string = 'stable',
workingDirPath: string = '',
config: KitFile,
): Promise<void | never> {
if (!url) throw Error('A url must be provided.');
if (!config) throw Error('A config must be provided.');

Expand Down Expand Up @@ -45,7 +50,7 @@ export default class KitController {
// always delete .git folder
await remove(path.join(workingDirPath, '.git'));
// run kit commands like `npm install`
await exec(config.hooks['post-unpack'], { maxBuffer: 1024 * 1024 * 100});
await exec(config.hooks['post-unpack'], { maxBuffer: 1024 * 1024 * 100 });
Loggy.succeed('unpack-kit', 'Kit downloaded and unpacked');

Loggy.noSpin(__filename, 'unpack', 'unpack-succeeded', `The kit is ready to use. \n${config.message}`);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/prompts/method-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function getCommandProps(
return {
...accum,
[arg.name]: {
message: `${arg.name} (${arg.type}):`,
message: arg.name ? `${arg.name} (${arg.type}):` : `(${arg.type}):`,
type: 'input',
when: () => !methodArgs || !methodArgs[index],
validate: input => {
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/src/prompts/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export function methodsList(
return contractMethods(contractFullName, constant, projectFile)
.map(({ name, hasInitializer, inputs, selector }) => {
const initializable = hasInitializer ? '* ' : '';
const args = inputs.map(({ name: inputName, type }) => `${inputName}: ${type}`);
const args = inputs.map(({ name: inputName, type }) => (inputName ? `${inputName}: ${type}` : type));
const label = `${initializable}${name}(${args.join(', ')})`;

return { name: label, value: { name, selector } };
Expand All @@ -198,7 +198,13 @@ export function argsList(
const method = contractMethods(contractFullName, constant, projectFile).find(
({ name, selector }): any => selector === methodIdentifier || name === methodIdentifier,
);
return method ? method.inputs : [];

if (method) {
return method.inputs.map((input, index) => {
return input.name ? input : { ...input, name: `#${index}` };
});
}
return [];
}

function contractMethods(
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/prompts/validators.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function notEmpty(input) {
if (input && input.length > 0) return true;
return "Please enter a non-empty value";
}
return 'Please enter a non-empty value';
}
2 changes: 2 additions & 0 deletions packages/cli/test/mocks/mock-stdlib/contracts/GreeterImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import "./GreeterLib.sol";

contract GreeterImpl {
using GreeterLib for string;

mapping(uint256 => string) public greetings;
event Greeting(string greeting);

function greet(string memory who) public {
Expand Down
Loading