Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dab1982

Browse filesBrowse files
committed
refactor: code cleanup for the --negate flag
No change to logic. This is a small refactor/cleanup for the '--negate' option added in PR #189. This also adds documentation to the README.
1 parent 6184003 commit dab1982
Copy full SHA for dab1982

File tree

Expand file treeCollapse file tree

2 files changed

+14
-11
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+14
-11
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ $ shx rm -r sub # options work as well
6060

6161
$ shx --silent ls fakeFileName # silence error output
6262

63-
$ shx --negate test -d dir # Negate status code output for boolean conditions
63+
$ shx --negate test -d dir # Negate status code output (e.g., failed commands will now have status 0)
6464
```
6565

6666
All commands internally call the ShellJS corresponding function, guaranteeing
@@ -145,10 +145,13 @@ supported options:
145145

146146
| [`set`](https://github.com/shelljs/shelljs#setoptions) flag | [`shell.config`](https://github.com/shelljs/shelljs#configuration) setting | shx command | Effect |
147147
|:---:| --- | --- | --- |
148-
| `-e` | `config.fatal = true` | Not supported | Exit upon first error |
149-
| `-v` | `config.verbose = true` | `shx --verbose cd foo` | Log the command as it's run |
150-
| `-f` | `config.noglob = true` | `shx --noglob cat '*.txt'` | Don't expand wildcards |
151-
| N/A | `config.silent = true` | `shx --silent cd noexist` | Don't show error output |
148+
| `-e` | `config.fatal = true` | Not supported | Exit upon first error. |
149+
| `-v` | `config.verbose = true` | `shx --verbose cd foo` | Log the command as it's run. |
150+
| `-f` | `config.noglob = true` | `shx --noglob cat '*.txt'` | Don't expand wildcards. |
151+
| N/A | `config.silent = true` | `shx --silent cd noexist` | Don't show error output. |
152+
| N/A | N/A | `shx --negate test -d dir` | Runs the specified command but negates the exit status. Failed command = status 0, successful command = status 1. |
153+
| N/A | N/A | `shx --help` | Show help text. |
154+
| N/A | N/A | `shx --version` | Print the shx version. |
152155

153156
## Team
154157

‎test/specs/cli.js

Copy file name to clipboardExpand all lines: test/specs/cli.js
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,11 @@ describe('cli', () => {
145145

146146
it('uses --negate to "NOT" a "0 output ', () => {
147147
const withoutNegate = cli('true');
148-
// Sanity check
149148
withoutNegate.code.should.equal(0);
150-
// Minifist opts.boolean always treat --* as boolean
151-
// Thus only using "--negate true" will be interpreted as "--negate=true"
152-
// without any actual command. Hence --negate true true
153-
const withNegate = cli('--negate', 'true', 'true');
149+
// We need an extra '--' otherwise Minimist will interprt this like `shx
150+
// --negate=true` without invoking the actual 'true' subcommand. This is
151+
// because of Minimist's opts.boolean option.
152+
const withNegate = cli('--negate', '--', 'true');
154153
withNegate.stdout.should.equal('');
155154
withNegate.stderr.should.equal('');
156155
withNegate.code.should.equal(1);
@@ -160,8 +159,9 @@ describe('cli', () => {
160159
const output = cli('help');
161160
output.stderr.should.equal('');
162161
output.stdout.should.match(/Usage/); // make sure help is printed
163-
output.stdout.should.match(/\* --verbose/);
162+
output.stdout.should.match(/\* --negate/);
164163
output.stdout.should.match(/\* --silent/);
164+
output.stdout.should.match(/\* --verbose/);
165165
output.stdout.should.match(/\* --version/);
166166
});
167167
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.