New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cmd-ts

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cmd-ts

> 💻 A type-driven command line argument parser, with awesome error reporting 🤤

  • 0.0.0-684600f145d167471c0fc091edc2110f2e846c6c
  • npm
  • Socket score

Version published
Weekly downloads
23K
decreased by-81.21%
Maintainers
1
Weekly downloads
 
Created

What is cmd-ts?

cmd-ts is a TypeScript library for building command-line applications. It provides a simple and type-safe way to define commands, arguments, and options, making it easier to create robust CLI tools.

What are cmd-ts's main functionalities?

Defining a Command

This feature allows you to define a command with arguments. In this example, a 'hello' command is created that takes a 'name' argument and prints a greeting message.

const { command, run, string } = require('cmd-ts');

const hello = command({
  name: 'hello',
  args: {
    name: string({
      description: 'Name to greet'
    })
  },
  handler: ({ name }) => {
    console.log(`Hello, ${name}!`);
  }
});

run(hello, process.argv.slice(2));

Handling Options

This feature allows you to handle options in your command. In this example, an 'excited' option is added to the 'greet' command, which appends an exclamation mark to the greeting if specified.

const { command, run, string, option } = require('cmd-ts');

const greet = command({
  name: 'greet',
  args: {
    name: string({
      description: 'Name to greet'
    }),
    excited: option({
      type: Boolean,
      long: 'excited',
      description: 'Add an exclamation mark'
    })
  },
  handler: ({ name, excited }) => {
    const greeting = `Hello, ${name}${excited ? '!' : ''}`;
    console.log(greeting);
  }
});

run(greet, process.argv.slice(2));

Subcommands

This feature allows you to define subcommands within a main command. In this example, 'hello' and 'goodbye' are subcommands of the 'app' command.

const { command, run, subcommands, string } = require('cmd-ts');

const hello = command({
  name: 'hello',
  args: {
    name: string({
      description: 'Name to greet'
    })
  },
  handler: ({ name }) => {
    console.log(`Hello, ${name}!`);
  }
});

const goodbye = command({
  name: 'goodbye',
  args: {
    name: string({
      description: 'Name to bid farewell'
    })
  },
  handler: ({ name }) => {
    console.log(`Goodbye, ${name}!`);
  }
});

const app = subcommands({
  name: 'app',
  cmds: { hello, goodbye }
});

run(app, process.argv.slice(2));

Other packages similar to cmd-ts

FAQs

Package last updated on 31 Mar 2020

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