# @fastpanel/console

> Create console (cli) application in NestJS framework context.

Latest version **1.0.0** (published 2021-04-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @fastpanel/console
pnpm add @fastpanel/console
yarn add @fastpanel/console
bun add @fastpanel/console
```

## 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.0.0 |
| Published | 2021-04-20 |
| First published | 2021-04-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 10 |
| Dependencies | 1 |
| Unpacked size | 321.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Desionlab |
| Maintainers | fenixphp |
| Keywords | cli, console, nestjs, fastpanel |

## Links

- npm: https://www.npmjs.com/package/@fastpanel/console
- Repository: https://github.com/fastpanel/console
- Issues: https://github.com/fastpanel/console/issues
- npm.io page: https://npm.io/package/@fastpanel/console

## Dependencies (1)

- [@caporal/core](https://npm.io/package/@caporal/core.md) ^2.0.2

## 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 (latest) — 2021-04-20

## README

# fastPanel [console]
Create console (cli) application in NestJS framework context.

> The a wrapper "[caporal](https://caporal.io/)" lib for use in "[nestjs](https://nestjs.com/)" framework.

## Install

### Stable
```bash
npm i @fastpanel/console
```

### Develop
```bash
npm i @fastpanel/console --registry https://npmjs.desionlab.net
```

## Usage

1. Add command providers.

```typescript
/**
 * pizza.commands.ts
 */

import { Injectable } from '@nestjs/common';
import { Console, Command, Argument, Option } from '@fastpanel/console';

@Console({ name: 'pizza' })
@Injectable()
export class PizzaCommands {
  @Command({ name: 'order', description: 'Order a pizza' })
  @Argument({ synopsis: '<type>', description: 'Type of pizza' })
  @Option({ synopsis: '-e, --extra-ingredients <ingredients>', description: 'Extra ingredients' })
  public async orderAction({ logger, args, options }) {
    logger.info('Order received: %s', args.type);

    if (options.extraIngredients) {
      logger.info('Extra: %s', options.extraIngredients);
    }
  }

  @Command({ name: 'cancel', description: 'Cancel an order' })
  @Argument({ synopsis: '<order-id>', description: 'Order id' })
  public async cancelAction({ logger, args }) {
    logger.info('Order canceled: %s', args.orderId);
  }
}
```

2. Add console module and command providers to app module.

```typescript
/**
 * app.module.ts
 */

import { Module } from '@nestjs/common';
import { ConsoleModule } from '@fastpanel/console';
import { PizzaCommands } from './pizza.commands.ts';

@Module({
  imports: [
    ConsoleModule.forRoot({
      name: 'my-test-app',
      version: '1.0.0',
      description: 'My test app'
    })
  ],
  providers: [PizzaCommands]
})
export class AppModule {}
```

3. Create application context.

```typescript
/**
 * cli.ts
 */

import { NestFactory } from '@nestjs/core';
import { ConsoleService } from '@fastpanel/console';
import { AppModule } from './app.module';

async function bootstrap() {
  /* Create app instant. */
  const app = await NestFactory.createApplicationContext(AppModule, {
    logger: false
  });

  /* Get console service. */
  const consoleService = app.get<ConsoleService>(ConsoleService);

  /* Add default help command. */
  consoleService.getHandler.action(async ({ program }) => {
    await program.exec(['help']);
  });

  /* Run cli handler. */
  await consoleService.run();

  /* End app. */
  await app.close();
}

/* Run app. */
bootstrap();
```

4. Add scripts to package.json

```json
{
  "scripts": {
    "console": "node dist/cli.js",
    "console:dev": "ts-node -r tsconfig-paths/register src/cli.ts"
  }
}
```

5. Use in terminal.

```bash
# Run in development mode
npm run console:dev -- help
npm run console:dev -- command-name

# Run in prod or build mode
npm run console -- help
npm run console -- command-name
```

## License

[MIT licensed](LICENSE).

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