File: cli.md

package info (click to toggle)
node-clipanion 3.2.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,232 kB
  • sloc: javascript: 75; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,413 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
---
id: cli
title: Cli
---

## `new Cli`

```ts
new Cli(opts: {...})
```

| Option | type | Description |
| --- | --- | --- |
| `binaryLabel` | `string` | Tool name, as shown in the help message |
| `binaryName` | `string`| Binary name, as shown in the usage line |
| `binaryVersion` | `string` | Tool version, as shown in `--version` |
| `enableCapture` | `boolean` | If set, redirect stdout/stderr into the command streams |
| `enableColors` | `boolean` | Overrides the automatic color detection for error messages |

## `Cli#process`

```ts
cli.process(input: string[])
```

Turn the given arguments into a partially hydrated command instance. Don't call `execute` on it, as some fields must still be set before the command can be truly executed. Instead, pass it forward to `Cli#run` if you wish to truly execute it.

## `Cli#run`

```ts
cli.run(input: Command, context: Context)
cli.run(input: string[], context: Context)
```

Turn the given argument into a command that will be immediately executed and returned. If an error happens during execution `Cli#run` will catch it and resolve with an exit code 1 instead.

## `Cli#runExit`

```ts
cli.runExit(input: string[], context?: Context)
```

Same thing as `Cli#run`, but catches the result of the command and sets `process.exitCode` accordingly. Note that it won't directly call `process.exit`, so the process may stay alive if the event loop isn't empty.