205 Commits

Author SHA1 Message Date
Nate Fischer
54c1befe94 refactor(parseOptions): better handle errors (#674)
* refactor(parseOptions): better handle errors

For the case where `parseOptions()` is passed a string that does not
start with a hyphen, we should reject this string instead of returning
the same value. This has no change on any other test cases, and should
not affect any commands since we are careful about what input we pass to
`parseOptions()`

This also adjust how we were handling error cases in the function. We
were previously using two different calls to `common.error()`, one for
if `errorOptions` is passed, and one without. This hurts readability,
because it reads like "if we have errorOptions, then this is an error,
and if we don't then it's also an error," instead of the more
appropriate, "we reached an error case and should use errorOptions if
it's available, otherwise we should signal an error without using it."

We do not need to use `errorOptions` for the added call to `error()`,
since this is an error which indicates misuse, and should not be
recoverable.

This adds a test case as well, for a line which was not previously
covered in our tests.

Partial fix for #671

* Refactor parseOptions()

This validates input at the top of `parseOptions()` for type
correctness. This changes `typeof x === 'object'` to `x instanceOf
Object` to improve robustness. Now we can safely use `errorOptions`
knowing that if it has a truthy value, it will be an object, otherwise
we should use defaults instead.

The new tests ensure that we have 100% unit test coverage for this
function.

* Use exceptions, not common.error()s, for internal misuse

* Add common.isObject() helper function

The `isObject()` helper is used throughout common.js to reliably test if
variables are JavaScript objects.
2017-03-08 19:30:56 -08:00
Brandon Freitag
7949759463 Add support for removing fifos (#687)
* Add support for removing fifos in rm

* Add test for removing fifo

* Add mkfifo util for testing

* Use ES5 syntax in utils
2017-03-08 07:33:41 -08:00
Brandon Freitag
5b5a28d2de Fix cp overwriting identical files (#679)
* Implement fix for cp with identical files

* Implement tests for cp with identical files

* Change error message

* Use common.error immediately if the file is identical

* Add test for copying to exact same path
2017-03-07 22:18:43 -08:00
Nate Fischer
b6b2cd84ef fix: convert error output to be consistent cross-platform (#684)
* fix: convert error output to be consistent cross-platform

The error output produced by `shell.error()` or `result.stderr` should
not be inconsistent between platforms. This ensures that path separators
are always printed by ShellJS as `/` instead of as `\` on Windows. This
should allow scripts using ShellJS to be more consistent cross-platform.

We were not previously relying on error output to always be consistent--
only checking its truthiness. Since this was not part of our tested API,
it should be reasonable to change this and release in a patch.

Fixes #681

* Fix broken pushd test case

* Fix TODO in a test case
2017-03-06 00:54:26 -08:00
Nate Fischer
346fca4cb6 test: don't count hard-to-test lines for coverage (#672)
No change in logic.

Add `/* istanbul ignore next */` lines for hard-to-test lines so that
they don't count against us during code coverage.

I've also adjusted comments that I found confusing, and changed some
formatting.

Partial fix for #671
2017-03-04 17:54:43 -08:00
Nate Fischer
5318fdc43a docs: miscellaneous README changes (#661)
- Add @freitagbr to the bottom of the README
 - Remove docs about shjs (it's not well supported)
 - Remove docs about coffeescript (we don't do anything special for
   coffeescript anyway)
 - Modify the section about shelljs/global, since we strongly recommend
   avoiding this now
 - Rewrite the code example to use `require('shelljs')` instead of
   shelljs/global
 - Mention ESLint next to JSHint
 - Reformat sections with long lines to be 80 columns
2017-03-04 01:07:23 -08:00
Nate Fischer
3cd4470be3 refactor: reduce repeated code in which() (#659)
Use path.delimiter instead of explicit conditional. Try to reuse
repeated code blocks.

Fixes #656
2017-03-04 00:14:20 -08:00
Fran Dios
172d0f1543 Modified glob pattern. Fixes #666 (#676) 2017-02-28 17:32:02 -08:00
Fran Dios
df06ac4a8a ls -L (follow symlinks) (#665)
* feat: -L (follow symlinks) option for ls

* test: ls -L option

* docs: Add ls -L option to readme

* fix: ls -L ternary operator

* Revert "test: ls -L option"

This reverts commit dbb057ac087b23aa2c1358018d3c832dd546c5f2.

* test: ls -L option

* test: Remove duplicate test
2017-02-27 20:53:32 -08:00
George Kalpakas
434ed592de docs(chmod): document options argument (#663) 2017-02-20 15:45:46 -08:00
Stanislav Termosa
8dd2488ec5 feature: add -a option for which command (#655)
* feature: add -a option for which command

* chore(test): test which -a with unexisting name

* chore(test): check which -a has same result as regular one

* chord(test): fix errors mentioned by eslint
2017-02-10 10:32:22 -08:00
Brandon Freitag
055156f7f5 Fix find ENOENT (#654)
* Add find: nonexistant path test

* Catch statSync errors, return shell error
2017-02-02 15:21:58 -08:00
Nate Fischer
84ffb386eb chore(lint): Enforce a trailing comma for multi-line (#646) 2017-01-16 12:45:14 -08:00
Nate Fischer
4c48631d74 refactor: create common.execPath (#636)
Switch to using common.execPath instead of process.execPath directly and warn
electron users if we were unable to find the correct path to NodeJS.
2017-01-08 13:52:39 -08:00
Nate Fischer
ac0ff873f1 refactor: add config.reset() and .resetForTesting() (#641)
Add .reset() and .resetForTesting() to shell.config and use .resetForTesting()
as a standard set-up for unit tests.
2017-01-07 22:40:38 -08:00
Nate Fischer
2da9ab55be fix: allow non-normalized paths as input to mkdir (#635)
Adds tests to make sure that non-normalized paths (i.e. path/to/./dir) are
valid for a few commands, including mkdir() which previously failed when given
the -p flag.

Fixes #634
2017-01-07 18:06:15 -08:00
Brandon Freitag
ded1a3e4a3 Fix: rm behavior regarding symlinks (#598)
* Treat files and symlinks separately

* Remove -f flag from dir symlink test

* Simplify control flow
2016-12-08 23:45:35 -08:00
Brandon Freitag
5ded216dc2 Use Object.assign if possible (#593)
* Fix typo

* Set objectAssign to Object.assign if defined

* Use correct terminology
2016-12-07 12:11:40 -08:00
Brandon Freitag
e4b71f0a23 Add ability to configure error from parseOptions (#594) 2016-12-06 23:52:02 -08:00
Brandon Freitag
12c103fc43 Update sed documentation regarding capture groups (#558)
* Update sed documentation regarding capture groups

* Remove unix sed example for brevity

* Regen README
2016-11-17 21:37:42 -08:00
Nate Fischer
4a1bce8815 fix: handle code-less errors more carefully in exec (#554)
If an error exists, but has no error code, it defaults to 1 (a common code for
most Unix commands). Tests have been omitted since this is an edge case that is
difficult to reproduce.

Fixes #536
2016-11-16 21:51:08 -08:00
Nate Fischer
7a82946a8d fix: maxdepth doesn't limit total number of copies (#549)
* fix: maxdepth doesn't limit total number of copies

Prevent maxdepth from limiting the total number of copies, only allow it to
limit the maximum depth

Fixes #547

* refactor: make `depth` be its own argument
2016-11-10 00:18:04 -08:00
Brandon Freitag
9bc498e512 Fix lint warning (#543)
* Fix lint warning

* Add a TODO to refactor loop
2016-11-01 21:38:00 -07:00
Nate Fischer
4975b54a4f feat: plugin.error() takes an options parameter (#535)
This implements the following options: `continue`, `code`, `prefix`, & `silent`.

Fixes #522, #523
2016-10-23 23:17:42 -07:00
Gyandeep Singh
93ea025755 Revert "refactor: replace fs.existsSync" (fixes #531) (#532)
This reverts commit ab8cf5a8e027b28fc7b784587e4339d2b6d0f08f.
2016-10-17 20:14:43 -07:00
Gyandeep Singh
9bf98dece9 Fix: Remove default glob from shell.test (fixes #529) (#530) 2016-10-17 11:00:04 -07:00
Nate Fischer
d057e075a7 feat: cp -u option (#527)
Only update when the source file is older than the destination, or the
destination file is missing.

Fixes #526
2016-10-14 15:39:59 -07:00
Nate Fischer
45f719de75 fix: echo supports -e option properly (#511) 2016-08-23 19:36:05 -07:00
Nate Fischer
ab8cf5a8e0 refactor: replace fs.existsSync (#509)
* refactor: replace fs.existsSync

* fix: add support for v0.10
2016-08-20 18:28:49 -07:00
Nate Fischer
a0c9032072 refactor: readFromPipe() requires no arguments (#506) 2016-08-13 15:50:31 -07:00
Nate Fischer
902f92ab5b feat: add overWrite option for commands (#503)
* feat: add overWrite option for commands

* fix: throws an error if a command is overwritten
2016-08-08 11:44:16 -07:00
Nate Fischer
2395214fee chore: switch to eslint (#504)
* chore: switch to eslint

* fix: works on older versions of NodeJS now

* chore: fix curly braces

* chore: fix indents and remove jshint references
2016-08-07 12:16:29 -07:00
Charles Read
cdd21c62f1 fixed head/tail readme (#499) 2016-07-31 12:58:21 -07:00
Nate Fischer
d4111763a9 refactor: glob by default for commands (#492) 2016-07-27 16:43:01 -07:00
Nate Fischer
06ae7d9b88 fix: conflicting options now properly override each other (#489) 2016-07-27 09:31:38 -07:00
Nate Fischer
add14adbf4 refactor: switch common.extend() to Object.assign ponyfill (#490) 2016-07-27 09:28:11 -07:00
Nate Fischer
11141a35ba refactor: switch from notUnix to unix in wrap() (#491) 2016-07-27 09:27:12 -07:00
Nate Fischer
7b9ec7fb66 refactor: allow pipeOnly commands (methods on ShellStrings) (#493) 2016-07-27 09:26:45 -07:00
Nate Fischer
9c7e6a892a refactor: add wrapOutput option to auto-ShellString-ify command output (#481) 2016-07-24 18:20:36 -07:00
Nate Fischer
e438e61f45 refactor: move option parsing into common.wrap() (#479)
* refactor: move option parsing into common.wrap()

* docs: update README
2016-07-24 17:52:51 -07:00
Nate Fischer
7b984e1c25 fix: mkdir for invalid perms does not kill process (#474)
* fix: mkdir for invalid perms does not kill process

* Re-throw exception in case it isn't `EACCES`
2016-07-24 16:58:45 -07:00
Nate Fischer
39fd6d1ed7 Fix mkdir malformed path (#477)
* Added recurs. mkdir dirname() failure check.

Prevents an infinite loop with malformed UNCs and/or permission problems.

* Now call common.error() instead of throwing (mkdir).

* refactor: clean up style
2016-07-23 16:21:59 -07:00
Nate Fischer
bd6f96db33 refactor: hook new uniq() command using new format (#478) 2016-07-23 10:56:26 -07:00
Shubham Joshi
3367e0c6c7 feat(command): new command: uniq() (#453)
* Added uniq.js, need to add tests

* Added basic tests for uniq.js

* Implemented uniq and added tests

* Generated docs for uniq

* Fixed lint error

* Added suport for -c and -d to uniq

* Generated docs

* Fixed formatting errors. Uniq now correctly returns empty string when output is specified

* Added uniq to piped methods

* Improved comment legibility

* Cleaned up the pipeline

* Added pipe test for uniq

* Converted uniq pipe test file to use linux line endings

* Fixed linting errors
2016-07-22 15:49:09 -07:00
Nate Fischer
3951a87913 refactor: commands now register themselves (#475) 2016-07-21 17:37:11 -07:00
Nate Fischer
5339375db0 fix(cp): -n option no longer raises error (#466)
Fixes #465
2016-06-28 00:27:33 -07:00
Nate Fischer
5d6adbaf53 fix(mv): works across partitions (#461)
Fixes #1
2016-06-19 14:44:32 -07:00
Nate Fischer
06c3d44e5b refactor: expose pipe-ability to command configuration (#464) 2016-06-17 16:05:59 -07:00
Nate Fischer
2e87f14c07 chore: update jshint and move it to an npm script (#454) 2016-06-07 16:57:42 -07:00
Nate Fischer
497149cc23 docs(exec): explicitly mention the shell option (#449) 2016-05-27 08:31:40 -07:00