dojo / cli

:rocket: Dojo - command line tooling.
http://dojo.io
Other
26 stars 34 forks source link

Type mistmatch between return types of ValidateHelper and validate #272

Closed JamesLMilner closed 5 years ago

JamesLMilner commented 5 years ago

Bug

There is currently a mismatch between the a commands .validate method and the ValidateHelper. .validate returns type of boolean but the ValidateHelper returns a Promise, meaning you can't use the helper in a command. Making .validate async would fix this issue.

Code

    validate(helper: Helper) {
        let schema;
        try {
            schema = JSON.parse(readFileSync(path.join(__dirname, 'schema.json')).toString());
        } catch (error) {
            return Promise.reject(Error('The dojorc schema for cli-build-app could not be read: ' + error));
        }
        return helper.validation.validate({
            commandGroup: command.group as string,
            commandName: command.name,
            commandSchema: schema,
            commandConfig: helper.configuration.get(),
            silentSuccess: true
        });
    }

Expected behavior:

You should be able to use the provided ValidateHelper in the .validate function.

Actual behavior:

ValidateHelper is async which stops it from being useable.

screenshot_20181130_113710