* 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.
* 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
* 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
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
- 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
* 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
* 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
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
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
* 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
* 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