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

Adding a global --negate flag #189

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Adding a global --negate flag #189

wants to merge 6 commits into from

Conversation

SoTrx
Copy link

@SoTrx SoTrx commented Jul 26, 2021

Hi,
I recently used shx and came across the problem of negating a condition.
So, referencing this #173, I implemented a global --negate flag.

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;
Copy link
Member

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);

Copy link
Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@nfischer nfischer left a 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!

@@ -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');
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

Will do !

const wNegate = cli('--negate', 'test', '-d', 'fakeDirName');
wNegate.stdout.should.equal('');
wNegate.stderr.should.equal('');
wNegate.code.should.equal(0);
Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

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

Done !

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.

2 participants