-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
expose the error
utility (in src/utils.js)
#54
Comments
paulovieira
added a commit
to paulovieira/sade
that referenced
this issue
Jul 11, 2022
For anyone interested in using this feature: a simple alternative is to extract the code from the function cliError(bin, str, num=1) {
const __ = ' ';
const NL = '\n';
let section = function section(str, arr) {
if (!arr || !arr.length) return '';
let i=0, out='';
out += (NL + __ + str);
for (; i < arr.length; i++) {
out += (NL + __ + __ + arr[i]);
}
return out + NL;
}
let out = section('ERROR', [str]);
out += (NL + __ + `Run \`$ ${bin} --help\` for more info.` + NL);
console.error(out);
process.exit(num);
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The error utility is used internally for cases like this:
https://github.com/lukeed/sade/blob/master/src/utils.js#L79-L84
But even if all the options are accepted by sade, they might not be valid (example: 2 options might conflict with each other). The user is responsible for these app-specific validations.
It would then be useful if sade could provide a
prog.error(message)
.Thanks for considering this.
UPDATE: I've made a fork for personal use where this feature is implemented. Is there any interest in a PR?
paulovieira@cd26309
UPDATE 2: below is the sade template that I'm using for my cli applications. Notice the call to the new
prog.error
utility (after the call tovalidateArgs
), which would output this:The text was updated successfully, but these errors were encountered: