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

@fluent/console

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fluent/console

Fluent - console component

  • 1.0.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
34
increased by17.24%
Maintainers
1
Weekly downloads
 
Created
Source

Console

The command line interface is the basis for application execution. The console operates with commands. That's how the command looks:

@Command('ping')
export class PingCommand extends CommandHandler {
  constructor(readonly logger: Logger) {
    super();
  }

  async handle() {
    this.logger.information('pong');
  }
}

@Command(string) is required. This decorator sets the template and allows you to inject the services on the constructor.

In order to add the command you need to register it in the application:

@Main()
export class Startup {
  configure(app: ApplicationBuilder) {
    app.addCommand(PingCommand);
  }
}

Template Definition

The command template consists of three components: name, arguments and options. These components should be separated by a space.

Name

The name is required and must be unique:

@Command('ping')

Argument

Arguments can be several or none.

Here is an example of an required argument:

@Command('ping {message}')

The argument may also be optional and contain default value:

@Command('ping {message?}')

// and with default value

@Command('ping {message=pong}')

Option

Options can be several or none as well. Option always will be optional and can be defined as string or boolean type.

Here is an example of option:

@Command('ping {--log}')

Option can have multi-definition:

@Command('ping {-l|--log}')

If the option is not specified then the value will be false;

That's how the option with value looks:

@Command('ping {--message=}')

// or with default value

@Command('ping {--message=pong}')

If the option is not specified then the value will be undefined;

Option can receive array value:

// ping --to=foo --to=bar

@Command('ping {--to=*}')

If the option is not specified then the value will be [];

Command Handler

the handler of the commands can receive parets through the decorators: @Argument() and @Option()

@Command('ping {message=pong} {--log}')
export class PingCommand extends CommandHandler {
  constructor(readonly logger: Logger) {
    super();
  }

  async handle(@Argument() message: string, @Option() log: boolean) {
    if (log) {
      this.logger.information(message);
    }
  }
}

In this case, the name of the argument and options are the name of the parameters. They can also be redefined:

async handle(@Argument('message') msg: string, @Option('--log') log: boolean) {
    if (log) {
      this.logger.information(message);
    }
  }

Command Execution

In order to execute the command you need to compile the code and enter:

node main.js "command template"

Example of PingCommand:

node main.js ping pong --log

Output will looks:

information: pong

Keywords

FAQs

Package last updated on 03 Feb 2018

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