# @pony-ci/cli-exec

> Execute CLI commands in node.

Latest version **1.0.6** (published 2020-04-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @pony-ci/cli-exec
pnpm add @pony-ci/cli-exec
yarn add @pony-ci/cli-exec
bun add @pony-ci/cli-exec
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.6 |
| Published | 2020-04-18 |
| First published | 2020-04-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10.0.0 |
| Dependencies | 1 |
| Unpacked size | 26.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ondřej Kratochvíl |
| Maintainers | ponyci |
| Keywords | pony, cli, exec, child_command, cmd, node, ts, typescript |

## Links

- npm: https://www.npmjs.com/package/@pony-ci/cli-exec
- Repository: https://github.com/pony-ci/cli-exec
- Homepage: https://github.com/pony-ci/cli-exec#readme
- Issues: https://github.com/pony-ci/cli-exec/issues
- npm.io page: https://npm.io/package/@pony-ci/cli-exec

## Dependencies (1)

- [fs-extra](https://npm.io/package/fs-extra.md) ^8.1.0

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.0.6 (latest) — 2020-04-18
- 1.0.5 — 2020-04-18
- 1.0.4 — 2020-04-13
- 1.0.3 — 2020-04-12
- 1.0.2 — 2020-04-11
- 1.0.1 — 2020-04-10
- 1.0.0 — 2020-04-10

## README

# cli-exec

[![CircleCI](https://circleci.com/gh/pony-ci/cli-exec.svg)](https://circleci.com/gh/pony-ci/cli-exec)
[![npm](https://badge.fury.io/js/%40pony-ci%2Fcli-exec.svg)](https://badge.fury.io/js/%40pony-ci%2Fcli-exec)
[![License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://github.com/pony-ci/cli-exec/blob/master/LICENSE)


Execute CLI commands in node.

## Usage
```javascript
await exec('docker', 'run', {rm: true}, 'hello-world');
// executes 'docker run --rm hello-world'

console.log(build('docker', 'run', {rm: true}, 'hello-world'));
// prints 'docker run --rm hello-world'

// you can also pass options in array
console.log(build('docker', ['run', {rm: true}, 'hello-world']));

const args = buildArgs('run', {rm: true}, 'hello-world');
// [ 'run', '--rm', 'hello-world' ]

await exec('docker', 'images', {filter: 'dangling=true'});
// executes 'docker images --filter dangling=true'

await exec('npm', {quiet: true, cwd: '/home/user/workspace/my-npm-project'}, 'install');
// executes 'npm install' in specified cwd with suppressed stdout and stderr

// cmd instance also contains methods exec, build and buildArgs
const docker = cmd('docker');
await docker.exec('run', {rm: true}, 'hello-world');
// executes 'docker run --rm hello-world'

const myCmd = cmd('mycmd');
// overriding transform function
const transform = myCmd.transform;
myCmd.transform = (opt) => {
    const args = [];
    Object.entries(opt).forEach(([name, value]) => {
        if (shouldJoinWithSign(name, value)) {
            args.push(`--${name}=${value}`);
        } else {
            args.push(...transform({[name]: value}));
        }
    });
    return args;
};
console.log(myCmd.build({name: 'value'}));
// prints 'mycmd --name=value'
```

## Special options
Special options modify the command execution.
#### Examples
```javascript
// options for every command executed on npm instance
const npm = cmd('npm', {
    cwd: '/home/user/workspace/my-npm-project',
    printCommand: false
});
// the command options can be overridden during execution
// they must be passed as first option
await npm.exec({printCommand: true}, 'install');
// executes 'npm install' with printing the command
await npm.exec('install', {printCommand: true});
// executes 'npm install --printCommand' without printing the command
```

#### Options overview
| name         | description                              | default       |
|--------------|------------------------------------------|---------------|
| cwd          | current working directory                | process.cwd() |
| printCommand | print command being executed             | true          |
| quiet        | suppress printCommand, stdout and stderr | false         |

## Default implementations
This module includes some common commands.

#### eslint
```javascript
await eslint('src/**/*.js');
```

#### npm
```javascript
await npm.install();
await npm.test();
await npm.publish('--dry-run');
```

#### npx
```javascript
await npx('eslint', 'src/**/*.js');
```

## License
This software is released under the [MIT License](https://github.com/pony-ci/cli-exec/blob/master/LICENSE).

---
_Source: https://npm.io/package/@pony-ci/cli-exec · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
