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

commanding

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commanding

A simple yet practical command-Line application framework, written in TypeScript.

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

Commanding

A simple yet practical command-Line application framework, written in TypeScript, with only 2 dependencies (chalk and lodash).

Why another CLI framework

Commanding has these features:

  • Written in TypeScript (easier to development & mantain, nicer to TypeScript developers)
  • Less mutable state (long chaining API calls is an old design pattern)
  • Decoupled (you can customize it, e.g.: write your own Sanitizer or change output themes)
  • Promise Based

Installation

$ npm i commanding

Quick Start

If your application only have one command:

import { solo, command, sanitize } from 'commanding';

solo(
    command('default')
        .argument('folder', {
            description: 'Output folder',
            required: true,
        })
        .argument('remark', {
        description: 'Something not important',
        })
        .option('-s, --source', {
            name: 'file',
            required: true,
            csv: true,
            description: 'The source files needs to be converted, you can assign multiple sources by `--source=[source1],[source2]`',
        })
        .option('-e', {
            description: 'Enable encryption',
            required: true,
        })
        .option('-c, --compression', {
            name: 'level',
            default: 5,
            description: 'Compression level, default: 5',
        })
        .option('--filter', {
            name: 'preset',
            repeatable: true,
            description: 'You can apply multiple filter on your video by just using `--filter=[preset]` multiple times',
        })
        .handle(async (args, options) => {
            console.log(args['folder']);
            console.log(options['-s']);
            console.log(options['--source']);

            return;
        }),
    // You can provide some infomations about your application
    {
        name: "Cool Application",
        version: '0.0.1',
        description: 'Check this out mate.',
    }
)
    .parse(process.argv)
    .then(() => {
        console.log('Promise based!');
    });

Then you can test your application:

$ node app.js -h

Screenshot

If your application has many commands (you can still have a default command):

import { gether, command, sanitize } from 'commanding';

gether(
    // Choosable commands:
    [
        command('download')
            .description('Download the content of the URL')
            .argument('URL', {
                description: 'The URL you want to download from',
                required: true,
            })
            .handle(async (args, options) => {
                // Command logic
            }),
        command('upload')
            .description('Upload content to the URL')
            .argument('URL', {
                description: 'The URL you want to upload to',
                required: true,
            })
            .handle(async (args, options) => {
                // Command logic
            }),
    ],
    // Default command:
    command('default')
        .handle((async args, options) => {
            // Command logic
        }),
    {
        name: "Cool Application",
        version: '0.0.1',
        description: 'Check this out mate.',
    }
)
    .parse(process.argv);

Roadmap

  1. - Better handling for long text
  2. - Bump test coverage to 90%
  3. - Support auto-complete (If it's necessary after assessment)

Credits

Heavily inspired by Caporal.

Build script from RxJS.

License

Apache 2.0

Keywords

FAQs

Package last updated on 30 Aug 2019

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