Skip to content

Commit 57524e8

Browse files
Tyler Kellenphated
authored andcommitted
Docs: Improve documentation and comments
1 parent 0a46fbf commit 57524e8

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

README.md

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55

66
## What is it?
77

8-
Say you wrote a command line tool that runs arbitrary javascript (e.g. task runner, test framework, etc). Now, say you want to support running it with v8 flags enabled (`--harmony`, for example).
8+
Say you wrote a command line tool that runs arbitrary javascript (e.g. task runner, test framework, etc). For the sake of discussion, let's pretend it's a testing harness you've named `testify`.
99

10-
For example, let's run an imaginary testing tool with the following command: `test --harmony spec tests.js`. This would produce a [`process.argv`](http://nodejs.org/docs/latest/api/process.html#process_process_argv) of:
10+
Everything is going splendidly until one day you decide to test some code that relies on a feature behind a v8 flag in node (`--harmony`, for example). Without much thought, you run `testify --harmony spec tests.js`.
11+
12+
It doesn't work. After digging around for a bit, you realize this produces a [`process.argv`](http://nodejs.org/docs/latest/api/process.html#process_process_argv) of:
1113

1214
`['node', '/usr/local/bin/test', '--harmony', 'spec', 'tests.js']`
1315

14-
The `--harmony` flag is in the wrong place! It needs to be a part of the **node** command. What we actually wanted was:
16+
Crap. The `--harmony` flag is in the wrong place! It should be applied to the **node** command, not our binary. What we actually wanted was this:
1517

1618
`['node', '--harmony', '/usr/local/bin/test', 'spec', 'tests.js']`
1719

18-
Good news, flaggedRespawn does exactly this. All it takes it a simple conditional in your cli code:
20+
Flagged-respawn solves this problem.
1921

20-
## Example
22+
## Sample Usage
2123
```js
2224
#!/usr/bin/env node
2325

@@ -26,14 +28,17 @@ const flaggedRespawn = require('flagged-respawn');
2628
// get a list of all possible v8 flags to intercept
2729
const v8flags = require('v8flags').fetch();
2830

29-
// if necessary, respawn to apply node flags
31+
// check to see if any defined flags are in the wrong position
32+
// if we didn't want to support all v8 flags, we could just as
33+
// easily do if (!flaggedRespawn.needed(['--harmony'])) instead.
3034
if (!flaggedRespawn.needed(v8flags)) {
31-
// If we are here, no respawn was needed a.k.a no special flags
32-
// were seen, or this is the child process that was spawned by
33-
// the first run.
35+
// If we are here, no special flags were seen, or this
36+
// is the child process that our initial run spawned.
3437
console.log('Running!');
3538
} else {
36-
// respawn so the above branch is entered
39+
// if we are here, there are special flags applied to the
40+
// wrong command. the above branch will be executed by the
41+
// child process this spawns.
3742
console.log('Respawning...');
3843
flaggedRespawn.execute(v8flags);
3944
}
@@ -43,4 +48,4 @@ To see it in action, clone this repository and run `npm install` / `npm run resp
4348

4449
## Release History
4550

46-
* 2014-09-04 - v0.1.0 - initial release
51+
* 2014-09-04 - v0.1.1 - initial release

bin/example.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ const flaggedRespawn = require('../');
55
// get a list of all possible v8 flags to intercept
66
const v8flags = require('v8flags').fetch();
77

8-
// if necessary, respawn to apply node flags
8+
// check to see if any defined flags are in the wrong position
9+
// if we didn't want to support all v8 flags, we could just as
10+
// easily do if (!flaggedRespawn.needed(['--harmony'])) instead.
911
if (!flaggedRespawn.needed(v8flags)) {
1012
// If we are here, no respawn was needed a.k.a no special flags
1113
// were seen, or this is the child process that was spawned by

0 commit comments

Comments
 (0)