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

@rushstack/ts-command-line

Package Overview
Dependencies
Maintainers
0
Versions
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rushstack/ts-command-line

An object-oriented command-line parser for TypeScript

  • 4.23.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created

What is @rushstack/ts-command-line?

The @rushstack/ts-command-line package provides a robust framework for building command-line interfaces (CLIs) with TypeScript. It offers features like argument parsing, tab completion, and rich command structures, making it easier to create complex and user-friendly command-line applications.

What are @rushstack/ts-command-line's main functionalities?

Defining commands

This feature allows developers to define custom commands by extending the CommandLineAction class. Each command can have its own parameters, help text, and execution logic.

{
  import { CommandLineAction } from '@rushstack/ts-command-line';

  class MyCommand extends CommandLineAction {
    public constructor() {
      super({
        actionName: 'do-something',
        summary: 'Does something interesting',
        documentation: 'A longer description of the command.'
      });
    }

    protected onDefineParameters(): void { /* Define parameters here */ }

    protected onExecute(): Promise<void> {
      // Your code here
      console.log('Doing something...');
      return Promise.resolve();
    }
  }
}

Parsing command line arguments

This feature involves creating a command line parser that can handle multiple commands, each with its own parameters. The parser takes care of interpreting the user's input and executing the corresponding command.

{
  import { CommandLineParser } from '@rushstack/ts-command-line';

  class MyCommandLine extends CommandLineParser {
    public constructor() {
      super({
        toolFilename: 'my-tool',
        toolDescription: 'This tool does amazing things.'
      });

      this.addAction(new MyCommand());
    }

    protected onDefineParameters(): void { /* Define global parameters here */ }
  }

  const myCommandLine = new MyCommandLine();
  myCommandLine.execute();
}

Tab completion

This feature allows the CLI to support tab completion, improving user experience by allowing users to easily see available commands and options. Implementing this feature typically involves generating a script that users can source in their shell.

{
  // Note: Actual implementation of tab completion requires setting up a shell script
  // This example demonstrates registering a command that can generate such a script

  import { CommandLineAction } from '@rushstack/ts-command-line';

  class GenerateCompletionScriptCommand extends CommandLineAction {
    public constructor() {
      super({
        actionName: 'generate-completion',
        summary: 'Generates a script for tab completion.',
        documentation: 'Generates a script to enable tab completion for the CLI.'
      });
    }

    protected onExecute(): Promise<void> {
      console.log('Generating tab completion script...');
      return Promise.resolve();
    }
  }
}

Other packages similar to @rushstack/ts-command-line

FAQs

Package last updated on 14 Dec 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