Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
@rushstack/ts-command-line
Advanced tools
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.
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();
}
}
}
Commander is a popular npm package for building command-line interfaces. It offers a simpler API compared to @rushstack/ts-command-line, making it a good choice for smaller projects or those who prefer a more straightforward approach. However, it might lack some of the advanced structuring and TypeScript integration provided by @rushstack/ts-command-line.
Yargs is another widely used library for building command-line tools. It focuses on easy argument parsing and includes built-in support for things like command chaining and advanced argument validation. While it offers robust features for argument handling, @rushstack/ts-command-line provides a more structured approach to defining commands and parameters, especially beneficial for complex CLI applications.
Oclif (Open CLI Framework) is a framework for building command-line interfaces developed by Heroku. It supports both TypeScript and JavaScript and offers features like plugin support, auto-documentation, and testing utilities. Oclif and @rushstack/ts-command-line share a similar philosophy in providing a structured approach to CLI development, but oclif's plugin ecosystem and Heroku's backing might make it more appealing for certain projects.
FAQs
An object-oriented command-line parser for TypeScript
The npm package @rushstack/ts-command-line receives a total of 1,989,001 weekly downloads. As such, @rushstack/ts-command-line popularity was classified as popular.
We found that @rushstack/ts-command-line demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
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.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.