# @devnetic/cli

> A tool for rapidly parse command line arguments or options

Latest version **1.2.1** (published 2020-10-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @devnetic/cli
pnpm add @devnetic/cli
yarn add @devnetic/cli
bun add @devnetic/cli
```

## 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.2.1 |
| Published | 2020-10-02 |
| First published | 2019-09-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 28.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Álvaro José Agámez Licha |
| Maintainers | aagamezl |
| Keywords | cli, command line, opts, parseopt, opt, args, console, argsparse, optparse, prompt |

## Links

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

## Dependencies (1)

- [@devnetic/utils](https://npm.io/package/@devnetic/utils.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

- 1.2.1 (latest) — 2020-10-02
- 1.2.0 — 2020-08-29
- 1.1.0 — 2020-01-26
- 1.0.3 — 2020-01-14
- 1.0.2 — 2019-09-17
- 1.0.1 — 2019-09-05
- 1.0.0 — 2019-09-05

## README

# @devnetic/cli

![npm (scoped)](https://img.shields.io/npm/v/@devnetic/cli)
![npm bundle size (scoped)](https://img.shields.io/bundlephobia/minzip/@devnetic/cli?color=red)
![npm](https://img.shields.io/npm/dt/@devnetic/cli)
![GitHub issues](https://img.shields.io/github/issues-raw/devnetic/cli)
![GitHub](https://img.shields.io/github/license/devnetic/cli)

A tool for rapidly parse command line arguments and create command line applications.

# Usage

## Get cli arguments

To get the cli arguments you can to use the `getParams` function; this function 
return an object with all the params and values given to your Node.js script.

```javascript
const { getParams } = require('@devnetic/cli')

const params = getParams()

if (params.help || params.h) {
  console.log('Help option is used')
}

// execute with node index.js --help or node index.js -h
```

## Using the `usage` function to create a help for our command line tools

```javascript
const { usage } = require('@devnetic/cli')

usage('Usage: $0 <command> [options]')
  .option(['-f', '--file'], 'Load a file', 'red')
  .option(['-h', '--help'], 'Show help', 'blue')
  .example('$0 -f foo.js', 'count the lines in the given file')
  .epilog('copyright 2019', 'green')
  .show()
```

## Using the `format` function to custom messages for our command lines tools

```javascript
const { format } = require('@devnetic/cli')

const error = format.bold().red

console.log(format.white(JSON.stringify(fixed, null, '  ')))
console.log(format.bold().italic().red(JSON.stringify(params, null, '  ')))

console.log(error('Unexpeted Error!'))
console.log(format.bold().yellow('This is a Warning!'))
```

## Prompt questions to the user

With cli package you can ask question to the user in a easy way; the `prompt` 
function return a `Promise` with the user's answers, so you can use the 
traditional promise mechanism or to use `async/await`:

```javascript
const { prompt } = require('@devnetic/cli')

const questions = [{
  type: 'input',
  name: 'firstName',
  message: "What's your firsr name? ",
}, {
  type: 'input',
  name: 'lastname',
  message: "What's your last name? ",
}, {
  type: 'input',
  name: 'phoneNumber',
  message: "What's your phone number? ",
}]

const run = async () => {
  const answers = await prompt(questions)

  console.log(answers)
  // { firstName: 'John', lastname: 'Doe', phoneNumber: '123' }
}

run()
```

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