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

Add a command to negate the exit code of some other command #173

Open
Shayan-To opened this issue Feb 5, 2020 · 1 comment
Open

Add a command to negate the exit code of some other command #173

Shayan-To opened this issue Feb 5, 2020 · 1 comment
Labels

Comments

@Shayan-To
Copy link

I couldn't find any way to do this in a cross-platform way. POSIX shell has the ! operator that can do that, but I couldn't find a way to do it on Windows. It could work like an exec command that negates the exit code of the execution.

Sample use case: Stop a commit using husky if any file contains string DO_NOT_COMMIT_THIS. "pre-commit": "shx not grep -rq DO_NOT_COMMIT_THIS ."

@nfischer nfischer added the feat label Feb 5, 2020
@nfischer
Copy link
Member

nfischer commented Feb 5, 2020

I don't think this is currently possible in shx. We support shx true and shx false (and the OS will support && and ||), but I believe these are not enough to implement negation.

We could support a shx --negate flag to logically negate exit codes. Would you be interested in sending a PR? We would want to check for the flag value here:

shx/src/shx.js

Lines 92 to 93 in 7e7bf7f

// Set shell.config with parsed options
Object.assign(shell.config, parsedArgs);

And then invert the exit code here:

shx/src/shx.js

Lines 118 to 125 in 7e7bf7f

if (typeof code === 'number') {
return code;
} else if (shell.error()) {
/* istanbul ignore next */
return EXIT_CODES.CMD_FAILED;
}
return EXIT_CODES.SUCCESS;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants