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

@oclif/command

Package Overview
Dependencies
Maintainers
8
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@oclif/command

oclif base command

  • 1.8.36
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
820K
increased by0.62%
Maintainers
8
Weekly downloads
 
Created

What is @oclif/command?

@oclif/command is a framework for building command-line interface (CLI) applications. It provides a robust set of tools and conventions for creating, organizing, and managing CLI commands, arguments, and options.

What are @oclif/command's main functionalities?

Creating a Basic Command

This feature allows you to create a basic command that prints 'Hello, world!' to the console. The Command class is extended to define the behavior of the command.

const { Command } = require('@oclif/command');

class HelloWorldCommand extends Command {
  async run() {
    this.log('Hello, world!');
  }
}

HelloWorldCommand.run();

Adding Arguments and Flags

This feature allows you to add arguments and flags to your command. In this example, the command takes an optional 'name' argument and a 'greeting' flag to customize the output.

const { Command, flags } = require('@oclif/command');

class GreetCommand extends Command {
  async run() {
    const { args, flags } = this.parse(GreetCommand);
    const name = args.name || 'world';
    const greeting = flags.greeting || 'Hello';
    this.log(`${greeting}, ${name}!`);
  }
}

GreetCommand.args = [
  { name: 'name' }
];

GreetCommand.flags = {
  greeting: flags.string({ char: 'g', description: 'greeting to use' })
};

GreetCommand.run();

Command Aliases

This feature allows you to define aliases for your commands. In this example, the 'HelloWorldCommand' can be invoked using 'hw' or 'hello' as aliases.

const { Command } = require('@oclif/command');

class HelloWorldCommand extends Command {
  async run() {
    this.log('Hello, world!');
  }
}

HelloWorldCommand.aliases = ['hw', 'hello'];

HelloWorldCommand.run();

Other packages similar to @oclif/command

Keywords

FAQs

Package last updated on 19 Aug 2023

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