From 2f8fcb7851f0752232baf465e9582ca6fa224cb5 Mon Sep 17 00:00:00 2001 From: Danny McCormick Date: Sun, 4 Aug 2019 09:00:04 -0400 Subject: [PATCH] Update package docs (#38) * Update README.md * Add exec guidance * Add io guidance * Add tool-cache guidance * Readability * Readability * Readability * Nit * Nit * Nit --- README.md | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 354acdc..e76ce0b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,60 @@ # `@actions/exec` -> Functions necessary for running tools on the command line - ## Usage -See [src/exec.ts](src/exec.ts). \ No newline at end of file +#### Basic + +You can use this package to execute your tools on the command line in a cross platform way: + +``` +const exec = require('@actions/exec'); + +await exec.exec('node index.js'); +``` + +#### Args + +You can also pass in arg arrays: + +``` +const exec = require('@actions/exec'); + +await exec.exec('node', ['index.js', 'foo=bar']); +``` + +#### Output/options + +Capture output or specify [other options](https://github.com/actions/toolkit/blob/d9347d4ab99fd507c0b9104b2cf79fb44fcc827d/packages/exec/src/interfaces.ts#L5): + +``` +const exec = require('@actions/exec'); + +const myOutput = ''; +const myError = ''; + +const options = {}; +options.listeners = { + stdout: (data: Buffer) => { + myOutput += data.toString(); + }, + stderr: (data: Buffer) => { + myError += data.toString(); + } +}; +options.cwd = './lib'; + +await exec.exec('node', ['index.js', 'foo=bar'], options); +``` + +#### Exec tools not in the PATH + +You can use it in conjunction with the `which` function from `@actions/io` to execute tools that are not in the PATH: + +``` +const exec = require('@actions/exec'); +const io = require('@actions/io'); + +const pythonPath: string = await io.which('python', true) + +await exec.exec(`"${pythonPath}"`, ['main.py']); +```