# @bizhermit/cli-utils

> CLI SDK

Latest version **1.0.0-rc.0** (published 2022-07-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install @bizhermit/cli-utils
pnpm add @bizhermit/cli-utils
yarn add @bizhermit/cli-utils
bun add @bizhermit/cli-utils
```

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-rc.0 |
| Published | 2022-07-31 |
| First published | 2022-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Senda Ryoichi |
| Maintainers | bizhermit |
| Keywords | bizhermit, cli, command line, read line |

## Links

- npm: https://www.npmjs.com/package/@bizhermit/cli-utils
- Repository: https://github.com/bizhermit/cli-utils
- Homepage: https://bizhermit.com
- Issues: https://github.com/bizhermit/cli-utils/issues
- npm.io page: https://npm.io/package/@bizhermit/cli-utils

## 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.0-rc.0 (latest) — 2022-07-31

## README

# CLI SDK

CLI SDK.  

Install
```bash
npm i @bizhermit/cli-utils
```

Example
```ts
import Cli, { getKeyArgs } from "@bizhermit/cli-utils";

const func = async () => {
  const command = Cli.getArg();
  const dest = Cli.getKeyArg("-d");
  const excludes = getKeyArgs("-excludes");
  const text = await Cli.rl("input > ");
  await Cli.wl(text);
};
func();
```

### Methods

* ***rl(message?: string) => Promise\<string>***  
  read input text line.
  ```ts
  const text = await rl("input > ");
  ```
  ```bash
  # console
  input > _
  ```

* ***wl(message?: string) => void***  
  write text for console.
  ```ts
  wl("hoge");
  ```
  ```bash
  # console
  hoge
  ```

* ***getArg(index?: number) => string | undefined***  
  get arg value.
  ```bash
  node cli hoge fuga piyo
  ```
  ```ts
  console.log(getArg()); // => "hoge"
  console.log(getArg(2)); // => "piyo"
  console.log(getArg(5)); // => undefined
  ```

* ***getArgs() => Array\<string>***  
  get arg values.
  ```bash
  node cli hoge fuga piyo
  ```
  ```ts
  console.log(getArgs()); // => ["hoge", "fuga", "piyo"]
  ```

* ***hasKeyArg(key: string, subKey?: string) => boolean***  
  return has key arg.
  ```bash
  node cli --hoge
  ```
  ```ts
  console.log(hasKeyArg("--hoge")); // => true
  console.log(hasKeyArg("--fuga")); // => false
  ```

* ***getKeyArg(key: string, subKey?: string) => string | undefined***  
  return arg value.
  ```bash
  node cli -hoge 1 2 3 4 -fuga 5 -piyo -foo
  ```
  ```ts
  console.log(getKeyArg("-hoge")); // => "1"
  console.log(getKeyArg("-fuga")); // => "5"
  console.log(getKeyArg("-piyo")); // => undefined
  console.log(getKeyArg("-none")); // => undefined
  ```

* ***getKeyArgs(key: string, subKey?: string) => Array\<string>***  
  return arg values. continue get value until value start with hyphen or end.  
  ```bash
  node cli -hoge 1 2 3 -fuga 4 -piyo -foo
  ```
  ```ts
  console.log(getKeyArgs("-hoge")); // => ["1", "2", "3"]
  console.log(getKeyArgs("-fuga")); // => ["4"]
  console.log(getKeyArgs("-piyo")); // => []
  console.log(getKeyArgs("-foo"));  // => []
  console.log(getKeyArgs("-none")); // => []
  ```

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