git-casefile/impl

Classes

DiffInteraction

Class encapsulating usage of diff

GitInteraction

Class encapsulating usage of git

Methods

(static) CommandRunner(program, optsopt) → {CommandRunnerFunc|ToolkitRunnerFunc}

Construct a command-runner function

Source:

Invocation of command line tools involves several aspects not covered by NodeJS's child_process module: flags, optional arguments, consumption of STDOUT, provision of input on STDIN, propagating STDERR output to a meaningful place (often to console), and handling of child process exit codes.

The functions returned by this function implement that level of expressivity for invoking command line tools programmatically: flags and optional arguments can be given in an Object (to indicate the irrelevance of ordering and to simplify each tool invocation), STDOUT can be delivered to a function that receives strings (or to a Writable stream for more flexibility), timeout capability is baked in, and coordination of result generation is easy; failures reject with a meaningful error.

Parameters:
Name Type Attributes Description
program string

The name of the program to run

opts object <optional>
Properties
Name Type Attributes Default Description
path string | function <optional>

Path to search for the program (given in normal style for the platform), or a function that returns the path

cwd string <optional>

Path to made the current directory of the tool when it starting

env Object.<string, string> <optional>

Object mapping environment variable names to values; can be overriden by passing an env property when invoking the tool; defaults to process.env

usesSubcommands boolean <optional>
false

Whether the returned value is a ToolkitRunnerFunc (true) or a CommandRunnerFunc (false)

optStyle string <optional>
'gnuopt'

A defined style of option rendering to be used with opts of the tool invocation

timeout number <optional>

Number of seconds to wait for the tool to complete execution before rejecting with a timeout error (err.code === 'Timeout')

logger Object <optional>

A console-like object supporting at least an error method to which errors are reported

tracer EventEmitter <optional>

An EventEmitter on which 'execute' (pre-execution) and 'executing' (after execution starts) events will be emitted

outputEncoding string <optional>

The name of a string encoding to use when converting output to strings; only effective for STDOUT if stdout prop passed to an invocation is a function, but also affects STDERR (which defaults to 'utf8')

Returns:
Type
CommandRunnerFunc | ToolkitRunnerFunc