machine-as-script
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -204,2 +204,3 @@ /** | ||
) { | ||
// TODO: support json-encoded output vs colors | ||
console.log(util.inspect(output, {depth: null, colors: true})); | ||
@@ -206,0 +207,0 @@ } |
{ | ||
"name": "machine-as-script", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Run a machine as a command-line script.", | ||
"scripts": { | ||
"test": "node ./node_modules/mocha/bin/mocha" | ||
"test": "node ./node_modules/mocha/bin/mocha test" | ||
}, | ||
@@ -21,9 +21,9 @@ "bin": { | ||
"commander": "2.6.0", | ||
"lodash": "^3.8.0", | ||
"machine": "12.1.0", | ||
"rttc": "^8.1.7", | ||
"lodash": "3.10.1", | ||
"machine": "^12.2.4", | ||
"rttc": "^9.7.0", | ||
"yargs": "3.4.5" | ||
}, | ||
"devDependencies": { | ||
"machinepack-process": "^1.4.0", | ||
"machinepack-process": "^2.0.2", | ||
"mocha": "^2.2.4" | ||
@@ -30,0 +30,0 @@ }, |
# machine-as-script | ||
Run any machine as a command-line script. | ||
Build a modified version of a machine that proxies its inputs from CLI arguments and/or `--` opts. | ||
Useful for running jobs (cron, Heroku scheduler), automating repetitive tasks (Grunt, gulp), writing one-off scripts (NPM, Chef), and building production-ready tools with command-line interfaces (e.g. `treeline`, `machinepack`). Suppots _serial command-line arguments_, command-line opts (`--`), and environment variables. | ||
```sh | ||
@@ -11,3 +11,5 @@ $ npm install machine-as-script --save | ||
> New to Node? Check out [**Getting Started With machine-as-script** from NPM](https://www.npmjs.com/package/machine-as-script/tutorial). | ||
## Usage | ||
@@ -18,6 +20,5 @@ | ||
var asScript = require('machine-as-script'); | ||
var MPMath = require('machinepack-math'); | ||
asScript({ | ||
require('machine-as-script')({ | ||
machine: MPMath.add | ||
@@ -31,3 +32,3 @@ }).exec({ | ||
Now you can run your machine as a script and provide inputs as CLI opts: | ||
Now you can run your machine as a script and provide input values as CLI opts: | ||
@@ -42,3 +43,14 @@ ```sh | ||
##### Assorted examples | ||
It's all well and good to build command-line scripts that do simple arithmetic, but what about something more practical? Here are a few real-world examples of `machine-as-script` in practice: | ||
+ https://github.com/node-machine/machinepack/blob/93a7132117546ed897fa8391997d0b8aa301d6e4/bin/machinepack-browserify.js | ||
+ https://github.com/node-machine/machinepack/blob/93a7132117546ed897fa8391997d0b8aa301d6e4/bin/machinepack-compare.js | ||
+ https://github.com/treelinehq/treeline/blob/32b8760504c46e9816ec89a1dc8e301e0c34f62a/bin/treeline-browse.js | ||
+ https://github.com/treelinehq/treeline/blob/763b293615e4b26339998a1384919cf958402ba8/bin/treeline-login.js | ||
## Using serial CLI arguments | ||
@@ -68,3 +80,3 @@ | ||
#### Experimental: The `args` input | ||
##### Experimental: The `args` input | ||
@@ -74,2 +86,4 @@ If you don't already have an input named `args`, when using machine-as-action, your machine's `fn` will receive an array of serial command-line arguments in `inputs.args`. **THIS IS AN EXPERIMENTAL FEATURE AND COULD CHANGE AT ANY TIME WITHOUT BACKWARDS COMPATIBILITY!!** | ||
## Using environment variables | ||
@@ -93,3 +107,3 @@ | ||
#### Setting a namespace | ||
##### Setting a namespace | ||
@@ -123,5 +137,5 @@ It's usually a good idea to namespace the environment variables specific to your application. | ||
#### A note on case-sensitivity | ||
##### A note on case-sensitivity | ||
Note that input names are _case-sensitive_, and therefore the names of environment variables understood by this module are also case-sensitive. | ||
Note that input code names are _case-sensitive_, and therefore the names of environment variables understood by this module are also case-sensitive. | ||
@@ -131,2 +145,3 @@ [On Windows, the names of environment variables are capitalized/case-insensitive](https://en.wikipedia.org/wiki/Environment_variable#DOS), so you may have difficulties using this approach. I'm happy to help in the implementation of a workaround if you need this and have any ideas for how to do it (hit me up [on Twitter](http://twitter.com/mikermcneil)). | ||
## Configuring non-string values | ||
@@ -138,3 +153,3 @@ | ||
#### Numeric inputs | ||
##### Numeric inputs | ||
@@ -145,3 +160,3 @@ ```sh | ||
#### Boolean inputs | ||
##### Boolean inputs | ||
@@ -152,3 +167,3 @@ ```sh | ||
#### Lamda (`->`) inputs | ||
##### Lamda (`->`) inputs | ||
@@ -159,3 +174,3 @@ ```sh | ||
#### Dictionary (`{}`) and array (`[]`) inputs | ||
##### Dictionary (`{}`) and array (`[]`) inputs | ||
@@ -172,3 +187,3 @@ If an input is expecting a dictionary or array (i.e. its example is a dictionary or array), then its value should be specified as JSON. | ||
#### JSON (`*`) inputs | ||
##### JSON (`*`) inputs | ||
@@ -202,3 +217,3 @@ If an input is expecting generic JSON (i.e. its example is `'*'`), then its value should be specified as JSON-- even if that value is a simple string, number, or boolean. | ||
#### Mutable reference (`===`) inputs | ||
##### Mutable reference (`===`) inputs | ||
@@ -209,9 +224,12 @@ For the automatic console output of machine-as-script, mutable reference inputs work just like JSON (`*`) inputs. For custom behavior, just override the automatic handling using `.exec()`. | ||
## Misc | ||
#### Escaping your input values | ||
##### Escaping your input values | ||
The rules for escaping env vars, CLI opts, and CLI arguments can vary across operating systems. However, a good reference point is the [escape machine in mp-process](http://node-machine.org/machinepack-process/escape). That's what the `machinepack` command-line tool uses internally for creating code samples after a machine is run using `mp exec`. | ||
#### Precedence | ||
##### Precedence | ||
@@ -229,5 +247,17 @@ It's always best to keep things simple. In keeping with that spirit, you should never _intentionally_ use both environment variables AND CLI opts/args to configure your script. But weird things are unavoidable, and when debugging, it's helpful to know more about the tools you use in case something jumps out. | ||
##### Other Implementation Details, Edge Cases, and Conventions | ||
`machine-as-action` works by building a modified version of a machine instance that, when you call `.exec()`, will proxy its input values from serial command-line arguments, command-line opts (`--`), and/or environment variables. You should almost always call `.exec()` immediately after using `machine-as-action`, in the same file. If you are building a command-line tool, it is conventional to keep these files in your project's `bin/` directory (see the `treeline` and `machinepack` CLI tools on NPM for examples). | ||
If, when you call `.exec()`, you omit a callback for a non-standard exit, the standard behavior of the machine runner applies. If you omit `error` or `success`, machine-as-script will attempt its best guess at appropriate output by using exit metadata + introspecting runtime output. Similarly, runtime input values are validated vs. the exemplars and requiredness in the machine's input definitions. | ||
## Support | ||
For more help, check out the [node-machine newsgroup](https://groups.google.com/forum/#!forum/node-machine) and [http://node-machine.org](http://node-machine.org). | ||
## License | ||
MIT © Mike McNeil | ||
MIT © 2015 Mike McNeil |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18220
207
247
+ Addedmachine@12.4.0(transitive)
+ Addedrttc@9.8.2(transitive)
- Removedlodash@3.8.0(transitive)
- Removedmachine@12.1.0(transitive)
- Removedrttc@8.1.79.3.4(transitive)
Updatedlodash@3.10.1
Updatedmachine@^12.2.4
Updatedrttc@^9.7.0