{"id":13847261,"url":"https://github.com/squareboat/nest-console","last_synced_at":"2025-10-28T11:31:50.396Z","repository":{"id":37465947,"uuid":"319100949","full_name":"squareboat/nest-console","owner":"squareboat","description":"Create beautiful CLI commands in your NestJS Applications","archived":false,"fork":false,"pushed_at":"2023-06-18T12:46:26.000Z","size":412,"stargazers_count":58,"open_issues_count":2,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-02-01T15:03:29.457Z","etag":null,"topics":["nestjs","nestjs-cli","nestjs-console"],"latest_commit_sha":null,"homepage":"https://squareboat.com/open-source/nestjs-boilerplate/console","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/squareboat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.MD","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-06T18:19:41.000Z","updated_at":"2024-08-07T07:48:48.000Z","dependencies_parsed_at":"2024-06-18T20:05:35.714Z","dependency_job_id":null,"html_url":"https://github.com/squareboat/nest-console","commit_stats":{"total_commits":44,"total_committers":2,"mean_commits":22.0,"dds":0.06818181818181823,"last_synced_commit":"b4d80444e4e43d7753399ea0c4749d4bfb533929"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squareboat%2Fnest-console","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squareboat%2Fnest-console/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squareboat%2Fnest-console/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squareboat%2Fnest-console/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/squareboat","download_url":"https://codeload.github.com/squareboat/nest-console/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238645867,"owners_count":19506919,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["nestjs","nestjs-cli","nestjs-console"],"created_at":"2024-08-04T18:01:14.866Z","updated_at":"2025-10-28T11:31:50.390Z","avatar_url":"https://github.com/squareboat.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Nestjs Console\n\nCreate beautiful CLI commands in your application. A simple NestJS CLI module, comes packaged with utilities.\n\n## Table Of Content\n\n- [Features](#features)\n- [Installation](#installation)\n- [Getting Started](#getting-started)\n- [Creating Command](#creating-command)\n  - [Class](#class)\n  - [Method](#method)\n- [Defining Input](#defining-input)\n  - [Arguments](#arguments)\n  - [Options](#options)\n- [Command Console I/O](#command-console-i-o)\n  - [Retrieving Inputs](#retrieving-inputs)\n  - [Prompting for Input](#prompting-for-input)\n  - [Writing Outputs](#writing-outputs)\n- [Available Commands](#available-commands)\n- [Available Options](#available-options)\n- [Contributing](#contributing)\n- [About Us](#about-us)\n- [License](#license)\n\n## Features\n\n- _**Quick Setup**_ - Quickly setup and configure your application\n\n- _**Utilities**_ - Comes packed with utilities to let you easily interact and print.\n- _**Beautiful Commands**_ - Creating a beautiful command is as easy as creating a simple injector.\n\n## Installation\n\nTo install the package, run\n\n```bash\nnpm install @squareboat/nest-console\n```\n\nOR\n\n```bash\nyarn add @squareboat/nest-console\n```\n\nFor NestJS v6.7.x, please use\n\n```\nnpm install @squareboat/nest-console^0.0.7\n```\n\n## Getting Started\n\nOnce the `cli` file is copied, you need to open the `cli` file and change the module that you need to pass in `createApplicationContext` method.\n\n\u003e If you are following the default project structure created by `nest` command. You don't need to do anything.\n\nOnce the added the correct module in `cli` file, you need to import the `ConsoleModule` from the package.\n\n```typescript\nimport { Module } from \"@nestjs/common\";\nimport { ConsoleModule } from \"@squareboat/nest-console\";\nimport { AppController } from \"./app.controller\";\nimport { AppService } from \"./app.service\";\n\n@Module({\n  imports: [ConsoleModule],\n  controllers: [AppController],\n  providers: [AppService],\n})\nexport class AppModule {}\n```\n\nNow, whatever command you create in your application will be discovered automatically.\n\n\u003e To be able for the package to discover the command, you need to register the Injectable class inside `providers` property in your module.\n\n## Creating Command\n\nThere are basically two ways through which you can define commands.\n\n- Using the `Command` decorator on an Injectable class\n- Using the `Command` decorator on an Injectable class' method.\n\n\u003e Remember to use the `@Injectable` decorator on the class always a, else the command will not be discovered and registered.\n\n### Class\n\nYou can create an injectable class and use `@Command` decorator on it. The package will automatically look for `handle` method inside the class.\n\n### Method\n\nYou can use `@Command` decorator on the method.\n\n```typescript\nimport { Injectable } from \"@nestjs/common\";\nimport { Command, ConsoleIO } from \"@squareboat/nest-console\";\n\n@Injectable()\nexport class AppService {\n  @Command(\"hello {name=world}\", { desc: \"Test Command\" })\n  sayHello(_cli: ConsoleIO) {\n    const name = _cli.argument\u003cstring\u003e(\"name\");\n    _cli.info(`Hello ${name}!`);\n    return;\n  }\n}\n```\n\nBefore running the command, you need to build it first.\n\n```bash\nnpm run build\n```\n\nNow, to run any command, you can simply do\n\n```bash\nnode cli hello\n```\n\n## Defining Input\n\nWe understand that you may want to build commands which can be dynamic in nature, ie. you may expect some required or optional parameters from client while running the command. We have made it dead simple for you to define your input expectations.\n\nAll user supplied arguments and options are wrapped in curly braces.\n\n### Arguments\n\nArguments in console applications are required variables.\n\n```typescript\n@Command(\n  'generate:report {type}',\n  { desc: 'Test Command' }\n)\n```\n\n```bash\n$ node cli generate:report gar\n```\n\n### Options\n\nOptions are the optional inputs for each command. They are denoted by double hyphens (`--`).\n\nExample:\n\n```typescript\n@Command(\n  'generate:report {type} {--emails}',\n  {  desc: 'Test Command',}\n)\n```\n\n```bash\n$ node cli generate:report gar --emails=email@example.com\n```\n\nTo pass array of values in any options or arguments, you can add asterik.\n\n```typescript\ngenerate:report {type*} {--emails*}\n```\n\n```bash\n$ node cli generate:report gar gmr --emails=email@example.com --emails=email2@example.com\n```\n\nYou can also define default values for the arguments or options by adding a `=` equal sign followed by the value.\n\n```typescript\ngenerate:report {type=gar} {--emails=email@example.com}\n```\n\n---\n\n## Retrieving Inputs\n\nWe provide easy to use APIs to work with I/O directly from the console.\n\n### Retrieving Passed Inputs\n\nWhile executing command, you will need to fetch the values that you may have passed in the invocation. Your method will be passed an `_cli: ConsoleIO` object. You can then simply check for all the values.\n\nFor fetching an argument, you can do\n\n```typescript\nconst type = _cli.argument\u003cstring\u003e(\"type\");\n```\n\nFor fetching an option, you can do\n\n```typescript\nconst email = _cli.option\u003cstring\u003e(\"email\");\n```\n\nIf no value is passed, the `argument` and `option` function will return the default value or `null` value.\n\n### Prompting for Input\n\nYou may want to ask for input while executing a command. We provide several ways with which you can ask for inputs directly on console.\n\nTo ask for simple input from the user, you can call `ask(question: string)` method.\n\n```typescript\nconst name = _cli.ask(\"name\");\n```\n\nYou may want to ask user about some secret or any password, which ideally should not get printed on the console.\n\n```typescript\nconst password = await _cli.password(\"Enter your pasword to continue\");\n```\n\nWhile running a command, you can also give choices to select from a defined list. For example:\n\n```typescript\n/**\n * Single choice example.\n * Returns one of the passed choices.\n */\nconst choice = await _cli.select(\n  \"Please select one superhero\", // question\n  [\"Batman\", \"Ironman\"], // choices\n  false // multiple?\n);\n\n/**\n * Multiple choices example.\n * Returns an array of the selected options.\n */\nconst choice = await _cli.select(\n  \"Please select one superhero\",\n  [\"Batman\", \"Ironman\"],\n  true\n);\n```\n\nLastly, sometimes you may want to ask for confirmation from the user before doing any execution. You can do so by using `confirm` method.\n\n```typescript\nconst confirm = await _cli.confirm(\"Do you really wish to continue?\");\nif (confirm) {\n  // do your magic here\n}\n```\n\n### Writing Outputs\n\nTill now, we have seen how we can operate with differnt type of inputs on the cli. There will be scenarios when you will want to print something on the console. We provide a very easy-to-use set of APIs for your basic console outputing needs.\n\nTo print any message on the console, use `info` method\n\n```typescript\n_cli.info(\"Some amazing message\"); // Outputs 'Some amazing message' on the console\n```\n\nIncase of an error message, use `error` method.\n\n```typescript\n_cli.error(\"Oops! Something went wrong.\");\n```\n\nSimilarly, to print any success message, use `success` method\n\n```typescript\n_cli.success(\"Wohoo! The command worked just fine!\");\n```\n\nTo print a divider on the console, simple do\n\n```typescript\n_cli.line();\n```\n\nTo print a table on the console, you can use `table` method:\n\n```typescript\n// this will automatically print unicode table on the console\n_cli.table([\n  { name: \"User 1\", designation: \"Software Engineer L1\" },\n  { name: \"User 2\", designation: \"Software Engineer L1\" },\n]);\n```\n\n---\n\n## Available Commands\n\nWe provide few commands, which will help in your day to day development process.\n\nTo list all commands available in your application, you can do\n\n```bash\nnode cli list\n```\n\n`list` is a reserved command name, please don't use it in any of the commands\n\n---\n\n## Available Options\n\nWe provide few out-of-the-box predefined options, which you can use with each of your command.\n\nTo list all the arguments and options that your command supports/expects, simply run\n\n```bash\nnode cli users:greet --options\n```\n\n`--options` is a reserved option. Please don't use it anywhere in your command\n\n## Contributing\n\nTo know about contributing to this package, read the guidelines [here](./CONTRIBUTING.md)\n\n## About Us\n\nWe are a bunch of dreamers, designers, and futurists. We are high on collaboration, low on ego, and take our happy hours seriously. We'd love to hear more about your product. Let's talk and turn your great ideas into something even greater! We have something in store for everyone. [☎️ 📧 Connect with us!](https://squareboat.com/contact)\n\nWe are hiring! Apply now at [careers](https://squareboat.com/careers) page\n\n## License\n\nThe MIT License. Please see License File for more information. Copyright © 2025 SquareBoat.\n\nMade with ❤️ by [Squareboat](https://squareboat.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquareboat%2Fnest-console","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsquareboat%2Fnest-console","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquareboat%2Fnest-console/lists"}