Socket
Book a DemoInstallSign in
Socket

commander-ts

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commander-ts

TypeScript decorators that enhance commander

latest
Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

commander-ts

TypeScript decorators for commander that makes developing command line tools with Node even easier.

Usage

  • Import commander-ts into your project.
    $ npm install --save commander-ts
    

Example

index.ts

import {
	action, command, commandOption, description, option,
	optionalArg, program, requiredArg, usage,
	variadicArg, version,
	Command
} from 'commander-ts';

@program()
@version('1.0.0')
@description('A basic program')
@usage('--help')
export class Program {
	@option('--env <env>')
	env: string = null;

	constructor() {}

	run(@requiredArg('message') message) {
		console.log(`Message: ${message}`);
	}

	@command()
	@commandOption('--reverse')
	print(
		this: Command,
		@requiredArg('first') first,
		@optionalArg('last') last,
		@variadicArg('credentials') credentials
	) {
		if (this.reverse) {
			console.log(`Name: ${last}, ${first}, ${credentials.join(', ')}`);
		} else {
			console.log(`Name: ${first} ${last}, ${credentials.join(', ')}`);
		}
	}
}

const p = new Program();

$ node index.js "Hello world"
  Hello world

$ node index.js print Jack Bauer
  Jack Bauer

$ node index.js print James Bond --reverse
  Bond, James

Keywords

command line

FAQs

Package last updated on 20 Oct 2021

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