# oo-cli

> A typescript-first object-oriented command line interface framework

Latest version **0.2.1** (published 2022-02-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install oo-cli
pnpm add oo-cli
yarn add oo-cli
bun add oo-cli
```

Provides the command `oo-cli`.

## Health

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

Positive: has types; no vulnerabilities; high quality score.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2022-02-07 |
| First published | 2019-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 197 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Levi Lansing |
| Maintainers | levilansing |

## Links

- npm: https://www.npmjs.com/package/oo-cli
- Repository: https://github.com/levilansing/oo-cli
- npm.io page: https://npm.io/package/oo-cli

## Dependencies (9)

- [glob](https://npm.io/package/glob.md) ^7.1.3
- [chalk](https://npm.io/package/chalk.md) ^2.4.2
- [marked](https://npm.io/package/marked.md) ^0.7.0
- [callsites](https://npm.io/package/callsites.md) ^3.1.0
- [columnify](https://npm.io/package/columnify.md) ^1.5.4
- [window-size](https://npm.io/package/window-size.md) ^1.1.1
- [@types/chalk](https://npm.io/package/@types/chalk.md) ^2.2.0
- [marked-terminal](https://npm.io/package/marked-terminal.md) ^3.2.0
- [@types/window-size](https://npm.io/package/@types/window-size.md) ^0.2.4

## Recent versions

- 0.2.1 (latest) — 2022-02-07
- 0.2.0 — 2019-10-21
- 0.1.2 — 2019-09-04
- 0.1.1 — 2019-07-01
- 0.1.0 — 2019-06-24
- 0.0.0 — 2019-05-01

## README

# OO-CLI

A Typescript-first, object-oriented CLI framework. Build your own CLI by simply decorating some classes.

# WARNING

Version 0 is unstable. Expect breaking changes until it reaches 1.0.0

# Getting Started (new project)

Install oo-cli globally using [yarn](https://yarnpkg.com/en/package/jest):

```bash
yarn global add oo-cli
```

Or [npm](https://www.npmjs.com/):

```bash
npm install --global oo-cli
```

Then run
```bash
oo-cli init
```
**(NOT YET IMPLEMENTED)**
to scaffold a new project or `oo-cli help` for help on other commands.

# Adding to an existing project

TODO

# Example Command

Simply decorate your class to define your command, flags, options, and parameters and oo-cli will do the rest.

```typescript
import { command, flag, help, invertible, multiple, optional, param } from '../../decorators';

export class StatusCommand {
  @flag('l')
  @help('Include lights')
  @invertible
  public lights?: boolean;

  @flag('d')
  @help('Include doors')
  @invertible
  public doors?: boolean;

  @flag('v')
  @help('Show detailed status information')
  public verbose!: boolean;

  @param
  @help('Specify name(s) of devices to check their status')
  @optional
  @multiple
  public devices?: string[];

  @command
  @help('Get the status of all smart devices')
  public status() {
    // TBD
  }
}
```

Then build and run your command:

```bash
yarn build && yarn link
smart-house status -l kitchen
```

# Decorators

## Class decorators
| Decorator                         | Description                                                                                                                                                                           |
|-----------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|      @namespace('namespace')      | Space delimited namespace to put this command under. Only necessary if you want to use namespaces.                                                                                    |

## Member variable decorators

| Decorator                         | Description                                                                                                                                                                           |
|-----------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| @flag \| @flag('alias', ...)      | Mark this member variable as a flag (boolean). Optionally add additional aliases for the flag.                                                                                        |
| @invertible                       | Allows the flag to be inverted with opposite case for a single character alias or prefixed with `no-` for longer aliases. E.g., -c, --color => -C, --no-color.                        |
| @required                         | Mark a flag required (useful for invertible flags).                                                                                                                                   |
| @help('Explanation ...')          | Add help text to a flag, option, parameter, or command for the generated documentation.                                                                                               |
| @option \| @option('alias', ...)  | Mark this member variable as an option that can receive a string value from the command. E.g., --option=value.                                                                        |
| @optional                         | Mark an option, or parameter as not required.                                                                                                                                         |
| @multiple                         | Allow multiple values for an option or parameter (data type will be a string array)                                                                                                   |
| @defaultValue                     | Specify the default value if the option or parameter is optional and not provided.                                                                                                    |
| @param \| @param('name')          | Mark this member variable as a parameter for the command. Parameters must be in the expected order in the class. The optional name will override the param name in the documentation. |

## Member function decorators

| Decorator                         | Description                                                                                                                                                                           |
|-----------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| @command \| @command('alias', ...)| Tells oo-cli to instantiate this class and call this function when the command is executed.                                                                                           |

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