# @writ/command

> Command parameter parsing for building cli applications

Latest version **4.0.0** (published 2020-06-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @writ/command
pnpm add @writ/command
yarn add @writ/command
bun add @writ/command
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2020-06-20 |
| First published | 2018-10-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 28.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | justin Tian |
| Maintainers | writ |
| Keywords | Nodejs, Cli, Command parse |

## Links

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

## 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

- 4.0.0 (latest) — 2020-06-20
- 3.2.0 — 2020-06-20
- 3.1.0 — 2020-06-20
- 3.0.0 — 2019-02-18
- 2.0.0 — 2018-11-05
- 1.1.1 — 2018-11-05
- 1.1.0 — 2018-11-01
- 1.0.4 — 2018-10-26
- 1.0.3 — 2018-10-24
- 1.0.2 — 2018-10-24
- 1.0.1 — 2018-10-24
- 1.0.0 — 2018-10-24

## README

# @writ/command

Mime, Command parameter parsing for building cli applications.
[中文](./README-zh.md)

## Table of Contents

* [Features](#features)
* [Install](#install)
* [Usage](#usage)
* [Change log](#changelog)
* [Resources](#resources)

### [Features](#features)

* elegant command line parameter parsing
* configure the build command line application

### [Install](#install)

[install node.js](https://github.com/tianlugang/docs/blob/master/en/installNodeJS.MD), Now, install and use this project

```sh
   npm install @writ/command
```

### [Usage](#usage)

1. Project Structure

   ```text
      ├─ example/      `usage examples`
      ├─ index.js      `entry points`
      ├─ test/         `test code`
      ├─ .gitignore    `git ignore`
      ├─ .eslintrc.js  `eslint format config`
      ├─ license       `agreement that`
      ├─ package.json  `table of modules with npm`
      └─ README.md     `description`
   ```

2. Usage
   [You can see my example here](./example)
   * Configuration using `function` types, You can do some work in the functions

   ```javascript
      #! /usr/bin/env node
      const Command = require('@writ/command');

      new Command(function(command) {
         return require('../.clirc');
      }).start();
   ```

   * Configuration using `object` types

   ```javascript
      #! /usr/bin/env node
      const Command = require('@writ/command');

      new Command({
         root: '.',
         order: {
            help: {
                  param: [],
                  alias: ['h', '-h']
            },
            version: {
                  alias: [
                     'v',
                     'V',
                     '-v',
                     '--version'
                  ]
            }
         },
         action: {
            help: require('../src/help'),
            version: require('../src/version')
         }
      }).start();
   ```

   * Configuration using `string` types

   ```javascript
      #! /usr/bin/env node

      const Command = require('../../src');
      new Command('../example/.clirc.js').start();
   ```

3. Options [example](./example/.clirc.js)

   * `options.root`[string] your `cli-app` root dir
   * `options.action`[string|object] command handler, it is a dirname or an object
   * `options.order`[object] command detail info

      ```javascript
         // for example: 
         module.exports = {
            root: '.',
            action: {
               example(param) {
                     if (param.all) {
                        process.stdout.write(`All: ${param.all.join(' ')}\n`);
                     }
                     if (param.bail) {
                        process.stdout.write(`Bail: ${param.bail.join(' ')}\n`);
                     }
                     if (param.comment) {
                        process.stdout.write(`Comment: ${param.comment.join(' ')}\n`);
                     }
               }
            },
            order: {
               // Declare the 'example` subcommand
               example: {
                     // example's alias
                     alias: [
                        'ex',
                        '-e'
                     ],
                     // command parameters, the rule is the '--' beginning refers to the full name of the parameter, the '-' beginning refers to the corresponding abbreviation
                     // in a program, or will be converted to the full name, such as the '-a' convert 'param.all = []'
                     param: [
                        '--all -a',
                        '--bail -b',
                        '--comment -c'
                     ]
               }
            }
         }
      ```

      The above configuration implements a child command `<main-command-name> example param`, a command only `alias` and `param` two properties, and are currently only supports arrays, `param` statement for eachparamter in the code: `--<name> -<alias>`, all will be used in the corresponding `action`, referred to as "only to belong to convenient

4. API intro
   In each `action`, `this` always points to your `Command` instances, So, you can use `Command's` methods and properties in each `action`.

   * `root`[string] your `cli-app's` root dir
   * `actRoot`[string] command handler file dir
   * `action`[object] commamd handlers
   * `orders`[object] command set
   * `runtime`[object] currently executing command's infomation
   * start(argv<[array]>)   start loader
   * whoami(enter<[string]>) find currently command's name
   * parse(param<[array|*]>) parse currently command's options
   * invalid() print invaild infomation

### [Change log](#changelog)

* Founded in Wed, 24 Oct 2018 01:38:45 GMT
* Add the test case, Mon, 28 Jan 2019 05:01:27 GMT
* Add usage, Sat, 16 Feb 2019 04:07:42 GMT

### [Resources](#resources)

* [Node.js](https://nodejs.org/en/)

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