Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): Better CLI args validation #1234

Merged
merged 1 commit into from
Jul 16, 2015

Conversation

srawlins
Copy link
Contributor

@srawlins srawlins commented Nov 4, 2014

Start adding better CLI args validation (#603). Validate log-level to start. This doesn't close the issue.

@maksimr
Copy link
Contributor

maksimr commented Nov 4, 2014

LGTM

@@ -33,6 +33,9 @@ var processArgs = function(argv, options, fs, path) {

if (helper.isString(options.logLevel)) {
options.logLevel = constant['LOG_' + options.logLevel.toUpperCase()] || constant.LOG_DISABLE;
} else if (helper.isDefined(options.logLevel)) {
console.error('Log level must be one of disable, error, warn, info, or debug.');
Copy link
Contributor

Choose a reason for hiding this comment

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

How about changing

exports.LOG_DISABLE = 'OFF';
exports.LOG_ERROR   = 'ERROR';
exports.LOG_WARN    = 'WARN';
exports.LOG_INFO    = 'INFO';
exports.LOG_DEBUG   = 'DEBUG';

in constants.js to:

exports.LOG.DISABLE = 'OFF';
exports.LOG.ERROR   = 'ERROR';
exports.LOG.WARN    = 'WARN';
exports.LOG.INFO    = 'INFO';
exports.LOG.DEBUG   = 'DEBUG';

Then we can get here something like this

Object.keys(require('constants').LOG)
.map(Function.prototype.call.bind(String.prototype.toLowerCase)).join(', ')

than our knowledge will be in one place constants.js, if we add new log level then it immediately appear here.

Copy link
Contributor

Choose a reason for hiding this comment

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

@maksimr good idea, let's do it in a separate PR.

@dignifiedquire
Copy link
Member

Yes please. @srawlins could you please do what @vojtajina and just print the warning and not exit. Other than that I'm happy to get this in.

@dignifiedquire
Copy link
Member

@srawlins ping

@srawlins
Copy link
Contributor Author

srawlins commented Jun 3, 2015

Eek, sorry. I'm on vacation for 2 more weeks. Back in late June.
On Jun 3, 2015 9:26 PM, "Friedel Ziegelmayer" notifications@github.com
wrote:

@srawlins https://github.com/srawlins ping


Reply to this email directly or view it on GitHub
#1234 (comment).

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@srawlins srawlins force-pushed the cli-args-validation branch from aee30e7 to 205fbba Compare July 15, 2015 22:59
@srawlins
Copy link
Contributor Author

OK changed behavior to exit on unrecognized log levels, and added a test. Ready for review again. Sorry for the absurd delay 😟

}
} else if (helper.isDefined(options.logLevel)) {
console.error('Log level must be one of disable, error, warn, info, or debug.');
process.exit(1);
Copy link
Member

Choose a reason for hiding this comment

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

This could be simpler, I think something like

var logLevel = options.logLevel

if (helper.isString(options.logLevel)) {
  logLevel = constant['LOG_' + options.logLevel.toUpperCase()]
}

if (!helper.isDefined(logLevel)) {
  console.error('Log level must be one of disable, error, warn, info, or debug.');
  process.exit(1);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, if logLevel is not defined (i.e. options.logLevel is not defined), this is valid. It just means the user did not pass a --log-level argument.

Start adding better CLI args validation (karma-runner#603). Validate log-level to start.
@srawlins srawlins force-pushed the cli-args-validation branch from 205fbba to 73d31c2 Compare July 16, 2015 17:17
@srawlins
Copy link
Contributor Author

I fixed the lint warnings and there is still a Travis failure that I don't think is related to this PR because it's sporadic. Travis builds #1600 and #1601. It passes for me locally.

@dignifiedquire
Copy link
Member

Thanks, looks good to me :octocat:

dignifiedquire added a commit that referenced this pull request Jul 16, 2015
feat(cli): Better CLI args validation
@dignifiedquire dignifiedquire merged commit 35a0dcf into karma-runner:master Jul 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants