Socket
Socket
Sign inDemoInstall

@oclif/core

Package Overview
Dependencies
27
Maintainers
2
Versions
365
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @oclif/core

base library for oclif CLIs


Version published
Weekly downloads
2M
decreased by-2.6%
Maintainers
2
Install size
7.83 MB
Created
Weekly downloads
 

Package description

What is @oclif/core?

The @oclif/core npm package is a framework for building command-line interfaces (CLIs) in Node.js. It provides a powerful set of tools to develop sophisticated CLIs with features such as argument parsing, command structure, and plugin support. This package is part of the Open CLI Framework (OCLIF) developed by Heroku.

What are @oclif/core's main functionalities?

Command Creation

This feature allows developers to create custom commands for their CLI. The code sample demonstrates how to define a simple command that accepts a name as a flag and prints a greeting message.

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

class MyCommand extends Command {
  async run() {
    const {flags} = await this.parse(MyCommand);
    console.log(`Hello, ${flags.name}!`);
  }
}

MyCommand.description = 'Describe the command here';

MyCommand.flags = {
  name: flags.string({char: 'n', description: 'name to print'}),
};

module.exports = MyCommand;

Argument Parsing

This feature simplifies the process of parsing arguments passed to commands. The code sample shows how to create a command that echoes a message passed as an argument.

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

class EchoCommand extends Command {
  async run() {
    const {args} = await this.parse(EchoCommand);
    console.log(`Echoing: ${args.message}`);
  }
}

EchoCommand.args = [{name: 'message'}];

module.exports = EchoCommand;

Plugin Support

OCLIF supports plugins to extend the functionality of your CLI. This code sample demonstrates how to define a simple plugin that includes a custom command.

const {Command, Plugin} = require('@oclif/core');

class MyPlugin extends Plugin {
  constructor(root, config) {
    super(root, config);
    this.name = 'my-plugin';
  }

  commands = [require('./commands/my-command')];
}

module.exports = MyPlugin;

Other packages similar to @oclif/core

Changelog

Source

3.19.6 (2024-02-23)

Bug Fixes

  • revert to original prompt implementation (a96e567)

Readme

Source

@oclif/core

base library for oclif CLIs

Version Downloads/week License

Migrating

See the v3 migration guide for an overview of breaking changes that occurred between v2 and v3.

See the v2 migration guide for an overview of breaking changes that occurred between v1 and v2.

Migrating from @oclif/config and @oclif/command? See the v1 migration guide.

CLI UX

The ux README contains detailed usage examples of using the ux export.

Usage

We strongly encourage you generate an oclif CLI using the oclif cli. The generator will generate an npm package with @oclif/core as a dependency.

You can, however, use @oclif/core in a standalone script like this:

#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning

import * as fs from 'fs'
import {Command, Flags, flush, handle} from '@oclif/core'

class LS extends Command {
  static description = 'List the files in a directory.'
  static flags = {
    version: Flags.version(),
    help: Flags.help(),
    dir: Flags.string({
      char: 'd',
      default: process.cwd(),
    }),
  }

  async run() {
    const {flags} = await this.parse(LS)
    const files = fs.readdirSync(flags.dir)
    for (const f of files) {
      this.log(f)
    }
  }
}

LS.run().then(
  async () => {
    await flush()
  },
  async (err) => {
    await handle(err)
  },
)

Then run it like this:

$ ts-node myscript.ts
...files in current dir...

Keywords

FAQs

Last updated on 23 Feb 2024

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc