# @jbp/yabamo-cli

> CLI wrapper for yabamo-core package

Latest version **0.0.5** (published 2020-09-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install @jbp/yabamo-cli
pnpm add @jbp/yabamo-cli
yarn add @jbp/yabamo-cli
bun add @jbp/yabamo-cli
```

Provides the command `yabamo-cli`.

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2020-09-05 |
| First published | 2020-08-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 52 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Janos Pomucz |
| Maintainers | jbp |
| Keywords | typescript, yabamo-core, @jbp/yabamo-core, cli |

## Links

- npm: https://www.npmjs.com/package/@jbp/yabamo-cli
- npm.io page: https://npm.io/package/@jbp/yabamo-cli

## Dependencies (4)

- [arg](https://npm.io/package/arg.md) 4.1.3
- [pm2](https://npm.io/package/pm2.md) ^4.4.1
- [typescript](https://npm.io/package/typescript.md) ^3.9.7
- [@jbp/yabamo-core](https://npm.io/package/@jbp/yabamo-core.md) 1.2.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

- 0.0.5 (latest) — 2020-09-05
- 0.0.4 — 2020-08-26
- 0.0.3 — 2020-08-26
- 0.0.2 — 2020-08-17
- 0.0.1 — 2020-08-17

## README

# yabamo-cli

CLI wrapper for the [@jbp/yabamo-core](https://www.npmjs.com/package/@jbp/yabamo-core) library.

## Installation
```npm install -g @jbp/yabamo-cli```

## Usage

### Starting API engine
```$ yabamo-cli start --config config.json```

where ```config.json``` is a ```.json``` file describing accessible paths and possible responses for your fake backend. A minimal config file would look something like this:
```
{
    "engineName": "testAPI",
    "port": "9000",
    "routes": [
        {
            "path": "/",
            "responses": {
                "default": "hello world!"
            }
        }
    ]
}
```
This very basic API responds to any request on its root (```http://localhost:9000```) with a simple "hello world!" string.

You can provide the name of the API engine with ```--engine``` option:

```$ yabamo-cli start --config config.json --engine Engine1```

It overrides the name provided in config and if none exists, the CLI will exit with error.

### Stopping API engine

```$ yabamo-cli stop --engine testAPI``` will stop the API engine named ```testAPI``` (if running).

```$ yabamo-cli stopall``` will stop all running engines.

### List running engines

```$ yabamo-core list``` will print a list of running API engines.

### Manipulate ```debug``` mode on engine

***This is probably not a good idea when running yabamo from CLI!** see [Debug](#debug) mode.*

You can use ```debug``` command to set or toggle debug mode on a certain route of an engine.

You need to provide name of the engine with ```--engine```, the path and the method with ```--path``` and ```--method``` and you can optionally set true or false by providing it as an argument.

Examples:

```$ yabamo-cli debug true -e testAPI -m GET -p /``` will set debug mode to true on the ```GET /``` route of the API called ```testAPI```. Omitting ```true``` or ```false``` will toggle the value; if debug mode was on, itt will turn it off and vice versa.

### Change response on engine

With ```changeresponse``` command you can override the response sent by a certain API endpoint. For example, let's say you augment the above configuration with a response named ```other``` like this:

```
"responses": {
    "default": "hello world!",
    "other": "HELLLO World!!"
}
```
In this case, by typing ```$ yabamo-cli changeresponse -e testAPI -m GET -p / -r other``` you can switch the current response to ```other```. From now on your API will respond with ```HELLLO World!``` when someone ```GET```s the path ```/``` (e.g. loads ```http://localhost:9000``` in her browser).

## Configuration

* engineName: optional, you can provide a name on start with ```--engine``` (or ```-e```) option. If you fail to provide the name of the API engine either way, the CLI will exit with error.
* port: required, the port number your API will use.
* routes: required, an ```Array``` of routes.
* fallback: optional, this is the response your API will use if no route has been found (your ```404``` response if you will).

### Routes
* path: required
* method: optional, defaults to ```GET```
* responses: required, a key=>value map where ```key``` is the name of the response, ```value``` is the response itself.
* currentResponse: optional, could be the name of one of the responses.


#### Method

Possible values: ```GET```, ```POST```, ```PUT```, ```DELETE``` and ```OPTIONS```

#### Responses

Every response is named. If there is only one response defined, it will be used. If there is more than one but no other indication of which one to use it will default to the first one. If there is a response named ```default```, it will have preference over other responses. If there is a ```currentResponse``` defined, it will have preference over everything else.

If the response is a ```string``` or a ```number``` it will be stringified and sent with ```res.send()```. If it is an ```Object``` or an ```Array``` it will be sent with ```res.json()```.

## Debug

You can set ```debug``` mode on any route. This means that when a request arrives to that route the API will pause and wait either for instruction regarding which possible response to send or until timeout. Default timeout is 30 seconds, you can overwrite it with ```debugTimeout``` (in milliseconds). This means that running yabamo from the CLI with a configuration containing ```debug:true``` on any route or setting debug mode later leads to a situation where requests may be delayed. Use it carefully!

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