-
Notifications
You must be signed in to change notification settings - Fork 45
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
Adding a global --negate flag #189
base: main
Are you sure you want to change the base?
Conversation
src/shx.js
Outdated
@@ -115,6 +115,11 @@ export function shx(argv) { | |||
code = ret ? 0 : 1; | |||
} | |||
|
|||
// Check for negation flag, and flip the code value | |||
if (parsedArgs.negate === true) { | |||
code = (code + 1) % 2; |
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 is a little confusing to read. How about this instead?
code = Number(!code);
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.
Done
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.
Thank you for the PR!
test/specs/cli.js
Outdated
@@ -134,6 +134,15 @@ describe('cli', () => { | |||
output.code.should.equal(2); | |||
}); | |||
|
|||
it('uses --negate to allows for "not" conditions ', () => { | |||
const woNegate = cli('test', '-d', 'fakeDirName'); |
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.
nit: please spell out "without" and "with" in the variable names. It just helps with readability a bit.
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.
Will do !
test/specs/cli.js
Outdated
const wNegate = cli('--negate', 'test', '-d', 'fakeDirName'); | ||
wNegate.stdout.should.equal(''); | ||
wNegate.stderr.should.equal(''); | ||
wNegate.code.should.equal(0); |
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.
Can you add another test case where the command normally succeeds but --negate
gives it a status of 1
? The true
command should be a good example to use for that case.
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.
Done !
Hi,
I recently used shx and came across the problem of negating a condition.
So, referencing this #173, I implemented a global --negate flag.