From c2e3e1864f1187d6c2559b61b942780335f7cc1f 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 | 80 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index e9b50d2..22f0901 100644 --- a/README.md +++ b/README.md @@ -4,46 +4,50 @@ ## Usage +#### mkdir -p + +Recursively make a directory. Follows rules specified in [man mkdir](https://linux.die.net/man/1/mkdir) with the `-p` option specified: + ``` -/** - * Copies a file or folder. - * - * @param source source path - * @param dest destination path - * @param options optional. See CopyOptions. - */ -export function cp(source: string, dest: string, options?: CopyOptions): Promise +const io = require('@actions/io'); -/** - * Remove a path recursively with force - * - * @param path path to remove - */ -export function rmRF(path: string): Promise +await io.mkdirP('path/to/make'); +``` -/** - * Make a directory. Creates the full path with folders in between - * - * @param p path to create - * @returns Promise - */ -export function mkdirP(p: string): Promise +#### cp/mv -/** - * Moves a path. - * - * @param source source path - * @param dest destination path - * @param options optional. See CopyOptions. - */ -export function mv(source: string, dest: string, options?: CopyOptions): Promise +Copy or move files or folders. Follows rules specified in [man cp](https://linux.die.net/man/1/cp) and [man mv](https://linux.die.net/man/1/mv): -/** - * Returns path of a tool had the tool actually been invoked. Resolves via paths. - * - * @param tool name of the tool - * @param options optional. See WhichOptions. - * @returns Promise path to tool - */ -export function which(tool: string, options?: WhichOptions): Promise -``` \ No newline at end of file +``` +const io = require('@actions/io'); + +// Recursive must be true for directories +const options = { recursive: true, force: false } + +await io.cp('path/to/directory', 'path/to/dest', options); +await io.mv('path/to/file', 'path/to/dest'); +``` + +#### rm -rf + +Remove a file or folder recursively. Follows rules specified in [man rm](https://linux.die.net/man/1/rm) with the `-r` and `-f` rules specified. + +``` +const io = require('@actions/io'); + +await io.rmRF('path/to/directory'); +await io.rmRF('path/to/file'); +``` + +#### which + +Get the path to a tool and resolves via paths. Follows the rules specified in [man which](https://linux.die.net/man/1/which). + +``` +const exec = require('@actions/exec'); +const io = require('@actions/io'); + +const pythonPath: string = await io.which('python', true) + +await exec.exec(`"${pythonPath}"`, ['main.py']); +```