Skip to main content

CLI Overview

A command line utility for lazy data processing in a shell using operations from Undercut and any valid JavaScript expression including loading your custom libraries.

Installation#

npm install --global @undercut/cli# oryarn global add @undercut/cli

You may also install it locally.

Usage#

The name of the installed command is undercut. You may also import the run function from the @undercut/cli to call it programmatically.

undercut [...options] [...operations]

List of available operations.

You're building a Push Line where the source is stdin and the target is stdout. Operations should be single quoted (prevents parsing by the shell) and separated by spaces. You can use everything that is available in the global context of Node.js. oreover, all exoprts from the @undercut/push are loaded into global scope by default, it's also available as a namespace object by the name of push. You could also quickly import @undercut/pull and @undercult/utils as namespaces using -p and -u keys.

undercut -u 'map(s => parseInt(s, 10))' 'filter(utils.isNumberValue)'
undercut 'composeOperations([push.sortStrings(utils.desc)])'          ^                  ^--- but you can also access them throught the push namespace          |--- exports from push are available in global scope

Any valid JavaScript expression resulting into a PushOperation works:

undercut 'observer => observer' # Does nothing useful, but works.

Options#

-i, --import=SPECIFIER#

Import a Node.js module to use it in expressions. The specifier has the format name::id. Module will be loaded by this id and accessible under this name.

$ undercut -i 'pad::left-pad' -p -s 'pull.range(0, 3)' 'map(x => pad(x, 3, 0))'000001002

A specifier is translated into something like this:

const name = await import("id");

So, the name should be a valid JS identifier, and the id should allow Node to load the module (like a path to a .js file or a name of npm package).

You may omit the name if your id is a valid identifier:

// -i 'chalk'const chalk = await import("chalk");

Or use a destructuring expression:

// -i '{green,blue}::chalk'const {green,blue} = await import("chalk");

-s, --source=EXPRESSION#

Specify a JavaScript expression of an Iterable to read input values from. In this case stdin will be ignored.

$ undercut -p -s 'range(0, 5)' 'sum()'10

--help#

Shows help information.

--version#

Prints package's version.