Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nest-commander

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nest-commander

A module for making CLI applications with NestJS. Decorators for running commands and separating out config parsers included. This package works on top of commander.

  • 3.15.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
211K
increased by12.37%
Maintainers
1
Weekly downloads
 
Created

What is nest-commander?

The nest-commander package is a utility for building command-line interfaces (CLI) using the NestJS framework. It allows developers to create and manage CLI commands in a structured and organized manner, leveraging the power of NestJS decorators and dependency injection.

What are nest-commander's main functionalities?

Creating a Basic Command

This feature allows you to create a basic command using the @Command decorator. The command can then be executed from the CLI, and it will print 'Hello, World!' to the console.

```typescript
import { Command, CommandRunner } from 'nest-commander';

@Command({ name: 'hello', description: 'A hello world command' })
export class HelloCommand extends CommandRunner {
  async run(passedParam: string[], options?: Record<string, any>): Promise<void> {
    console.log('Hello, World!');
  }
}
```

Handling Command Parameters

This feature demonstrates how to handle command parameters. The command 'greet' takes a single parameter 'name' and prints a personalized greeting message.

```typescript
import { Command, CommandRunner } from 'nest-commander';

@Command({ name: 'greet', arguments: '<name>' })
export class GreetCommand extends CommandRunner {
  async run(passedParam: string[], options?: Record<string, any>): Promise<void> {
    const [name] = passedParam;
    console.log(`Hello, ${name}!`);
  }
}
```

Using Command Options

This feature shows how to use command options. The 'hello' command has an option 'shout' that, when used, will print the greeting message in uppercase.

```typescript
import { Command, CommandRunner, Option } from 'nest-commander';

interface HelloOptions {
  shout: boolean;
}

@Command({ name: 'hello', options: { shout: { alias: 's', description: 'Shout the greeting' } } })
export class HelloCommand extends CommandRunner {
  async run(passedParam: string[], options?: HelloOptions): Promise<void> {
    const message = 'Hello, World!';
    if (options?.shout) {
      console.log(message.toUpperCase());
    } else {
      console.log(message);
    }
  }
}
```

Other packages similar to nest-commander

Keywords

FAQs

Package last updated on 14 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc