727 Commits

Author SHA1 Message Date
Nate Fischer
8f8119cfae
docs: announce plugin API (#812)
Fixes #391
2018-01-11 21:12:42 -08:00
Nate Fischer
0b65d2a06d
chore: update CI to Node v9 (#811)
Fixes #799
2018-01-11 00:21:20 -08:00
Nate Fischer
a2343d0eab
refactor: harden plugins against unknown options (#804)
This reworks the plugin API such that:

 - Unable to register a command with unknown wrap-options
 - `TypeError` raised for wrap-option type mistakes
 - Remove the `overWrite` option (it's unused, probably safest to not
   expose for now)
 - `cmdOptions` defaults to `null` instead of `false` for type
   consistency (no change to default behavior)
 - Move `pipeMethods` logic into `_register`, since it makes more sense
   there

This is not expected to have any effect on existing plugins.
2017-11-16 12:44:51 -08:00
Nate Fischer
64d5899abc
refactor(exec): remove paramsFile (#807)
The `paramsFile` is obsolete now that we use `execFileSync()` for our
internal implementation. Instead, we pass parameters to the child
process directly as a single commandline parameter to reduce file I/O.

Issue #782
2017-11-16 12:43:54 -08:00
Nate Fischer
8ab0a3a393
chore: update nyc dependency (#805)
This is to fix an issue related to the most recent node 8.x.y versions.

Fixes #803
2017-11-13 22:55:41 -08:00
Nate Fischer
6189d7f8e5
Remove codeFile parameter (#791)
This parameter isn't needed, we can easily rely on exit code status for this.

Eliminating the parameter reduces file IO, code complexity, and removes a busy
loop.

This also removes some legacy code related to streams.

Issue #782
2017-10-31 15:51:18 -07:00
Nate Fischer
8451fceb81
chore(eslint): use words instead of numbers (#797)
Eslint rules can be configured either using words or number values:

 * "off" or 0
 * "warn" or 1
 * "error" or 2

This switches our config to use the string values instead of the number
values, since the number values are too cryptic.

No change to our actual settings.
2017-10-30 18:04:48 -07:00
Nate Fischer
a187bd1b36 Provide an API to pass parameters which resemble options (#792)
This adds the special option string `--`, which means "no options". This can be
passed if the first parameter looks like an option (starts with a `-` followed
by 1+ letters).

Fixes #778
2017-10-26 21:29:26 -07:00
Nate Fischer
b885590e0f Use execFileSync to launch child process (#790)
This uses `child_process.execFileSync` instead of `execSync` to launch the child
process. This further reduces the attack surface, removing a possible point for
command injection in the ShellJS implementation.

This does not affect backwards compatibility for the `shell.exec` API (the
behavior is determined by the call to `child_process.exec` within
`src/exec-child.js`).

Issue #782
2017-10-26 20:33:04 -07:00
Brandon Freitag
e9461dc5a7 Add note to issue template about FAQ (#794)
* Add note to issue template about FAQ

* Use more general language in FAQ comment
2017-10-23 17:27:13 -07:00
Nate Fischer
90165ba2f5 docs(changelog): updated by Nate Fischer [ci skip] 2017-10-19 23:06:24 -07:00
Nate Fischer
9e3f9abd2a refactor(exec): move child process to source file (#786)
This PR refactors `shell.exec()` by putting its child process in a separate code
file. This also slightly cleans up dead code.

There's more potential to clean this up (e.g. exit status), but this is a good
enough start.

Issue #782
2017-10-19 13:19:52 -07:00
Brandon Freitag
a7d6df5f6d Wrap fs.statSync and fs.lstatSync (#783)
Adds two new methods to src/common.js, common.statFollowLinks and common.statNoFollowLinks, which wrap fs.statSync and fs.lstatSync, respectively. This change is meant to improve readability and clarify intent.

* Add common.statFollowLinks and common.statNoFollowLinks

* Replace fs.statSync and fs.lstatSync in source files
2017-10-17 19:25:09 -07:00
Brandon Freitag
7cbce88915 Add a test for ls for a single file (#784) 2017-10-17 19:22:37 -07:00
Brandon Freitag
32972e0cdd Remove unnecessary shell.error checks from common tests (#785) 2017-10-14 02:38:12 -07:00
Nate Fischer
df1460ff53 chore: clean up refs to unsupported node versions (#779)
Also removes unnecessary guard code leftover from old versions.
2017-10-12 23:23:23 -07:00
Nate Fischer
cd1aabab39 chore: set AVA options (#780)
This sets 2 AVA options:

 * `serial`: same behavior as the CLI flag, which this replaces
 * `powerAssert`: if an assert fails, it will inspect all objects involved in
   the failed assert. This causes readability issues if `t.falsy(shell.error())`
   breaks, since it inspects all of `shell` (which is way too large).

AVA options are a little easier to manage than CLI options (we only update one
place instead of 2 in `package.json`).
2017-10-12 23:23:09 -07:00
Alexander Regueiro
cea0e58250 Added -q (quiet) option to push, popd, dirs functions. (#777)
* Added `-q` (quiet) option to `push`, `popd`, `dirs` functions.

* Added unit tests for pushd/popd quiet mode.

* Added tests for `pushd` and `popd` with quiet mode off.

* Updated docs for `pushd` and `popd` functions.

* Moved preliminary `pushd` commands for `popd` tests before disabling of silent flag.
2017-10-09 20:53:17 -07:00
cristHian Gz
c889075f78 feat(cat): number output lines (#750) (#775) 2017-09-22 21:27:42 -07:00
Brandon Freitag
dcead1be86 Add "encoding" option to exec (#763)
* Add 'encoding' option to shell.exec

* Add 'encoding' option to docs

* Add exec encoding option tests

* Clarify use of encoding with fs.readFileSync

* Add check for stderr buffer
2017-09-13 16:18:28 -07:00
Brandon Freitag
c7d65ac590 fix(ls): ls not following links to directories by default (#764)
* Fix ls not following links to directories by default
2017-08-23 19:06:25 -07:00
Nate Fischer
2ee83ebf74 refactor(test): update AVA and refactor tests (#760)
This updates tests for `AVA` 19.0.0+.

`AVA` 0.18.0 has a breaking change which changes the current working directory
for tests. As a result, we need to change 'resources' -> 'test/resources' (and
 similar path changes).

`AVA` 0.19.0 has a breaking change that all tests must run at least one assert.
This breaking change was already resolved by #746, so no change was necessary in
this PR.

This updates to `AVA` 0.21.0, since there are no other breaking changes.
2017-08-11 11:03:13 -07:00
Nate Fischer
38b57c8942 chore: add skipOnWin and skipOnUnix test helpers (#746)
This adds `skipOnWin` and `skipOnUnix` to help us manage our platform-dependent
tests. These methods give a nice warning message when we skip tests. We may also
consider adding warnings when running platform-dependent tests.

Part of the motivation for this is if we ever update to AVA v0.19. This version
requires at least one assertion per test case. While this could be disabled with
an AVA setting, we instead benefit from warnings for any case when we
unintentionally skip assertions.

This adds chalk as a dev dependency to enable colored messages.
2017-06-18 11:51:01 -07:00
Nate Fischer
5823ab18bb test(exec): add tests for coverage (#744)
* test(exec): add tests for coverage

No logic change.

This adds one test to cover some missing lines, and adds some `istanbul ignore`
directives.

I see 100% line coverage for `src/exec.js` when running:

```sh
$ nyc --reporter=text --reporter=lcov ava --serial test/exec.js`
```

Fixes #742

* Fix lint
2017-06-17 19:09:01 -07:00
Nate Fischer
291241811f test(head): improve coverage (#743)
This adds a test for `head()` on the right-hand side of a pipe. This also
removes the try-catch surrounding `fs.openSync()`, because it was unreachable
code. `fs.existsSync()` guarantees that the file exists, and `fs.openSync()`
only throws if the file does not exist, according to official documentation.

Fixes #671
2017-06-17 18:31:24 -07:00
Vojtech Jasny
c16fb7dac9 Remove PDF.js mention from README.md (#738)
Fixes #737.
2017-06-16 15:55:25 -07:00
Brandon Freitag
522a46dcf4 Deprecate common.getUserHome, advise using os.homedir instead (#725)
* Deprecate common.getUserHome, advise using os.homedir instead

* Remove common.getUserHome
2017-06-06 21:10:27 -07:00
Brandon Freitag
e8ec60bc2f Echo test mocks (#708)
* Add stdout/stderr test mocks

* Mock stdout/stderr during echo tests

* Fix lint issues

* Use 'use strict'

* Re-implement mocks as a prototype

* Implement mocks as a single-instance

* Remove redundant test

* Create mocked stdout/stderr.write methods once
2017-06-06 21:10:27 -07:00
Nate Fischer
c1d8fecc56 Fix broken test 2017-06-06 21:10:27 -07:00
Nate Fischer
18034486a5 Echo stdout (#677)
* Add newline to output of echo (#557)

* Add newline to output of echo

* Add test

* Throw an error if the options string does not start with '-' (#615)

* Throw an error if the options string does not start with '-'

* Add test

* Change message grammar

* Add -n option to echo

* Fix null argument issue

* Add -n tests

* Add documentation

* Add -en escaped character test

* Add function to parse options for echo

* Use parseOptions to parse echo options

* Simplify control flow

* parseOptions throws now

* Allow null to be echoed

* Prevent echo stderr on unrecognized option

* Add test to check stderr of returned value

* Use consistent variable name

* Change test message, leave TODO about console output
2017-06-06 21:10:27 -07:00
Brandon Freitag
97a8c1969a fix(grep, sed, sort, uniq): Split only on newline characters (#690)
* Split on newlines only

* Only split lines if need be

* Clarify code by making use of Array.prototype.reduce
2017-06-06 21:10:27 -07:00
Nate Fischer
f74e783890 chore: remove v0.12 and iojs support (#648)
Fixes #647
2017-06-06 21:10:27 -07:00
Brandon Freitag
5d05d27108 Safely exit by throwing an error (#649) 2017-06-06 21:10:27 -07:00
Brandon Freitag
5acb353bc5 Add newline to output of echo (#557)
* Add newline to output of echo

* Add test
2017-06-06 21:10:27 -07:00
Nate Fischer
0ad6252f2e docs(changelog): updated by Nate Fischer [ci skip] 2017-06-06 21:02:26 -07:00
Nate Fischer
38645675f1 0.7.8 v0.7.8 2017-06-06 21:01:21 -07:00
Nate Fischer
a66e338b5f docs(changelog): updated by Nate Fischer [ci skip] 2017-06-06 20:58:14 -07:00
Brandon Freitag
bbd8178cba Add node 8 to CI (#730) 2017-06-03 22:26:10 -07:00
Nate Fischer
15558cf67a fix(mkdir): improve error handling around files (#721)
* fix(mkdir): improve error handling around files

In particular, this fixes:

 - if we try to overwrite a file with a mkdir
 - if we try to create a subdirectory of a file
 - adds `continue: true` in spots where we missed it

Fixes #720

* Fixing tests on Windows
2017-05-16 00:30:11 -07:00
Nate Fischer
a2e13b62dc Properly handle directories as arguments (#713)
* fix(cat): do not cat directories

Fixes #707

* fix(head): do not let head() read directories

Also fixes a typo

* fix(sort): do not sort directories

Also fixes a typo

* fix(tail): do not let tail() read directories

Also fixes a typo

* fix(uniq): do not let uniq() read directories

We also had a test which called sort() instead of uniq(), so we never
actually tested the missing-file case. This fixes that as well.

This also throws an error for using a directory as output.

* fix(pipe): fix breakages with piped commands
2017-05-08 22:57:58 -07:00
Brandon Freitag
951ff22671 Add common.buffer (#710)
* Add common.buffer

* Fix comment
2017-05-02 23:04:56 -07:00
Brandon Freitag
92d3f3982e Fix common.expand error (#709)
* When glob.sync errors, return original array element

* Add test for cp with empty string
2017-05-02 19:54:56 -07:00
Kumar Uttpal
bbe521b57d Fix #631 throw error when overwriting recently created file (#702)
* cp: add error to not overwrite recently created files #631

* cp: add tests for errors not overwrite recently created files #631

* mv: show error when overwriting recently created file #631

* mv: add tests for error on recently created files #631

* mv: test remove unnecessary steps #631
2017-04-15 02:01:58 -07:00
Nate Fischer
d8ac4d3f02 refactor: remove unnecessary common.js imports (#703)
No change in logic.

This removes unnecessary imports of `common.js` in favor of the `shell`
package.
2017-04-15 00:51:29 -07:00
Brandon Freitag
7feabda0d6 Remove contents of symlink to dir with rm -rf (#688)
* rm -rf on a symlink to a dir deletes contents

* Fix comment typo

* Clarify comments

* Pass symlink directly to rmdirSync

* Skip rm -rf symlink test on windows
2017-04-15 00:49:10 -07:00
Brandon Freitag
e12da9d888 Refactor: Use process.platform across codebase (#689)
* Use process.platform across codebase

* Use process.platform in tests
2017-04-14 23:04:21 -07:00
Christian Zommerfelds
80d590ec05 Small clarification of verbose flag (#691)
* small clarification of verbose flag

* nfischer's documentation suggestion

* verbose flag documentation in source file
2017-03-30 20:30:30 -07:00
Nate Fischer
b9201eba0f docs(changelog): updated by Nate Fischer [ci skip] 2017-03-08 22:38:36 -08:00
Nate Fischer
95638cc773 0.7.7 v0.7.7 2017-03-08 22:37:03 -08:00
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