-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feat(cli): Better CLI args validation #1234
Conversation
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.'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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. |
@srawlins ping |
Eek, sorry. I'm on vacation for 2 more weeks. Back in late June.
|
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.
|
aee30e7
to
205fbba
Compare
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); |
There was a problem hiding this comment.
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);
}
There was a problem hiding this comment.
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.
205fbba
to
73d31c2
Compare
Thanks, looks good to me |
feat(cli): Better CLI args validation
Start adding better CLI args validation (#603). Validate log-level to start. This doesn't close the issue.